Skip to content

Commit 24c3bc3

Browse files
DEBUG get_suggestions, returning many non matching words
1 parent 3a6af93 commit 24c3bc3

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/robotide/editor/texteditor.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,10 +1223,14 @@ def on_content_assist(self, event):
12231223
"""
12241224
self.store_position()
12251225
selected = self.source_editor.get_selected_or_near_text()
1226+
print(f"DEBUG: texteditor.py SourceEditor SELECTION selected = {selected} is type={type(selected)}")
12261227
self.set_editor_caret_position()
12271228
self._suggestions.update_from_local(self.words_cache(self.source_editor.GetLineCount()), self.language)
12281229
sugs = set()
12291230
if selected:
1231+
selected = list(selected)
1232+
selected = ([selected[0], selected[-1].split(' ')[-1]] if selected[0] != selected[-1].split(' ')[-1]
1233+
else [selected[0]])
12301234
for start in selected:
12311235
found = []
12321236
for s in self._suggestions.get_suggestions(start):
@@ -1235,22 +1239,25 @@ def on_content_assist(self, event):
12351239
else:
12361240
found.append(s)
12371241
sugs.update(found)
1242+
print(f"DEBUG: texteditor.py SourceEditor on_content_assist FIRST SUGGESTION suggestions = {sugs}\n")
12381243
# DEBUG: Here, if sugs is still [], then we can get all words from line and repeat suggestions
12391244
# In another evolution, we can use database of words by frequency (considering future by project db)
12401245
sel = [s for s in selected] if selected else ['']
12411246
entry_word = sel[0].split('.')[-1].strip()
12421247
length_entered = len(entry_word) # Because Libraries prefixed
1243-
print(f"DEBUG: texteditor.py SourceEditor on_content_assist selection = {sel}")
1248+
# print(f"DEBUG: texteditor.py SourceEditor on_content_assist selection = {sel}")
12441249
# if sel[0] == '':
12451250
# The case when we call Ctl+Space in empty line o always add suggestions
1246-
found = []
1247-
for start in sel:
1251+
# for start in sel:
1252+
print(f"DEBUG: texteditor.py SourceEditor on_content_assist selection = {sel}")
1253+
if sel[0] == '':
1254+
found = []
12481255
for s in self._suggestions.get_suggestions(''):
12491256
if hasattr(s, 'name'):
12501257
found.append(s.name)
12511258
else:
12521259
found.append(s)
1253-
sugs.update(found)
1260+
sugs.update(found)
12541261
if len(sel[0]) >= 2: # Search again with and without variable prefixes
12551262
found = []
12561263
for start in sel:

src/robotide/namespace/local_namespace.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self, controller, namespace):
3030
self.namespace = namespace
3131

3232
def get_suggestions(self, start):
33+
print(f"DEBUG: local_namespace.py LocalMacroNamespace get_suggestions ENTER start={start}")
3334
return self.namespace.get_suggestions_for(self._controller, start)
3435

3536
def has_name(self, value):
@@ -55,6 +56,8 @@ def __init__(self, controller, namespace, row):
5556

5657
def get_suggestions(self, start):
5758
suggestions = LocalMacroNamespace.get_suggestions(self, start)
59+
print(f"DEBUG: suggesters.py LocalRowNamespace get_suggestions after LocalMacroNamespace start={start}\n"
60+
f"suggestions={suggestions}")
5861
if self._could_be_variable(start):
5962
suggestions = self._harvest_local_variables(start, suggestions)
6063
else:

src/robotide/namespace/namespace.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def get_suggestions_for(self, controller, start):
138138
datafile = controller.datafile
139139
ctx = self._context_factory.ctx_for_controller(controller)
140140
sugs = self._words_cache or set()
141+
print(f"DEBUG: namespace.py Namespace get_suggestions_for ENTER start={start} {datafile=} {ctx=} {sugs=}")
141142
while start and start[-1] in [']', '}', '=', ',']:
142143
start = start[:-1]
143144
sugs.update(self._get_suggestions_from_hooks(datafile, start))
@@ -153,6 +154,7 @@ def get_suggestions_for(self, controller, start):
153154
sugs.update(self._content_suggestions(start))
154155
sugs_list = list(sugs)
155156
sugs_list.sort()
157+
print(f"DEBUG: namespace.py Namespace get_suggestions_for RETURN {sugs_list=}")
156158
return sugs_list
157159

158160
def _get_suggestions_from_hooks(self, datafile, start):
@@ -188,7 +190,8 @@ def _content_suggestions(self, start):
188190
ArgumentInfo, LibraryKeywordInfo, BlockKeywordInfo)):
189191
if v.name.lower().startswith(start.lower()):
190192
sugs.update(v.name)
191-
elif v.lower().startswith(start.lower()) or v.strip('[').lower().startswith(start.lower()):
193+
elif (v.lower().startswith(start.lower()) or v.strip('$&@%{[(').lower()
194+
.startswith(start.strip('$&@%{[(').lower())):
192195
sugs.update(v)
193196
return sugs
194197

src/robotide/namespace/suggesters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_suggestions(self, value, row=None):
2929
start = value
3030
while start and start[-1] in [']', '}', '=', ',']:
3131
start = start[:-1]
32-
print(f"DEBUG: suggesters.py SuggestionSource get_suggestions SEARCHING start={start}")
32+
# print(f"DEBUG: suggesters.py SuggestionSource get_suggestions SEARCHING start={start}")
3333
# If we have a space separated value, try first the value and then the last word
3434
key = start.split(' ')[-1]
3535
keys = [start, key] if start != key else [start]
@@ -131,6 +131,7 @@ class BuiltInLibrariesSuggester(_Suggester):
131131

132132
def get_suggestions(self, name, *args):
133133
_ = args
134+
print(f"DEBUG: suggesters.py BuiltInLibrariesSuggester get_suggestions ENTER name={name}")
134135
return [self._suggestion(n) for n in sorted(robotapi.STDLIB_NAMES)
135136
if name.lower() in n.lower() and n not in ['BuiltIn', 'Reserved', 'Easter']]
136137

0 commit comments

Comments
 (0)