Skip to content

Commit a75c39b

Browse files
committed
Builtin Libraries code completion
Signed-off-by: martinRenou <martin.renou@gmail.com>
1 parent 55ef347 commit a75c39b

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/robotkernel/completion_finders.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Completion implementations."""
22

3-
from IPython.core.completerlib import get_root_modules
43
from robot.libraries import STDLIBS
54
from typing import List
65

@@ -9,7 +8,7 @@ def complete_libraries(needle: str,) -> List[str]:
98
"""Complete library names."""
109
matches = []
1110

12-
for lib in list(STDLIBS) + list(get_root_modules()):
11+
for lib in list(STDLIBS):
1312
if needle in lib.lower():
1413
matches.append(lib)
1514

src/robotkernel/kernel.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from robotkernel.utils import get_lunr_completions
3232
from robotkernel.utils import lunr_builder
3333
from robotkernel.utils import lunr_query
34+
from robotkernel.utils import remove_prefix
3435
from robotkernel.utils import scored_results
3536
from robotkernel.utils import yield_current_connection
3637
import re
@@ -138,7 +139,13 @@ def do_complete(self, code, cursor_pos):
138139
"get library instance" in line.lower(),
139140
]
140141
):
141-
matches = complete_libraries(needle.lower())
142+
needle = needle.lower()
143+
needle = remove_prefix(needle, 'library ')
144+
needle = remove_prefix(needle, 'import library ')
145+
needle = remove_prefix(needle, 'reload library ')
146+
needle = remove_prefix(needle, 'get library instance ')
147+
148+
matches = complete_libraries(needle)
142149
else:
143150
# Clear selector completion highlights
144151
for driver in yield_current_connection(

src/robotkernel/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def lunr_builder(ref, fields):
7777
return builder
7878

7979

80+
def remove_prefix(value, prefix):
81+
if value.startswith(prefix):
82+
value = value[len(prefix):]
83+
return value
84+
85+
8086
def readable_keyword(s):
8187
"""Return keyword with only the first letter in title case."""
8288
if s and not s.startswith("*") and not s.startswith("["):

0 commit comments

Comments
 (0)