Skip to content

Commit 5a8abf2

Browse files
committed
fix: corrected parsing of OPTION tokens and variable resolving
fixes: #289 and #295
1 parent 161d8ab commit 5a8abf2

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@
101101
from robot.variables.search import VariableMatches
102102

103103

104+
if get_robot_version() < (5, 0):
105+
ALLOWED_VARIABLE_TOKENS = [
106+
Token.NAME,
107+
Token.ARGUMENT,
108+
Token.KEYWORD,
109+
Token.ASSIGN,
110+
]
111+
else:
112+
ALLOWED_VARIABLE_TOKENS = [
113+
Token.NAME,
114+
Token.ARGUMENT,
115+
Token.KEYWORD,
116+
Token.ASSIGN,
117+
Token.OPTION,
118+
]
119+
120+
104121
DEFAULT_HEADER_STYLE = "*** {name}s ***"
105122
DEFAULT_HEADER_STYLE_51 = "*** {name} ***"
106123

@@ -1141,12 +1158,7 @@ def complete_default(
11411158
break
11421159
token_at_position = tokens_at_position[token_at_position_index]
11431160

1144-
if token_at_position.type not in [
1145-
Token.NAME,
1146-
Token.ARGUMENT,
1147-
Token.KEYWORD,
1148-
Token.ASSIGN,
1149-
]:
1161+
if token_at_position.type not in ALLOWED_VARIABLE_TOKENS:
11501162
return None
11511163

11521164
close_brace_index_before = token_at_position.value.rfind(

packages/robot/src/robotcode/robot/diagnostics/namespace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def visit_Var(self, node: Statement) -> None: # noqa: N802
538538
source=self.namespace.source,
539539
)
540540

541-
if var_name not in self._results or type(self._results[var_name]) is type(var):
541+
if var_name not in self._results or type(self._results[var_name]) is not type(var):
542542
if isinstance(var, LocalVariableDefinition) or not any(
543543
l for l in self.namespace.get_global_variables() if l.matcher == var.matcher
544544
):

packages/robot/src/robotcode/robot/utils/ast.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,21 @@ def _tokenize_no_variables(token: Token) -> Iterator[Token]:
225225
yield token
226226

227227

228+
if get_robot_version() < (5, 0):
229+
ALLOWED_TOKEN_TYPES = {
230+
*Token.ALLOW_VARIABLES,
231+
Token.KEYWORD,
232+
Token.ASSIGN,
233+
}
234+
else:
235+
ALLOWED_TOKEN_TYPES = {
236+
*Token.ALLOW_VARIABLES,
237+
Token.KEYWORD,
238+
Token.ASSIGN,
239+
Token.OPTION,
240+
}
241+
242+
228243
def tokenize_variables(
229244
token: Token,
230245
identifiers: str = "$@&%",
@@ -233,9 +248,7 @@ def tokenize_variables(
233248
extra_types: Optional[Set[str]] = None,
234249
) -> Iterator[Token]:
235250
if token.type not in {
236-
*Token.ALLOW_VARIABLES,
237-
Token.KEYWORD,
238-
Token.ASSIGN,
251+
*ALLOWED_TOKEN_TYPES,
239252
*(extra_types if extra_types is not None else set()),
240253
}:
241254
return _tokenize_no_variables(token)

0 commit comments

Comments
 (0)