Skip to content

Commit

Permalink
feat(langserver): support for new VAR statement in RF7
Browse files Browse the repository at this point in the history
  • Loading branch information
d-biehl committed Nov 20, 2023
1 parent f799fb4 commit 2678884
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from robot.parsing.model.statements import LibraryImport as RobotLibraryImport
from robot.parsing.model.statements import ResourceImport as RobotResourceImport
from robot.parsing.model.statements import VariablesImport as RobotVariablesImport
from robot.variables.search import is_scalar_assign, search_variable
from robot.variables.search import is_scalar_assign, is_variable, search_variable
from robotcode.core.async_tools import Lock, async_event
from robotcode.core.logging import LoggingDescriptor
from robotcode.core.lsp.types import (
Expand Down Expand Up @@ -227,7 +227,7 @@ def get_variable_token(self, token: Token) -> Optional[Token]:
v
for v in itertools.dropwhile(
lambda t: t.type in Token.NON_DATA_TOKENS,
tokenize_variables(token, ignore_errors=True),
tokenize_variables(token, ignore_errors=True, extra_types={Token.VARIABLE}),
)
if v.type == Token.VARIABLE
),
Expand Down Expand Up @@ -360,6 +360,27 @@ def visit_ForHeader(self, node: Statement) -> None: # noqa: N802
source=self.source,
)

def visit_Var(self, node: Statement) -> None: # noqa: N802
variable = node.get_token(Token.VARIABLE)
if variable is None:
return
try:
if not is_variable(variable.value):
return

self._results[variable.value] = LocalVariableDefinition(
name=variable.value,
name_token=strip_variable_token(variable),
line_no=variable.lineno,
col_offset=variable.col_offset,
end_line_no=variable.lineno,
end_col_offset=variable.end_col_offset,
source=self.source,
)

except VariableError:
pass


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

0 comments on commit 2678884

Please sign in to comment.