Skip to content

Commit 2678884

Browse files
committed
feat(langserver): support for new VAR statement in RF7
1 parent f799fb4 commit 2678884

File tree

1 file changed

+23
-2
lines changed
  • packages/language_server/src/robotcode/language_server/robotframework/diagnostics

1 file changed

+23
-2
lines changed

packages/language_server/src/robotcode/language_server/robotframework/diagnostics/namespace.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from robot.parsing.model.statements import LibraryImport as RobotLibraryImport
3535
from robot.parsing.model.statements import ResourceImport as RobotResourceImport
3636
from robot.parsing.model.statements import VariablesImport as RobotVariablesImport
37-
from robot.variables.search import is_scalar_assign, search_variable
37+
from robot.variables.search import is_scalar_assign, is_variable, search_variable
3838
from robotcode.core.async_tools import Lock, async_event
3939
from robotcode.core.logging import LoggingDescriptor
4040
from robotcode.core.lsp.types import (
@@ -227,7 +227,7 @@ def get_variable_token(self, token: Token) -> Optional[Token]:
227227
v
228228
for v in itertools.dropwhile(
229229
lambda t: t.type in Token.NON_DATA_TOKENS,
230-
tokenize_variables(token, ignore_errors=True),
230+
tokenize_variables(token, ignore_errors=True, extra_types={Token.VARIABLE}),
231231
)
232232
if v.type == Token.VARIABLE
233233
),
@@ -360,6 +360,27 @@ def visit_ForHeader(self, node: Statement) -> None: # noqa: N802
360360
source=self.source,
361361
)
362362

363+
def visit_Var(self, node: Statement) -> None: # noqa: N802
364+
variable = node.get_token(Token.VARIABLE)
365+
if variable is None:
366+
return
367+
try:
368+
if not is_variable(variable.value):
369+
return
370+
371+
self._results[variable.value] = LocalVariableDefinition(
372+
name=variable.value,
373+
name_token=strip_variable_token(variable),
374+
line_no=variable.lineno,
375+
col_offset=variable.col_offset,
376+
end_line_no=variable.lineno,
377+
end_col_offset=variable.end_col_offset,
378+
source=self.source,
379+
)
380+
381+
except VariableError:
382+
pass
383+
363384

364385
class ImportVisitor(Visitor):
365386
def get(self, source: str, model: ast.AST) -> List[Import]:

0 commit comments

Comments
 (0)