Skip to content

Commit 9b98b87

Browse files
committed
correct finding vars in parameter in keyword calls with assignments
1 parent 981e790 commit 9b98b87

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

robotcode/language_server/robotframework/diagnostics/entities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class VariableDefinition(SourceEntity):
9090
type: VariableDefinitionType = VariableDefinitionType.VARIABLE
9191

9292
def __hash__(self) -> int:
93-
return hash((type(self), self.name, self.type))
93+
return hash((type(self), self.name, self.type, self.range, self.source))
9494

9595
def range(self) -> Range:
9696
return Range(

robotcode/language_server/robotframework/diagnostics/namespace.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
Range,
3636
)
3737
from ...common.text_document import TextDocument
38-
from ..utils.ast import Token, range_from_node, tokenize_variables
38+
from ..utils.ast import Token, range_from_node, range_from_token, tokenize_variables
3939
from ..utils.async_ast import AsyncVisitor
4040
from .entities import (
4141
ArgumentDefinition,
@@ -203,19 +203,29 @@ async def visit_KeywordCall(self, node: ast.AST) -> None: # noqa: N802
203203
# TODO analyse "Set Local/Global/Suite Variable"
204204

205205
n = cast(KeywordCall, node)
206+
206207
for assign_token in n.get_tokens(RobotToken.ASSIGN):
207208
variable_token = self.get_variable_token(assign_token)
209+
208210
try:
209-
if variable_token is not None and variable_token.value not in self._results:
210-
self._results[variable_token.value] = LocalVariableDefinition(
211-
name=variable_token.value,
212-
name_token=variable_token,
213-
line_no=variable_token.lineno,
214-
col_offset=variable_token.col_offset,
215-
end_line_no=variable_token.lineno,
216-
end_col_offset=variable_token.end_col_offset,
217-
source=self.source,
218-
)
211+
if variable_token is not None:
212+
if (
213+
self.position is not None
214+
and self.position in range_from_node(n)
215+
and self.position > range_from_token(variable_token).end
216+
):
217+
continue
218+
219+
if variable_token.value not in self._results:
220+
self._results[variable_token.value] = LocalVariableDefinition(
221+
name=variable_token.value,
222+
name_token=variable_token,
223+
line_no=variable_token.lineno,
224+
col_offset=variable_token.col_offset,
225+
end_line_no=variable_token.lineno,
226+
end_col_offset=variable_token.end_col_offset,
227+
source=self.source,
228+
)
219229

220230
except VariableError:
221231
pass

0 commit comments

Comments
 (0)