Skip to content

Commit 023bfd7

Browse files
committed
fix(langserver): correct duplicate items in completions
1 parent c96a321 commit 023bfd7

File tree

1 file changed

+26
-21
lines changed
  • packages/language_server/src/robotcode/language_server/robotframework/parts

1 file changed

+26
-21
lines changed

packages/language_server/src/robotcode/language_server/robotframework/parts/completion.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ async def resolve(self, sender: Any, completion_item: CompletionItem) -> Complet
174174

175175

176176
_CompleteMethod = Callable[
177-
[ast.AST, List[ast.AST], Position, Optional[CompletionContext]],
177+
[Any, ast.AST, List[ast.AST], Position, Optional[CompletionContext]],
178178
Awaitable[Optional[Optional[List[CompletionItem]]]],
179179
]
180180

@@ -287,27 +287,29 @@ def __init__(
287287

288288
_method_cache: Dict[Type[Any], List[_CompleteMethod]] = {}
289289

290-
async def _find_methods(self, cls: Type[Any]) -> AsyncIterator[_CompleteMethod]:
291-
if cls in self._method_cache:
292-
for m in self._method_cache[cls]:
290+
@classmethod
291+
def _find_methods(cls, visitor_cls: Type[Any]) -> Iterator[_CompleteMethod]:
292+
if visitor_cls in cls._method_cache:
293+
for m in cls._method_cache[visitor_cls]:
293294
yield m
295+
return
294296

295297
methods = []
296-
if cls is ast.AST:
298+
if visitor_cls is ast.AST:
297299
return
298300

299-
method_name = "complete_" + cls.__name__
300-
if hasattr(self, method_name):
301-
method = getattr(self, method_name)
301+
method_name = "complete_" + visitor_cls.__name__
302+
if hasattr(cls, method_name):
303+
method = getattr(cls, method_name)
302304
if callable(method):
303305
methods.append(method)
304306
yield cast(_CompleteMethod, method)
305-
for base in cls.__bases__:
306-
async for m in self._find_methods(base):
307+
for base in visitor_cls.__bases__:
308+
for m in cls._find_methods(base):
307309
methods.append(m)
308310
yield m
309311

310-
self._method_cache[cls] = methods
312+
cls._method_cache[visitor_cls] = methods
311313

312314
async def collect(
313315
self, position: Position, context: Optional[CompletionContext]
@@ -320,8 +322,8 @@ async def collect(
320322

321323
async def iter_results() -> AsyncIterator[List[CompletionItem]]:
322324
for result_node in result_nodes:
323-
async for method in self._find_methods(type(result_node)):
324-
r = await method(result_node, result_nodes, position, context)
325+
for method in self._find_methods(type(result_node)):
326+
r = await method(self, result_node, result_nodes, position, context)
325327
if r is not None:
326328
yield r
327329

@@ -721,20 +723,23 @@ def get_keyword_snipped_text(self, kw: KeywordDoc, in_template: bool) -> str:
721723

722724
else:
723725
for index, match in enumerate(VariableMatches(kw.name, identifiers="$", ignore_errors=True)):
724-
var_name = variable[2:-1].split(":", 1)[0]
726+
var_name = match.base.split(":", 1)[0] if match.base else ""
725727
result += match.before
726-
result += "${" + str(index + 1) + ":"
727-
if in_template:
728-
result += "\\${"
728+
result += "${" + str(index + 1)
729729

730-
result += var_name
730+
if var_name:
731+
result += ":"
732+
if in_template:
733+
result += "\\${"
731734

732-
if in_template:
733-
result += "\\}"
735+
result += var_name
736+
737+
if in_template:
738+
result += "\\}"
734739

735740
result += "}"
736741

737-
if after:
742+
if match.after:
738743
result += match.after
739744

740745
return result

0 commit comments

Comments
 (0)