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 9fa744c commit 9a87603
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 2 additions & 3 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,8 +8,8 @@ def complete_libraries(needle: str,) -> List[str]:
"""Complete library names."""
matches = []

for lib in list(STDLIBS) + list(get_root_modules()):
if needle in lib.lower():
for lib in list(STDLIBS):
if lib.lower().startswith(needle):
matches.append(lib)

return matches
11 changes: 9 additions & 2 deletions src/robotkernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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

Expand Down Expand Up @@ -171,9 +172,15 @@ def do_complete(self, code, cursor_pos):
]
):
self.log.debug("Context: Library name")
matches = complete_libraries(needle.lower())
metadata_type = "class"

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)
metadata_type = "class"
else:
self.log.debug("Context: Keywords or Built-ins")
# Clear selector completion highlights
Expand Down
6 changes: 6 additions & 0 deletions src/robotkernel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,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 in title case."""
if s and not s.startswith("*") and not s.startswith("["):
Expand Down

0 comments on commit 9a87603

Please sign in to comment.