diff --git a/src/robotkernel/completion_finders.py b/src/robotkernel/completion_finders.py index 5184fd07..46a0274d 100644 --- a/src/robotkernel/completion_finders.py +++ b/src/robotkernel/completion_finders.py @@ -1,6 +1,5 @@ """Completion implementations.""" -from IPython.core.completerlib import get_root_modules from robot.libraries import STDLIBS from typing import List @@ -9,7 +8,7 @@ def complete_libraries(needle: str,) -> List[str]: """Complete library names.""" matches = [] - for lib in list(STDLIBS) + list(get_root_modules()): + for lib in list(STDLIBS): if needle in lib.lower(): matches.append(lib) diff --git a/src/robotkernel/kernel.py b/src/robotkernel/kernel.py index be92e193..a408d7cc 100644 --- a/src/robotkernel/kernel.py +++ b/src/robotkernel/kernel.py @@ -31,6 +31,7 @@ from robotkernel.utils import get_lunr_completions from robotkernel.utils import lunr_builder from robotkernel.utils import lunr_query +from robotkernel.utils import remove_prefix from robotkernel.utils import scored_results from robotkernel.utils import yield_current_connection import re @@ -138,7 +139,13 @@ def do_complete(self, code, cursor_pos): "get library instance" in line.lower(), ] ): - matches = complete_libraries(needle.lower()) + needle = needle.lower() + needle = remove_prefix(needle, 'library ') + needle = remove_prefix(needle, 'import library ') + needle = remove_prefix(needle, 'reload library ') + needle = remove_prefix(needle, 'get library instance ') + + matches = complete_libraries(needle) else: # Clear selector completion highlights for driver in yield_current_connection( diff --git a/src/robotkernel/utils.py b/src/robotkernel/utils.py index b8af272e..e7aa2ee4 100644 --- a/src/robotkernel/utils.py +++ b/src/robotkernel/utils.py @@ -77,6 +77,12 @@ def lunr_builder(ref, fields): return builder +def remove_prefix(value, prefix): + if value.startswith(prefix): + value = value[len(prefix):] + return value + + def readable_keyword(s): """Return keyword with only the first letter in title case.""" if s and not s.startswith("*") and not s.startswith("["):