Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builtin Libraries code completion #11

Open
wants to merge 1 commit into
base: robocode
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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