Skip to content

Commit

Permalink
Builtin Libraries code completion
Browse files Browse the repository at this point in the history
Signed-off-by: martinRenou <[email protected]>
  • Loading branch information
martinRenou committed Dec 1, 2020
1 parent 55ef347 commit a75c39b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/robotkernel/completion_finders.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Completion implementations."""

from IPython.core.completerlib import get_root_modules
from robot.libraries import STDLIBS
from typing import List

Expand All @@ -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)

Expand Down
9 changes: 8 additions & 1 deletion src/robotkernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions src/robotkernel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("["):
Expand Down

0 comments on commit a75c39b

Please sign in to comment.