robotcode-robot 2.6.2__py3-none-any.whl → 2.8.0.dev548__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robotcode/robot/__version__.py +1 -1
- robotcode/robot/config/loader.py +18 -5
- robotcode/robot/config/model.py +258 -61
- robotcode/robot/diagnostics/analyzer_result.py +1 -0
- robotcode/robot/diagnostics/data_cache.py +12 -1
- robotcode/robot/diagnostics/diagnostic_rules.py +75 -0
- robotcode/robot/diagnostics/diagnostics_modifier.py +83 -43
- robotcode/robot/diagnostics/document_cache_helper.py +158 -17
- robotcode/robot/diagnostics/errors.py +7 -0
- robotcode/robot/diagnostics/import_resolver.py +178 -12
- robotcode/robot/diagnostics/imports_manager.py +556 -220
- robotcode/robot/diagnostics/library_doc.py +874 -162
- robotcode/robot/diagnostics/namespace.py +84 -18
- robotcode/robot/diagnostics/namespace_analyzer.py +59 -16
- robotcode/robot/diagnostics/project_index.py +88 -13
- robotcode/robot/diagnostics/scope_tree.py +2 -2
- robotcode/robot/diagnostics/semantic_analyzer/analyzer.py +790 -201
- robotcode/robot/diagnostics/semantic_analyzer/enums.py +39 -2
- robotcode/robot/diagnostics/semantic_analyzer/json_dump.py +364 -0
- robotcode/robot/diagnostics/semantic_analyzer/model.py +72 -11
- robotcode/robot/diagnostics/semantic_analyzer/nodes.py +7 -1
- robotcode/robot/diagnostics/semantic_analyzer/variable_tokenizer.py +218 -112
- robotcode/robot/diagnostics/workspace_config.py +3 -0
- robotcode/robot/utils/markdown_docs.py +733 -0
- robotcode/robot/utils/markdownformatter.py +57 -12
- robotcode/robot/utils/match.py +13 -0
- robotcode/robot/utils/robot_patching.py +4 -0
- robotcode/robot/utils/variables.py +3 -0
- {robotcode_robot-2.6.2.dist-info → robotcode_robot-2.8.0.dev548.dist-info}/METADATA +4 -3
- robotcode_robot-2.8.0.dev548.dist-info/RECORD +48 -0
- {robotcode_robot-2.6.2.dist-info → robotcode_robot-2.8.0.dev548.dist-info}/WHEEL +1 -1
- robotcode_robot-2.6.2.dist-info/RECORD +0 -46
|
@@ -46,12 +46,14 @@ from robot.parsing.model.statements import (
|
|
|
46
46
|
Break,
|
|
47
47
|
Comment,
|
|
48
48
|
Continue,
|
|
49
|
+
Documentation,
|
|
49
50
|
EmptyLine,
|
|
50
51
|
End,
|
|
51
52
|
Fixture,
|
|
52
53
|
KeywordCall,
|
|
53
54
|
KeywordName,
|
|
54
55
|
LibraryImport,
|
|
56
|
+
Metadata,
|
|
55
57
|
ResourceImport,
|
|
56
58
|
Statement,
|
|
57
59
|
Template,
|
|
@@ -89,7 +91,7 @@ from ...utils.ast import (
|
|
|
89
91
|
strip_variable_token,
|
|
90
92
|
tokenize_variables,
|
|
91
93
|
)
|
|
92
|
-
from ...utils.match import normalize
|
|
94
|
+
from ...utils.match import normalize, normalize_metadata_name
|
|
93
95
|
from ...utils.stubs import Languages
|
|
94
96
|
from ...utils.variables import (
|
|
95
97
|
BUILTIN_VARIABLES,
|
|
@@ -104,6 +106,7 @@ from ...utils.variables import (
|
|
|
104
106
|
)
|
|
105
107
|
from ...utils.visitor import Visitor
|
|
106
108
|
from ..analyzer_result import AnalyzerResult
|
|
109
|
+
from ..diagnostic_rules import private_keyword_call_message, tags_row_without_empty_row
|
|
107
110
|
from ..entities import (
|
|
108
111
|
ArgumentDefinition,
|
|
109
112
|
BuiltInVariableDefinition,
|
|
@@ -123,6 +126,8 @@ from ..import_resolver import ImportResolver, ResolvedImports
|
|
|
123
126
|
from ..imports_manager import ImportsManager
|
|
124
127
|
from ..keyword_finder import KeywordFinder
|
|
125
128
|
from ..library_doc import (
|
|
129
|
+
BUILTIN_LIBRARY_NAME,
|
|
130
|
+
KeywordArgumentKind,
|
|
126
131
|
KeywordDoc,
|
|
127
132
|
KeywordMatcher,
|
|
128
133
|
LibraryDoc,
|
|
@@ -131,7 +136,7 @@ from ..library_doc import (
|
|
|
131
136
|
)
|
|
132
137
|
from ..scope_tree import ScopeTreeBuilder
|
|
133
138
|
from ..variable_scope import VariableScope
|
|
134
|
-
from .enums import ForFlavor, ForZipMode, ImportType, NodeKind, OnLimitAction, TokenKind
|
|
139
|
+
from .enums import ForFlavor, ForZipMode, ImportType, NodeKind, OnLimitAction, TokenKind, TokenModifier
|
|
135
140
|
from .model import SemanticModel
|
|
136
141
|
from .nodes import (
|
|
137
142
|
DefinitionBlock,
|
|
@@ -164,6 +169,9 @@ from .run_keyword import (
|
|
|
164
169
|
from .variable_tokenizer import (
|
|
165
170
|
_MATCH_EXTENDED,
|
|
166
171
|
VariableOccurrence,
|
|
172
|
+
VariableSite,
|
|
173
|
+
_build_python_expression_sub_tokens,
|
|
174
|
+
build_variable_sub_tokens,
|
|
167
175
|
iter_variable_occurrences_from_token,
|
|
168
176
|
iter_variable_tokens_with_index_access,
|
|
169
177
|
)
|
|
@@ -257,6 +265,8 @@ class SemanticAnalyzer(Visitor):
|
|
|
257
265
|
|
|
258
266
|
self._current_testcase_or_keyword_name: Optional[str] = None
|
|
259
267
|
self._current_keyword_doc: Optional[KeywordDoc] = None
|
|
268
|
+
self._in_keyword = False
|
|
269
|
+
self._in_testcase = False
|
|
260
270
|
self._test_template: Optional[TestTemplate] = None
|
|
261
271
|
self._template: Optional[Template] = None
|
|
262
272
|
self._node_stack: List[ast.AST] = []
|
|
@@ -269,6 +279,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
269
279
|
self._keyword_tag_references: Dict[str, Set[Location]] = defaultdict(set)
|
|
270
280
|
self._testcase_tag_references: Dict[str, Set[Location]] = defaultdict(set)
|
|
271
281
|
self._metadata_references: Dict[str, Set[Location]] = defaultdict(set)
|
|
282
|
+
self._testcase_metadata_references: Dict[str, Set[Location]] = defaultdict(set)
|
|
272
283
|
|
|
273
284
|
# Phase 1+2 results (set by resolve())
|
|
274
285
|
self._library_doc: ResourceDoc = cast(ResourceDoc, None)
|
|
@@ -302,6 +313,12 @@ class SemanticAnalyzer(Visitor):
|
|
|
302
313
|
# RunKeywordCallStatement support: inner calls collected during _analyze_run_keyword
|
|
303
314
|
self._last_inner_calls: list[KeywordCallStatement] = []
|
|
304
315
|
|
|
316
|
+
# Positions (line, col) of ELSE / ELSE IF / AND separator cells inside
|
|
317
|
+
# Run Keyword variants, recorded during run-keyword analysis. Token
|
|
318
|
+
# builders mark these ARGUMENT cells as CONTROL_FLOW. Positions are
|
|
319
|
+
# unique per file, so the set accumulates without per-statement resets.
|
|
320
|
+
self._rk_separator_positions: Set[Tuple[int, int]] = set()
|
|
321
|
+
|
|
305
322
|
# Token-decomposition info populated by _analyze_keyword_call() for the
|
|
306
323
|
# current keyword call. Visitors read these after the analysis call to
|
|
307
324
|
# build BDD_PREFIX / NAMESPACE / SEPARATOR / KEYWORD splits, and to
|
|
@@ -401,6 +418,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
401
418
|
self._keyword_tag_references,
|
|
402
419
|
self._testcase_tag_references,
|
|
403
420
|
self._metadata_references,
|
|
421
|
+
self._testcase_metadata_references,
|
|
404
422
|
self._scope_builder.build(self._variable_scope),
|
|
405
423
|
semantic_model=self._semantic_model,
|
|
406
424
|
)
|
|
@@ -772,6 +790,72 @@ class SemanticAnalyzer(Visitor):
|
|
|
772
790
|
)
|
|
773
791
|
self._add_statement(stmt)
|
|
774
792
|
|
|
793
|
+
# --- Variables section rows ---
|
|
794
|
+
|
|
795
|
+
def visit_Variable(self, node: Variable) -> None: # noqa: N802
|
|
796
|
+
"""Variables-section row: the defining name is a variable with sub-tokens
|
|
797
|
+
split as a declaration; values get variable decomposition; `&{dict}` rows
|
|
798
|
+
split `key=value` items into named-argument sub-tokens (legacy behavior)."""
|
|
799
|
+
self._analyze_statement_variables(node)
|
|
800
|
+
|
|
801
|
+
name_token = node.get_token(Token.VARIABLE)
|
|
802
|
+
is_dict = bool(name_token is not None and name_token.value and name_token.value.startswith("&"))
|
|
803
|
+
|
|
804
|
+
def handle_argument(t: Token) -> List[SemanticToken]:
|
|
805
|
+
if is_dict:
|
|
806
|
+
return [self._build_dict_item_token(t)]
|
|
807
|
+
return [self._build_argument_semantic_token(t, keyword_doc=None)]
|
|
808
|
+
|
|
809
|
+
stmt = SemanticStatement(
|
|
810
|
+
kind=NodeKind.VARIABLE_DEF,
|
|
811
|
+
line_start=node.lineno,
|
|
812
|
+
line_end=node.end_lineno or node.lineno,
|
|
813
|
+
tokens=self._build_header_tokens(
|
|
814
|
+
node,
|
|
815
|
+
special={
|
|
816
|
+
Token.VARIABLE: lambda t: [
|
|
817
|
+
self._build_token_with_var_subtokens(t, TokenKind.VARIABLE, site=VariableSite.DECLARATION)
|
|
818
|
+
],
|
|
819
|
+
Token.ARGUMENT: handle_argument,
|
|
820
|
+
},
|
|
821
|
+
),
|
|
822
|
+
)
|
|
823
|
+
self._add_statement(stmt)
|
|
824
|
+
|
|
825
|
+
def _build_dict_item_token(self, rf_token: Token) -> SemanticToken:
|
|
826
|
+
"""`&{dict}` definition item: `key=value` splits into
|
|
827
|
+
NAMED_ARGUMENT_NAME + OPERATOR + NAMED_ARGUMENT_VALUE (with variable
|
|
828
|
+
decomposition on the value half)."""
|
|
829
|
+
value = rf_token.value
|
|
830
|
+
line = rf_token.lineno
|
|
831
|
+
col = rf_token.col_offset
|
|
832
|
+
name, item_value = split_from_equals(value)
|
|
833
|
+
if item_value is None:
|
|
834
|
+
return self._build_argument_semantic_token(rf_token, keyword_doc=None)
|
|
835
|
+
parent = SemanticToken(
|
|
836
|
+
kind=TokenKind.ARGUMENT,
|
|
837
|
+
value=value,
|
|
838
|
+
line=line,
|
|
839
|
+
col_offset=col,
|
|
840
|
+
length=len(value),
|
|
841
|
+
)
|
|
842
|
+
value_col = col + len(name) + 1
|
|
843
|
+
value_rf_token = Token(Token.ARGUMENT, item_value, line, value_col)
|
|
844
|
+
value_subs = self._argument_sub_tokens(value_rf_token) if item_value else None
|
|
845
|
+
parent.sub_tokens = [
|
|
846
|
+
SemanticToken(kind=TokenKind.NAMED_ARGUMENT_NAME, value=name, line=line, col_offset=col, length=len(name)),
|
|
847
|
+
SemanticToken(kind=TokenKind.OPERATOR, value="=", line=line, col_offset=col + len(name), length=1),
|
|
848
|
+
SemanticToken(
|
|
849
|
+
kind=TokenKind.NAMED_ARGUMENT_VALUE,
|
|
850
|
+
value=item_value,
|
|
851
|
+
line=line,
|
|
852
|
+
col_offset=value_col,
|
|
853
|
+
length=len(item_value),
|
|
854
|
+
sub_tokens=value_subs,
|
|
855
|
+
),
|
|
856
|
+
]
|
|
857
|
+
return parent
|
|
858
|
+
|
|
775
859
|
# --- Generic statement visitor ---
|
|
776
860
|
|
|
777
861
|
# Mapping from RF Token type to SemanticModel TokenKind.
|
|
@@ -784,7 +868,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
784
868
|
Token.CONTINUE: TokenKind.CONTROL_FLOW,
|
|
785
869
|
Token.RETURN_STATEMENT: TokenKind.CONTROL_FLOW,
|
|
786
870
|
Token.FOR: TokenKind.CONTROL_FLOW,
|
|
787
|
-
Token.FOR_SEPARATOR: TokenKind.
|
|
871
|
+
Token.FOR_SEPARATOR: TokenKind.FOR_SEPARATOR,
|
|
788
872
|
Token.IF: TokenKind.CONTROL_FLOW,
|
|
789
873
|
Token.ELSE_IF: TokenKind.CONTROL_FLOW,
|
|
790
874
|
Token.ELSE: TokenKind.CONTROL_FLOW,
|
|
@@ -810,16 +894,17 @@ class SemanticAnalyzer(Visitor):
|
|
|
810
894
|
# Structure
|
|
811
895
|
Token.CONTINUATION: TokenKind.CONTINUATION,
|
|
812
896
|
Token.SEPARATOR: TokenKind.SEPARATOR,
|
|
897
|
+
Token.EOL: TokenKind.EOL,
|
|
813
898
|
# Section headers
|
|
814
|
-
Token.TESTCASE_HEADER: TokenKind.
|
|
815
|
-
Token.KEYWORD_HEADER: TokenKind.
|
|
816
|
-
Token.SETTING_HEADER: TokenKind.
|
|
817
|
-
Token.VARIABLE_HEADER: TokenKind.
|
|
818
|
-
Token.COMMENT_HEADER: TokenKind.
|
|
899
|
+
Token.TESTCASE_HEADER: TokenKind.HEADER_TESTCASE,
|
|
900
|
+
Token.KEYWORD_HEADER: TokenKind.HEADER_KEYWORD,
|
|
901
|
+
Token.SETTING_HEADER: TokenKind.HEADER_SETTINGS,
|
|
902
|
+
Token.VARIABLE_HEADER: TokenKind.HEADER_VARIABLE,
|
|
903
|
+
Token.COMMENT_HEADER: TokenKind.HEADER_COMMENT,
|
|
819
904
|
# Import settings
|
|
820
|
-
Token.LIBRARY: TokenKind.
|
|
821
|
-
Token.RESOURCE: TokenKind.
|
|
822
|
-
Token.VARIABLES: TokenKind.
|
|
905
|
+
Token.LIBRARY: TokenKind.SETTING_IMPORT,
|
|
906
|
+
Token.RESOURCE: TokenKind.SETTING_IMPORT,
|
|
907
|
+
Token.VARIABLES: TokenKind.SETTING_IMPORT,
|
|
823
908
|
# Keyword / test settings
|
|
824
909
|
Token.SETUP: TokenKind.SETTING_NAME,
|
|
825
910
|
Token.TEARDOWN: TokenKind.SETTING_NAME,
|
|
@@ -839,7 +924,11 @@ class SemanticAnalyzer(Visitor):
|
|
|
839
924
|
Token.TEST_TEARDOWN: TokenKind.SETTING_NAME,
|
|
840
925
|
Token.TEST_TEMPLATE: TokenKind.SETTING_NAME,
|
|
841
926
|
Token.TEST_TIMEOUT: TokenKind.SETTING_NAME,
|
|
842
|
-
Token.WITH_NAME
|
|
927
|
+
# `WITH NAME` import alias marker. On RF 7.0+ `Token.WITH_NAME` is the
|
|
928
|
+
# same string as `Token.AS`, so this entry also covers `AS` there
|
|
929
|
+
# (including `EXCEPT ... AS`, matching the legacy rendering); on
|
|
930
|
+
# RF < 7.0 `Token.AS` above keeps its CONTROL_FLOW mapping.
|
|
931
|
+
Token.WITH_NAME: TokenKind.SETTING_IMPORT,
|
|
843
932
|
# Errors
|
|
844
933
|
Token.ERROR: TokenKind.ERROR,
|
|
845
934
|
Token.FATAL_ERROR: TokenKind.ERROR,
|
|
@@ -848,24 +937,23 @@ class SemanticAnalyzer(Visitor):
|
|
|
848
937
|
# Version-conditional token mappings
|
|
849
938
|
if RF_VERSION >= (6, 0):
|
|
850
939
|
_RF_TOKEN_TO_TOKEN_KIND[Token.CONFIG] = TokenKind.CONFIG
|
|
851
|
-
_RF_TOKEN_TO_TOKEN_KIND[Token.TASK_HEADER] = TokenKind.
|
|
940
|
+
_RF_TOKEN_TO_TOKEN_KIND[Token.TASK_HEADER] = TokenKind.HEADER_TASK
|
|
852
941
|
_RF_TOKEN_TO_TOKEN_KIND[Token.KEYWORD_TAGS] = TokenKind.SETTING_NAME
|
|
942
|
+
if RF_VERSION >= (6, 1):
|
|
943
|
+
# `Name` suite setting (RF 6.1+).
|
|
944
|
+
_RF_TOKEN_TO_TOKEN_KIND[Token.SUITE_NAME] = TokenKind.SETTING_NAME
|
|
853
945
|
if RF_VERSION >= (7, 0):
|
|
854
|
-
_RF_TOKEN_TO_TOKEN_KIND[Token.VAR] = TokenKind.
|
|
946
|
+
_RF_TOKEN_TO_TOKEN_KIND[Token.VAR] = TokenKind.VAR_MARKER
|
|
855
947
|
if RF_VERSION >= (7, 2):
|
|
856
948
|
_RF_TOKEN_TO_TOKEN_KIND[Token.GROUP] = TokenKind.CONTROL_FLOW
|
|
857
949
|
|
|
858
|
-
# Tokens to skip — whitespace and line structure tokens
|
|
859
|
-
_RF_SKIP_TOKENS: frozenset[str] = frozenset(
|
|
860
|
-
{
|
|
861
|
-
Token.EOL,
|
|
862
|
-
Token.EOS,
|
|
863
|
-
}
|
|
864
|
-
)
|
|
865
|
-
|
|
866
950
|
def _build_tokens_from_node(self, node: Statement) -> list[SemanticToken]:
|
|
867
|
-
"""Build SemanticToken list from an RF Statement node using the generic
|
|
868
|
-
|
|
951
|
+
"""Build SemanticToken list from an RF Statement node using the generic
|
|
952
|
+
mapping. ARGUMENT tokens always get variable decomposition."""
|
|
953
|
+
return self._build_header_tokens(
|
|
954
|
+
node,
|
|
955
|
+
special={Token.ARGUMENT: lambda t: [self._build_argument_semantic_token(t, keyword_doc=None)]},
|
|
956
|
+
)
|
|
869
957
|
|
|
870
958
|
def _build_header_tokens(
|
|
871
959
|
self,
|
|
@@ -875,12 +963,13 @@ class SemanticAnalyzer(Visitor):
|
|
|
875
963
|
"""Generic SemanticToken builder for header / statement nodes.
|
|
876
964
|
|
|
877
965
|
Walks the statement's RF tokens once and:
|
|
878
|
-
1. Skips tokens
|
|
879
|
-
|
|
880
|
-
|
|
966
|
+
1. Skips tokens without a value or position (this drops the
|
|
967
|
+
virtual `EOS` statement markers; `EOL` is kept as layout data
|
|
968
|
+
so the model stays reconstruction-complete).
|
|
969
|
+
2. For tokens whose `type` is in `special`, calls the handler and
|
|
881
970
|
extends with its result (returning `None` from the handler means
|
|
882
971
|
"fall through to the generic mapping").
|
|
883
|
-
|
|
972
|
+
3. Otherwise looks the type up in `_RF_TOKEN_TO_TOKEN_KIND` and
|
|
884
973
|
emits a single SemanticToken using the mapped TokenKind.
|
|
885
974
|
|
|
886
975
|
Centralising this loop ensures every header builder picks up the
|
|
@@ -890,8 +979,6 @@ class SemanticAnalyzer(Visitor):
|
|
|
890
979
|
"""
|
|
891
980
|
tokens: List[SemanticToken] = []
|
|
892
981
|
for rf_token in node.tokens:
|
|
893
|
-
if rf_token.type in self._RF_SKIP_TOKENS:
|
|
894
|
-
continue
|
|
895
982
|
if not rf_token.value or rf_token.col_offset is None:
|
|
896
983
|
continue
|
|
897
984
|
handler = special.get(rf_token.type)
|
|
@@ -900,30 +987,154 @@ class SemanticAnalyzer(Visitor):
|
|
|
900
987
|
if extra is not None:
|
|
901
988
|
tokens.extend(extra)
|
|
902
989
|
continue
|
|
903
|
-
|
|
904
|
-
if
|
|
990
|
+
sem_token = self._map_generic_token(rf_token)
|
|
991
|
+
if sem_token is not None:
|
|
992
|
+
tokens.append(sem_token)
|
|
993
|
+
return tokens
|
|
994
|
+
|
|
995
|
+
def _map_generic_token(self, rf_token: Token) -> Optional[SemanticToken]:
|
|
996
|
+
"""Map one RF token through `_RF_TOKEN_TO_TOKEN_KIND`, applying the
|
|
997
|
+
kind-specific build rules that must hold everywhere: bracket-setting
|
|
998
|
+
splits (`[Tags]` → `[` + name + `]`), documentation modifiers, and
|
|
999
|
+
definition-name variable splits. Central so every builder loop picks
|
|
1000
|
+
up the same final render semantics."""
|
|
1001
|
+
kind = self._RF_TOKEN_TO_TOKEN_KIND.get(rf_token.type)
|
|
1002
|
+
if kind is None:
|
|
1003
|
+
return None
|
|
1004
|
+
if kind is TokenKind.SETTING_NAME:
|
|
1005
|
+
return self._build_setting_name_token(rf_token)
|
|
1006
|
+
if kind is TokenKind.TEST_NAME or kind is TokenKind.KEYWORD_NAME:
|
|
1007
|
+
return self._build_definition_name_token(rf_token, kind)
|
|
1008
|
+
if rf_token.type == Token.ASSIGN:
|
|
1009
|
+
return self._build_token_with_var_subtokens(rf_token, kind, site=VariableSite.DECLARATION)
|
|
1010
|
+
return SemanticToken(
|
|
1011
|
+
kind=kind,
|
|
1012
|
+
value=rf_token.value,
|
|
1013
|
+
line=rf_token.lineno,
|
|
1014
|
+
col_offset=rf_token.col_offset,
|
|
1015
|
+
length=len(rf_token.value),
|
|
1016
|
+
)
|
|
1017
|
+
|
|
1018
|
+
def _build_setting_name_token(self, rf_token: Token) -> SemanticToken:
|
|
1019
|
+
"""Setting-name token: bracket settings (`[Tags]`, `[Setup]`, …) get
|
|
1020
|
+
OPERATOR + SETTING_NAME + OPERATOR sub-tokens; `[Documentation]` /
|
|
1021
|
+
`Metadata` names carry the DOCUMENTATION modifier."""
|
|
1022
|
+
value = rf_token.value
|
|
1023
|
+
line = rf_token.lineno
|
|
1024
|
+
col = rf_token.col_offset
|
|
1025
|
+
modifiers = (
|
|
1026
|
+
frozenset({TokenModifier.DOCUMENTATION}) if rf_token.type in (Token.DOCUMENTATION, Token.METADATA) else None
|
|
1027
|
+
)
|
|
1028
|
+
token = SemanticToken(
|
|
1029
|
+
kind=TokenKind.SETTING_NAME,
|
|
1030
|
+
value=value,
|
|
1031
|
+
line=line,
|
|
1032
|
+
col_offset=col,
|
|
1033
|
+
length=len(value),
|
|
1034
|
+
modifiers=modifiers,
|
|
1035
|
+
)
|
|
1036
|
+
if len(value) >= 2 and value[0] == "[" and value[-1] == "]":
|
|
1037
|
+
token.sub_tokens = [
|
|
1038
|
+
SemanticToken(kind=TokenKind.OPERATOR, value="[", line=line, col_offset=col, length=1),
|
|
1039
|
+
SemanticToken(
|
|
1040
|
+
kind=TokenKind.SETTING_NAME,
|
|
1041
|
+
value=value[1:-1],
|
|
1042
|
+
line=line,
|
|
1043
|
+
col_offset=col + 1,
|
|
1044
|
+
length=len(value) - 2,
|
|
1045
|
+
),
|
|
1046
|
+
SemanticToken(kind=TokenKind.OPERATOR, value="]", line=line, col_offset=col + len(value) - 1, length=1),
|
|
1047
|
+
]
|
|
1048
|
+
return token
|
|
1049
|
+
|
|
1050
|
+
def _build_definition_name_token(self, rf_token: Token, kind: TokenKind) -> SemanticToken:
|
|
1051
|
+
"""Definition-name token (test case / keyword name): embedded variables
|
|
1052
|
+
split into name-kind fragments + VARIABLE sub-tokens."""
|
|
1053
|
+
value = rf_token.value
|
|
1054
|
+
line = rf_token.lineno
|
|
1055
|
+
col = rf_token.col_offset
|
|
1056
|
+
token = SemanticToken(kind=kind, value=value, line=line, col_offset=col, length=len(value))
|
|
1057
|
+
|
|
1058
|
+
identifiers = "$" if kind is TokenKind.KEYWORD_NAME else "$@&%"
|
|
1059
|
+
site = VariableSite.KEYWORD_NAME if kind is TokenKind.KEYWORD_NAME else VariableSite.USAGE
|
|
1060
|
+
try:
|
|
1061
|
+
occurrences = list(
|
|
1062
|
+
iter_variable_occurrences_from_token(
|
|
1063
|
+
rf_token,
|
|
1064
|
+
identifiers=identifiers,
|
|
1065
|
+
site=site,
|
|
1066
|
+
is_defined=self._is_variable_defined,
|
|
1067
|
+
ignore_errors=True,
|
|
1068
|
+
)
|
|
1069
|
+
)
|
|
1070
|
+
except (VariableError, InvalidVariableError):
|
|
1071
|
+
occurrences = []
|
|
1072
|
+
if not occurrences:
|
|
1073
|
+
return token
|
|
1074
|
+
|
|
1075
|
+
sub_tokens: list[SemanticToken] = []
|
|
1076
|
+
cursor = col
|
|
1077
|
+
end_col = col + len(value)
|
|
1078
|
+
for occ in occurrences:
|
|
1079
|
+
if occ.col_offset < cursor:
|
|
905
1080
|
continue
|
|
906
|
-
|
|
1081
|
+
if occ.col_offset > cursor:
|
|
1082
|
+
text_value = value[cursor - col : occ.col_offset - col]
|
|
1083
|
+
if text_value:
|
|
1084
|
+
sub_tokens.append(
|
|
1085
|
+
SemanticToken(kind=kind, value=text_value, line=line, col_offset=cursor, length=len(text_value))
|
|
1086
|
+
)
|
|
1087
|
+
sub_tokens.append(
|
|
907
1088
|
SemanticToken(
|
|
908
|
-
kind=
|
|
909
|
-
value=
|
|
910
|
-
line=
|
|
911
|
-
col_offset=
|
|
912
|
-
length=
|
|
1089
|
+
kind=TokenKind.VARIABLE,
|
|
1090
|
+
value=occ.value,
|
|
1091
|
+
line=line,
|
|
1092
|
+
col_offset=occ.col_offset,
|
|
1093
|
+
length=occ.length,
|
|
1094
|
+
sub_tokens=occ.semantic_sub_tokens,
|
|
913
1095
|
)
|
|
914
1096
|
)
|
|
915
|
-
|
|
1097
|
+
cursor = occ.col_offset + occ.length
|
|
1098
|
+
if cursor < end_col:
|
|
1099
|
+
text_value = value[cursor - col :]
|
|
1100
|
+
if text_value:
|
|
1101
|
+
sub_tokens.append(
|
|
1102
|
+
SemanticToken(kind=kind, value=text_value, line=line, col_offset=cursor, length=len(text_value))
|
|
1103
|
+
)
|
|
1104
|
+
token.sub_tokens = sub_tokens
|
|
1105
|
+
return token
|
|
1106
|
+
|
|
1107
|
+
@staticmethod
|
|
1108
|
+
def _is_builtin_namespace(namespace: str) -> bool:
|
|
1109
|
+
"""True if the written namespace qualifier refers to the BuiltIn library
|
|
1110
|
+
(KeywordMatcher-style normalization: case, spaces, underscores)."""
|
|
1111
|
+
return namespace.replace(" ", "").replace("_", "").lower() == "builtin"
|
|
1112
|
+
|
|
1113
|
+
@staticmethod
|
|
1114
|
+
def _builtin_keyword_modifiers(kw_doc: Optional[KeywordDoc]) -> Optional[frozenset[TokenModifier]]:
|
|
1115
|
+
"""BUILTIN modifier set if the resolved keyword lives in the BuiltIn library."""
|
|
1116
|
+
if kw_doc is not None and kw_doc.libname == BUILTIN_LIBRARY_NAME:
|
|
1117
|
+
return frozenset({TokenModifier.BUILTIN})
|
|
1118
|
+
return None
|
|
916
1119
|
|
|
917
1120
|
def _split_keyword_name_token(
|
|
918
1121
|
self,
|
|
919
1122
|
rf_token: Token,
|
|
920
1123
|
bdd_prefix: Optional[str],
|
|
921
1124
|
namespace: Optional[str],
|
|
1125
|
+
kw_doc: Optional[KeywordDoc] = None,
|
|
1126
|
+
inner: bool = False,
|
|
1127
|
+
unresolved_as_argument: bool = False,
|
|
922
1128
|
) -> list[SemanticToken]:
|
|
923
|
-
"""Split a keyword-name RF Token into BDD_PREFIX + NAMESPACE +
|
|
1129
|
+
"""Split a keyword-name RF Token into BDD_PREFIX + NAMESPACE + OPERATOR + KEYWORD.
|
|
924
1130
|
|
|
925
1131
|
bdd_prefix may include a trailing space (RF reports e.g. "Given ").
|
|
926
1132
|
namespace is the qualifier *before* the dot (e.g. "BuiltIn" in "BuiltIn.Log").
|
|
1133
|
+
|
|
1134
|
+
The keyword part carries final render semantics: KEYWORD_INNER for
|
|
1135
|
+
Run Keyword inner calls, the BUILTIN modifier for BuiltIn keywords,
|
|
1136
|
+
embedded-argument splits (with the EMBEDDED modifier), and ARGUMENT
|
|
1137
|
+
for unresolved template names (`unresolved_as_argument`).
|
|
927
1138
|
"""
|
|
928
1139
|
line = rf_token.lineno
|
|
929
1140
|
col = rf_token.col_offset
|
|
@@ -956,12 +1167,13 @@ class SemanticAnalyzer(Visitor):
|
|
|
956
1167
|
line=line,
|
|
957
1168
|
col_offset=col,
|
|
958
1169
|
length=ns_len,
|
|
1170
|
+
modifiers=(frozenset({TokenModifier.BUILTIN}) if self._is_builtin_namespace(namespace) else None),
|
|
959
1171
|
)
|
|
960
1172
|
)
|
|
961
1173
|
col += ns_len
|
|
962
1174
|
out.append(
|
|
963
1175
|
SemanticToken(
|
|
964
|
-
kind=TokenKind.
|
|
1176
|
+
kind=TokenKind.OPERATOR,
|
|
965
1177
|
value=".",
|
|
966
1178
|
line=line,
|
|
967
1179
|
col_offset=col,
|
|
@@ -972,16 +1184,159 @@ class SemanticAnalyzer(Visitor):
|
|
|
972
1184
|
value = value[ns_len + 1 :]
|
|
973
1185
|
|
|
974
1186
|
if value:
|
|
975
|
-
|
|
1187
|
+
if kw_doc is None and unresolved_as_argument:
|
|
1188
|
+
keyword_kind = TokenKind.ARGUMENT
|
|
1189
|
+
elif inner:
|
|
1190
|
+
keyword_kind = TokenKind.KEYWORD_INNER
|
|
1191
|
+
else:
|
|
1192
|
+
keyword_kind = TokenKind.KEYWORD
|
|
1193
|
+
kw_mods = self._builtin_keyword_modifiers(kw_doc)
|
|
1194
|
+
|
|
1195
|
+
if kw_doc is not None and kw_doc.is_embedded and kw_doc.matcher.embedded_arguments:
|
|
1196
|
+
out.append(self._build_embedded_keyword_token(value, line, col, kw_doc, keyword_kind, kw_mods))
|
|
1197
|
+
else:
|
|
1198
|
+
out.append(
|
|
1199
|
+
SemanticToken(
|
|
1200
|
+
kind=keyword_kind,
|
|
1201
|
+
value=value,
|
|
1202
|
+
line=line,
|
|
1203
|
+
col_offset=col,
|
|
1204
|
+
length=len(value),
|
|
1205
|
+
modifiers=kw_mods,
|
|
1206
|
+
)
|
|
1207
|
+
)
|
|
1208
|
+
return out
|
|
1209
|
+
|
|
1210
|
+
def _build_embedded_keyword_token(
|
|
1211
|
+
self,
|
|
1212
|
+
value: str,
|
|
1213
|
+
line: int,
|
|
1214
|
+
col: int,
|
|
1215
|
+
kw_doc: KeywordDoc,
|
|
1216
|
+
keyword_kind: TokenKind,
|
|
1217
|
+
kw_mods: Optional[frozenset[TokenModifier]],
|
|
1218
|
+
) -> SemanticToken:
|
|
1219
|
+
"""Embedded-argument keyword name: one parent token whose sub-tokens are
|
|
1220
|
+
the keyword-text fragments plus the embedded argument fragments (text
|
|
1221
|
+
and variables, all carrying the EMBEDDED modifier).
|
|
1222
|
+
|
|
1223
|
+
If the written text does not match the keyword's own embedded pattern,
|
|
1224
|
+
the parent carries the EMBEDDED modifier itself and gets no sub-tokens —
|
|
1225
|
+
consumers can detect and treat that case explicitly.
|
|
1226
|
+
"""
|
|
1227
|
+
parent = SemanticToken(
|
|
1228
|
+
kind=keyword_kind,
|
|
1229
|
+
value=value,
|
|
1230
|
+
line=line,
|
|
1231
|
+
col_offset=col,
|
|
1232
|
+
length=len(value),
|
|
1233
|
+
modifiers=kw_mods,
|
|
1234
|
+
)
|
|
1235
|
+
|
|
1236
|
+
embedded = kw_doc.matcher.embedded_arguments
|
|
1237
|
+
if embedded is None:
|
|
1238
|
+
return parent
|
|
1239
|
+
if RF_VERSION >= (7, 3):
|
|
1240
|
+
m = embedded.name.fullmatch(value)
|
|
1241
|
+
elif RF_VERSION >= (6, 0):
|
|
1242
|
+
m = embedded.match(value)
|
|
1243
|
+
else:
|
|
1244
|
+
m = embedded.name.match(value)
|
|
1245
|
+
|
|
1246
|
+
if not m or m.lastindex is None:
|
|
1247
|
+
parent.modifiers = frozenset((kw_mods or frozenset()) | {TokenModifier.EMBEDDED})
|
|
1248
|
+
return parent
|
|
1249
|
+
|
|
1250
|
+
embedded_mods = frozenset({TokenModifier.EMBEDDED})
|
|
1251
|
+
sub_tokens: list[SemanticToken] = []
|
|
1252
|
+
start, end = m.span(0)
|
|
1253
|
+
for i in range(1, m.lastindex + 1):
|
|
1254
|
+
arg_start, arg_end = m.span(i)
|
|
1255
|
+
if arg_start - start > 0:
|
|
1256
|
+
sub_tokens.append(
|
|
1257
|
+
SemanticToken(
|
|
1258
|
+
kind=keyword_kind,
|
|
1259
|
+
value=value[start:arg_start],
|
|
1260
|
+
line=line,
|
|
1261
|
+
col_offset=col + start,
|
|
1262
|
+
length=arg_start - start,
|
|
1263
|
+
modifiers=kw_mods,
|
|
1264
|
+
)
|
|
1265
|
+
)
|
|
1266
|
+
|
|
1267
|
+
arg_value = value[arg_start:arg_end]
|
|
1268
|
+
arg_rf_token = Token(Token.ARGUMENT, arg_value, line, col + arg_start)
|
|
1269
|
+
try:
|
|
1270
|
+
occurrences = list(
|
|
1271
|
+
iter_variable_occurrences_from_token(
|
|
1272
|
+
arg_rf_token,
|
|
1273
|
+
identifiers="$@&%",
|
|
1274
|
+
is_defined=self._is_variable_defined,
|
|
1275
|
+
ignore_errors=True,
|
|
1276
|
+
)
|
|
1277
|
+
)
|
|
1278
|
+
except (VariableError, InvalidVariableError):
|
|
1279
|
+
occurrences = []
|
|
1280
|
+
cursor = col + arg_start
|
|
1281
|
+
arg_end_col = col + arg_end
|
|
1282
|
+
for occ in occurrences:
|
|
1283
|
+
if occ.col_offset < cursor:
|
|
1284
|
+
continue
|
|
1285
|
+
if occ.col_offset > cursor:
|
|
1286
|
+
text_value = arg_value[cursor - (col + arg_start) : occ.col_offset - (col + arg_start)]
|
|
1287
|
+
if text_value:
|
|
1288
|
+
sub_tokens.append(
|
|
1289
|
+
SemanticToken(
|
|
1290
|
+
kind=TokenKind.ARGUMENT,
|
|
1291
|
+
value=text_value,
|
|
1292
|
+
line=line,
|
|
1293
|
+
col_offset=cursor,
|
|
1294
|
+
length=len(text_value),
|
|
1295
|
+
modifiers=embedded_mods,
|
|
1296
|
+
)
|
|
1297
|
+
)
|
|
1298
|
+
sub_tokens.append(
|
|
1299
|
+
SemanticToken(
|
|
1300
|
+
kind=TokenKind.VARIABLE,
|
|
1301
|
+
value=occ.value,
|
|
1302
|
+
line=line,
|
|
1303
|
+
col_offset=occ.col_offset,
|
|
1304
|
+
length=occ.length,
|
|
1305
|
+
sub_tokens=occ.semantic_sub_tokens,
|
|
1306
|
+
modifiers=embedded_mods,
|
|
1307
|
+
)
|
|
1308
|
+
)
|
|
1309
|
+
cursor = occ.col_offset + occ.length
|
|
1310
|
+
if cursor < arg_end_col:
|
|
1311
|
+
text_value = arg_value[cursor - (col + arg_start) :]
|
|
1312
|
+
if text_value:
|
|
1313
|
+
sub_tokens.append(
|
|
1314
|
+
SemanticToken(
|
|
1315
|
+
kind=TokenKind.ARGUMENT,
|
|
1316
|
+
value=text_value,
|
|
1317
|
+
line=line,
|
|
1318
|
+
col_offset=cursor,
|
|
1319
|
+
length=len(text_value),
|
|
1320
|
+
modifiers=embedded_mods,
|
|
1321
|
+
)
|
|
1322
|
+
)
|
|
1323
|
+
|
|
1324
|
+
start = arg_end + 1
|
|
1325
|
+
|
|
1326
|
+
if start < end:
|
|
1327
|
+
sub_tokens.append(
|
|
976
1328
|
SemanticToken(
|
|
977
|
-
kind=
|
|
978
|
-
value=value,
|
|
1329
|
+
kind=keyword_kind,
|
|
1330
|
+
value=value[start:end],
|
|
979
1331
|
line=line,
|
|
980
|
-
col_offset=col,
|
|
981
|
-
length=
|
|
1332
|
+
col_offset=col + start,
|
|
1333
|
+
length=end - start,
|
|
1334
|
+
modifiers=kw_mods,
|
|
982
1335
|
)
|
|
983
1336
|
)
|
|
984
|
-
|
|
1337
|
+
|
|
1338
|
+
parent.sub_tokens = sub_tokens
|
|
1339
|
+
return parent
|
|
985
1340
|
|
|
986
1341
|
@staticmethod
|
|
987
1342
|
def _named_argument_split(value: str, keyword_doc: Optional[KeywordDoc]) -> Optional[Tuple[str, str]]:
|
|
@@ -993,17 +1348,15 @@ class SemanticAnalyzer(Visitor):
|
|
|
993
1348
|
"""
|
|
994
1349
|
if keyword_doc is None or not value:
|
|
995
1350
|
return None
|
|
996
|
-
|
|
997
|
-
if
|
|
1351
|
+
name, split_value = split_from_equals(value)
|
|
1352
|
+
if split_value is None or not name:
|
|
998
1353
|
return None
|
|
999
|
-
name = value[:eq_idx]
|
|
1000
1354
|
# Skip if the name part itself contains a variable — that's positional.
|
|
1001
1355
|
if "${" in name or "@{" in name or "&{" in name or "%{" in name:
|
|
1002
1356
|
return None
|
|
1003
|
-
|
|
1004
|
-
if name not in arg_names:
|
|
1357
|
+
if not any(arg.kind == KeywordArgumentKind.VAR_NAMED or arg.name == name for arg in keyword_doc.arguments):
|
|
1005
1358
|
return None
|
|
1006
|
-
return name,
|
|
1359
|
+
return name, split_value
|
|
1007
1360
|
|
|
1008
1361
|
def _build_argument_semantic_token(
|
|
1009
1362
|
self, rf_token: Token, keyword_doc: Optional[KeywordDoc] = None
|
|
@@ -1066,6 +1419,13 @@ class SemanticAnalyzer(Visitor):
|
|
|
1066
1419
|
col_offset=name_col,
|
|
1067
1420
|
length=len(name_part),
|
|
1068
1421
|
),
|
|
1422
|
+
SemanticToken(
|
|
1423
|
+
kind=TokenKind.OPERATOR,
|
|
1424
|
+
value="=",
|
|
1425
|
+
line=line,
|
|
1426
|
+
col_offset=name_col + len(name_part),
|
|
1427
|
+
length=1,
|
|
1428
|
+
),
|
|
1069
1429
|
value_token,
|
|
1070
1430
|
]
|
|
1071
1431
|
return arg_token
|
|
@@ -1078,7 +1438,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
1078
1438
|
for occ in iter_variable_occurrences_from_token(
|
|
1079
1439
|
rf_token,
|
|
1080
1440
|
identifiers="$@&%",
|
|
1081
|
-
|
|
1441
|
+
is_defined=self._is_variable_defined,
|
|
1082
1442
|
ignore_errors=True,
|
|
1083
1443
|
)
|
|
1084
1444
|
]
|
|
@@ -1141,10 +1501,16 @@ class SemanticAnalyzer(Visitor):
|
|
|
1141
1501
|
arg_token.sub_tokens = sub_tokens
|
|
1142
1502
|
return arg_token
|
|
1143
1503
|
|
|
1144
|
-
def _argument_sub_tokens(
|
|
1145
|
-
|
|
1146
|
-
|
|
1504
|
+
def _argument_sub_tokens(
|
|
1505
|
+
self,
|
|
1506
|
+
rf_token: Token,
|
|
1507
|
+
text_kind: TokenKind = TokenKind.TEXT_FRAGMENT,
|
|
1508
|
+
site: VariableSite = VariableSite.USAGE,
|
|
1509
|
+
) -> Optional[list[SemanticToken]]:
|
|
1510
|
+
"""Variable sub-tokens (with `text_kind` fragments for literal text) for
|
|
1511
|
+
an ARGUMENT-like RF token. Returns None if the value contains no
|
|
1147
1512
|
variables (caller should leave sub_tokens empty in that case).
|
|
1513
|
+
`site` tells where the variables stand (see `VariableSite`).
|
|
1148
1514
|
"""
|
|
1149
1515
|
line = rf_token.lineno
|
|
1150
1516
|
col_start = rf_token.col_offset
|
|
@@ -1156,7 +1522,8 @@ class SemanticAnalyzer(Visitor):
|
|
|
1156
1522
|
iter_variable_occurrences_from_token(
|
|
1157
1523
|
rf_token,
|
|
1158
1524
|
identifiers="$@&%",
|
|
1159
|
-
|
|
1525
|
+
site=site,
|
|
1526
|
+
is_defined=self._is_variable_defined,
|
|
1160
1527
|
ignore_errors=True,
|
|
1161
1528
|
)
|
|
1162
1529
|
)
|
|
@@ -1177,7 +1544,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
1177
1544
|
if text_value:
|
|
1178
1545
|
sub_tokens.append(
|
|
1179
1546
|
SemanticToken(
|
|
1180
|
-
kind=
|
|
1547
|
+
kind=text_kind,
|
|
1181
1548
|
value=text_value,
|
|
1182
1549
|
line=line,
|
|
1183
1550
|
col_offset=cursor,
|
|
@@ -1202,7 +1569,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
1202
1569
|
if text_value:
|
|
1203
1570
|
sub_tokens.append(
|
|
1204
1571
|
SemanticToken(
|
|
1205
|
-
kind=
|
|
1572
|
+
kind=text_kind,
|
|
1206
1573
|
value=text_value,
|
|
1207
1574
|
line=line,
|
|
1208
1575
|
col_offset=cursor,
|
|
@@ -1211,7 +1578,13 @@ class SemanticAnalyzer(Visitor):
|
|
|
1211
1578
|
)
|
|
1212
1579
|
return sub_tokens
|
|
1213
1580
|
|
|
1214
|
-
def _build_token_with_var_subtokens(
|
|
1581
|
+
def _build_token_with_var_subtokens(
|
|
1582
|
+
self,
|
|
1583
|
+
rf_token: Token,
|
|
1584
|
+
kind: TokenKind,
|
|
1585
|
+
text_kind: TokenKind = TokenKind.TEXT_FRAGMENT,
|
|
1586
|
+
site: VariableSite = VariableSite.USAGE,
|
|
1587
|
+
) -> SemanticToken:
|
|
1215
1588
|
"""Build a SemanticToken (any kind) with variable sub-tokens
|
|
1216
1589
|
attached when the RF token contains variables. Used for CONDITION,
|
|
1217
1590
|
VARIABLE_NAME-in-defining-context, TAG, and similar cases that
|
|
@@ -1224,11 +1597,29 @@ class SemanticAnalyzer(Visitor):
|
|
|
1224
1597
|
col_offset=rf_token.col_offset,
|
|
1225
1598
|
length=len(rf_token.value),
|
|
1226
1599
|
)
|
|
1227
|
-
sub = self._argument_sub_tokens(rf_token)
|
|
1600
|
+
sub = self._argument_sub_tokens(rf_token, text_kind=text_kind, site=site)
|
|
1228
1601
|
if sub:
|
|
1229
1602
|
token.sub_tokens = sub
|
|
1230
1603
|
return token
|
|
1231
1604
|
|
|
1605
|
+
def _build_condition_token(self, rf_token: Token) -> SemanticToken:
|
|
1606
|
+
"""CONDITION token with variable sub-tokens plus PYTHON_VARIABLE_REF
|
|
1607
|
+
sub-tokens for bare ``$var`` expression references (same tokenize scan
|
|
1608
|
+
as `_iter_expression_variables_from_token`, so the positions match the
|
|
1609
|
+
analysis results). The refs are model-only data for expression-aware
|
|
1610
|
+
consumers (inline values, debug extraction); the semantic-token
|
|
1611
|
+
renderer never emits them. ``${var}`` occurrences are unaffected: the
|
|
1612
|
+
scan only matches ``$`` directly followed by a Python name.
|
|
1613
|
+
"""
|
|
1614
|
+
token = self._build_token_with_var_subtokens(rf_token, TokenKind.CONDITION)
|
|
1615
|
+
if rf_token.value and rf_token.col_offset is not None:
|
|
1616
|
+
refs = _build_python_expression_sub_tokens(rf_token.value, rf_token.lineno, rf_token.col_offset)
|
|
1617
|
+
if refs:
|
|
1618
|
+
merged = list(token.sub_tokens or []) + refs
|
|
1619
|
+
merged.sort(key=lambda t: t.col_offset)
|
|
1620
|
+
token.sub_tokens = merged
|
|
1621
|
+
return token
|
|
1622
|
+
|
|
1232
1623
|
def _build_setting_tokens(
|
|
1233
1624
|
self,
|
|
1234
1625
|
node: Statement,
|
|
@@ -1253,8 +1644,6 @@ class SemanticAnalyzer(Visitor):
|
|
|
1253
1644
|
"""
|
|
1254
1645
|
tokens: list[SemanticToken] = []
|
|
1255
1646
|
for rf_token in node.tokens:
|
|
1256
|
-
if rf_token.type in self._RF_SKIP_TOKENS:
|
|
1257
|
-
continue
|
|
1258
1647
|
if rf_token.type == Token.ARGUMENT and rf_token.value and rf_token.col_offset is not None:
|
|
1259
1648
|
if argument_kind is TokenKind.ARGUMENT:
|
|
1260
1649
|
tokens.append(self._build_argument_semantic_token(rf_token, keyword_doc=None))
|
|
@@ -1262,24 +1651,16 @@ class SemanticAnalyzer(Visitor):
|
|
|
1262
1651
|
tokens.append(self._build_token_with_var_subtokens(rf_token, argument_kind))
|
|
1263
1652
|
continue
|
|
1264
1653
|
if rf_token.type == Token.VARIABLE and rf_token.value and rf_token.col_offset is not None:
|
|
1265
|
-
|
|
1654
|
+
site = VariableSite.DECLARATION if variable_kind is TokenKind.VARIABLE_NAME else VariableSite.USAGE
|
|
1655
|
+
tokens.append(self._build_token_with_var_subtokens(rf_token, variable_kind, site=site))
|
|
1266
1656
|
continue
|
|
1267
1657
|
if split_options and rf_token.type == Token.OPTION and rf_token.value and rf_token.col_offset is not None:
|
|
1268
1658
|
tokens.extend(self._split_option_token(rf_token))
|
|
1269
1659
|
continue
|
|
1270
|
-
kind = self._RF_TOKEN_TO_TOKEN_KIND.get(rf_token.type)
|
|
1271
|
-
if kind is None:
|
|
1272
|
-
continue
|
|
1273
1660
|
if rf_token.value and rf_token.col_offset is not None:
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
value=rf_token.value,
|
|
1278
|
-
line=rf_token.lineno,
|
|
1279
|
-
col_offset=rf_token.col_offset,
|
|
1280
|
-
length=len(rf_token.value),
|
|
1281
|
-
)
|
|
1282
|
-
)
|
|
1661
|
+
sem_token = self._map_generic_token(rf_token)
|
|
1662
|
+
if sem_token is not None:
|
|
1663
|
+
tokens.append(sem_token)
|
|
1283
1664
|
return tokens
|
|
1284
1665
|
|
|
1285
1666
|
@staticmethod
|
|
@@ -1294,10 +1675,11 @@ class SemanticAnalyzer(Visitor):
|
|
|
1294
1675
|
return bool(name) and name in known_names
|
|
1295
1676
|
|
|
1296
1677
|
def _split_option_token(self, rf_token: Token) -> list[SemanticToken]:
|
|
1297
|
-
"""Split
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
value doesn't actually
|
|
1678
|
+
"""Split an option token (`name=value`) of `VAR`, `FOR`, `WHILE` or
|
|
1679
|
+
`EXCEPT` into an OPTION token with OPTION_NAME + OPERATOR +
|
|
1680
|
+
OPTION_VALUE sub-tokens, with variable decomposition on the value half.
|
|
1681
|
+
Falls back to a single ARGUMENT token if the value doesn't actually
|
|
1682
|
+
contain `=`.
|
|
1301
1683
|
"""
|
|
1302
1684
|
value = rf_token.value or ""
|
|
1303
1685
|
line = rf_token.lineno
|
|
@@ -1322,16 +1704,23 @@ class SemanticAnalyzer(Visitor):
|
|
|
1322
1704
|
# `_argument_sub_tokens`.
|
|
1323
1705
|
value_rf_token = Token(rf_token.type, value_part, line, value_col, rf_token.error)
|
|
1324
1706
|
value_sub = self._argument_sub_tokens(value_rf_token) if value_part else None
|
|
1325
|
-
|
|
1707
|
+
sub_tokens = [
|
|
1326
1708
|
SemanticToken(
|
|
1327
|
-
kind=TokenKind.
|
|
1709
|
+
kind=TokenKind.OPTION_NAME,
|
|
1328
1710
|
value=name_part,
|
|
1329
1711
|
line=line,
|
|
1330
1712
|
col_offset=col,
|
|
1331
1713
|
length=len(name_part),
|
|
1332
1714
|
),
|
|
1333
1715
|
SemanticToken(
|
|
1334
|
-
kind=TokenKind.
|
|
1716
|
+
kind=TokenKind.OPERATOR,
|
|
1717
|
+
value="=",
|
|
1718
|
+
line=line,
|
|
1719
|
+
col_offset=col + eq_idx,
|
|
1720
|
+
length=1,
|
|
1721
|
+
),
|
|
1722
|
+
SemanticToken(
|
|
1723
|
+
kind=TokenKind.OPTION_VALUE,
|
|
1335
1724
|
value=value_part,
|
|
1336
1725
|
line=line,
|
|
1337
1726
|
col_offset=value_col,
|
|
@@ -1339,12 +1728,23 @@ class SemanticAnalyzer(Visitor):
|
|
|
1339
1728
|
sub_tokens=value_sub,
|
|
1340
1729
|
),
|
|
1341
1730
|
]
|
|
1731
|
+
return [
|
|
1732
|
+
SemanticToken(
|
|
1733
|
+
kind=TokenKind.OPTION,
|
|
1734
|
+
value=value,
|
|
1735
|
+
line=line,
|
|
1736
|
+
col_offset=col,
|
|
1737
|
+
length=len(value),
|
|
1738
|
+
sub_tokens=sub_tokens,
|
|
1739
|
+
)
|
|
1740
|
+
]
|
|
1342
1741
|
|
|
1343
1742
|
def _build_keyword_call_tokens(
|
|
1344
1743
|
self,
|
|
1345
1744
|
node: Statement,
|
|
1346
1745
|
keyword_token_type: str = Token.KEYWORD,
|
|
1347
1746
|
keyword_doc: Optional[KeywordDoc] = None,
|
|
1747
|
+
unresolved_as_argument: bool = False,
|
|
1348
1748
|
) -> list[SemanticToken]:
|
|
1349
1749
|
"""Build SemanticTokens for a keyword-executing statement.
|
|
1350
1750
|
|
|
@@ -1366,27 +1766,38 @@ class SemanticAnalyzer(Visitor):
|
|
|
1366
1766
|
|
|
1367
1767
|
tokens: list[SemanticToken] = []
|
|
1368
1768
|
for rf_token in node.tokens:
|
|
1369
|
-
if rf_token.type in self._RF_SKIP_TOKENS:
|
|
1370
|
-
continue
|
|
1371
1769
|
if rf_token.type == keyword_token_type and rf_token.value:
|
|
1372
|
-
tokens.extend(
|
|
1770
|
+
tokens.extend(
|
|
1771
|
+
self._split_keyword_name_token(
|
|
1772
|
+
rf_token,
|
|
1773
|
+
bdd_prefix,
|
|
1774
|
+
namespace,
|
|
1775
|
+
kw_doc=keyword_doc,
|
|
1776
|
+
unresolved_as_argument=unresolved_as_argument,
|
|
1777
|
+
)
|
|
1778
|
+
)
|
|
1373
1779
|
continue
|
|
1374
1780
|
if rf_token.type == Token.ARGUMENT and rf_token.value and rf_token.col_offset is not None:
|
|
1781
|
+
# ELSE / ELSE IF / AND separator cells of Run Keyword variants
|
|
1782
|
+
# belong to the outer run-keyword syntax — recorded during
|
|
1783
|
+
# run-keyword analysis, rendered as control flow.
|
|
1784
|
+
if (rf_token.lineno, rf_token.col_offset) in self._rk_separator_positions:
|
|
1785
|
+
tokens.append(
|
|
1786
|
+
SemanticToken(
|
|
1787
|
+
kind=TokenKind.CONTROL_FLOW,
|
|
1788
|
+
value=rf_token.value,
|
|
1789
|
+
line=rf_token.lineno,
|
|
1790
|
+
col_offset=rf_token.col_offset,
|
|
1791
|
+
length=len(rf_token.value),
|
|
1792
|
+
)
|
|
1793
|
+
)
|
|
1794
|
+
continue
|
|
1375
1795
|
tokens.append(self._build_argument_semantic_token(rf_token, keyword_doc=keyword_doc))
|
|
1376
1796
|
continue
|
|
1377
|
-
token_kind = self._RF_TOKEN_TO_TOKEN_KIND.get(rf_token.type)
|
|
1378
|
-
if token_kind is None:
|
|
1379
|
-
continue
|
|
1380
1797
|
if rf_token.value and rf_token.col_offset is not None:
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
value=rf_token.value,
|
|
1385
|
-
line=rf_token.lineno,
|
|
1386
|
-
col_offset=rf_token.col_offset,
|
|
1387
|
-
length=len(rf_token.value),
|
|
1388
|
-
)
|
|
1389
|
-
)
|
|
1798
|
+
sem_token = self._map_generic_token(rf_token)
|
|
1799
|
+
if sem_token is not None:
|
|
1800
|
+
tokens.append(sem_token)
|
|
1390
1801
|
return tokens
|
|
1391
1802
|
|
|
1392
1803
|
def _node_kind_for_statement(self, node: Statement) -> NodeKind:
|
|
@@ -1651,6 +2062,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
1651
2062
|
ignore_errors_if_contains_variables: bool = False,
|
|
1652
2063
|
unescape_keyword: bool = True,
|
|
1653
2064
|
is_template: bool = False,
|
|
2065
|
+
check_arguments: bool = True,
|
|
1654
2066
|
) -> Optional[KeywordDoc]:
|
|
1655
2067
|
# Reset token-decomposition outputs for this call. Visitors read them
|
|
1656
2068
|
# after we return to build BDD_PREFIX / NAMESPACE / SEPARATOR / KEYWORD
|
|
@@ -1808,17 +2220,16 @@ class SemanticAnalyzer(Visitor):
|
|
|
1808
2220
|
code=Error.RESERVED_KEYWORD,
|
|
1809
2221
|
)
|
|
1810
2222
|
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
)
|
|
2223
|
+
private_message = private_keyword_call_message(result, self._source)
|
|
2224
|
+
if private_message is not None:
|
|
2225
|
+
self._append_diagnostics(
|
|
2226
|
+
range=kw_range,
|
|
2227
|
+
message=private_message,
|
|
2228
|
+
severity=DiagnosticSeverity.WARNING,
|
|
2229
|
+
code=Error.PRIVATE_KEYWORD,
|
|
2230
|
+
)
|
|
1820
2231
|
|
|
1821
|
-
if not isinstance(node, (Template, TestTemplate)):
|
|
2232
|
+
if check_arguments and not isinstance(node, (Template, TestTemplate)):
|
|
1822
2233
|
try:
|
|
1823
2234
|
if result.arguments_spec is not None:
|
|
1824
2235
|
result.arguments_spec.resolve(
|
|
@@ -1913,10 +2324,25 @@ class SemanticAnalyzer(Visitor):
|
|
|
1913
2324
|
# _analyze_keyword_call call set for *this* inner keyword.
|
|
1914
2325
|
tokens: list[SemanticToken] = []
|
|
1915
2326
|
if kw_token.value and kw_token.col_offset is not None:
|
|
1916
|
-
tokens.extend(
|
|
2327
|
+
tokens.extend(
|
|
2328
|
+
self._split_keyword_name_token(
|
|
2329
|
+
kw_token, self._last_bdd_prefix, self._last_kw_namespace, kw_doc=kw_doc, inner=True
|
|
2330
|
+
)
|
|
2331
|
+
)
|
|
1917
2332
|
if argument_tokens:
|
|
1918
2333
|
for arg_t in argument_tokens:
|
|
1919
2334
|
if arg_t.value and arg_t.col_offset is not None:
|
|
2335
|
+
if (arg_t.lineno, arg_t.col_offset) in self._rk_separator_positions:
|
|
2336
|
+
tokens.append(
|
|
2337
|
+
SemanticToken(
|
|
2338
|
+
kind=TokenKind.CONTROL_FLOW,
|
|
2339
|
+
value=arg_t.value,
|
|
2340
|
+
line=arg_t.lineno,
|
|
2341
|
+
col_offset=arg_t.col_offset,
|
|
2342
|
+
length=len(arg_t.value),
|
|
2343
|
+
)
|
|
2344
|
+
)
|
|
2345
|
+
continue
|
|
1920
2346
|
tokens.append(self._build_argument_semantic_token(arg_t, keyword_doc=kw_doc))
|
|
1921
2347
|
|
|
1922
2348
|
if nested_inner_calls:
|
|
@@ -1966,7 +2392,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
1966
2392
|
tokens = list(argument_tokens)
|
|
1967
2393
|
token_idx = 0
|
|
1968
2394
|
|
|
1969
|
-
for arg_info in kw_args:
|
|
2395
|
+
for arg_idx, arg_info in enumerate(kw_args):
|
|
1970
2396
|
if token_idx >= len(tokens):
|
|
1971
2397
|
break
|
|
1972
2398
|
|
|
@@ -1976,15 +2402,21 @@ class SemanticAnalyzer(Visitor):
|
|
|
1976
2402
|
kw_name_token = tokens[token_idx]
|
|
1977
2403
|
token_idx += 1
|
|
1978
2404
|
|
|
2405
|
+
# Without a following is_keyword_argument parameter the keyword is only
|
|
2406
|
+
# named, not called (e.g. `Keyword Should Exist`): the remaining tokens
|
|
2407
|
+
# belong to the outer keyword and the inner arguments are not checked.
|
|
2408
|
+
is_called = any(a.is_keyword_argument for a in kw_args[arg_idx + 1 :])
|
|
2409
|
+
|
|
1979
2410
|
# Collect inner keyword args: all remaining tokens that map to
|
|
1980
2411
|
# is_keyword_argument parameters (VAR_POSITIONAL covers all remaining)
|
|
1981
|
-
inner_arg_tokens = tokens[token_idx:]
|
|
2412
|
+
inner_arg_tokens = tokens[token_idx:] if is_called else []
|
|
1982
2413
|
kw_doc = self._analyze_keyword_call(
|
|
1983
2414
|
node,
|
|
1984
2415
|
kw_name_token,
|
|
1985
2416
|
inner_arg_tokens,
|
|
1986
2417
|
allow_variables=True,
|
|
1987
2418
|
ignore_errors_if_contains_variables=True,
|
|
2419
|
+
check_arguments=is_called,
|
|
1988
2420
|
)
|
|
1989
2421
|
nested = self._last_inner_calls
|
|
1990
2422
|
self._last_inner_calls = [
|
|
@@ -2047,6 +2479,8 @@ class SemanticAnalyzer(Visitor):
|
|
|
2047
2479
|
t = argument_tokens[0]
|
|
2048
2480
|
argument_tokens = argument_tokens[1:]
|
|
2049
2481
|
if t.value == "AND":
|
|
2482
|
+
if t.col_offset is not None:
|
|
2483
|
+
self._rk_separator_positions.add((t.lineno, t.col_offset))
|
|
2050
2484
|
self._append_diagnostics(
|
|
2051
2485
|
range=range_from_token(t),
|
|
2052
2486
|
message=f"Incorrect use of {t.value}.",
|
|
@@ -2058,6 +2492,8 @@ class SemanticAnalyzer(Visitor):
|
|
|
2058
2492
|
and_token = next((e for e in argument_tokens if e.value == "AND"), None)
|
|
2059
2493
|
args = []
|
|
2060
2494
|
if and_token is not None:
|
|
2495
|
+
if and_token.col_offset is not None:
|
|
2496
|
+
self._rk_separator_positions.add((and_token.lineno, and_token.col_offset))
|
|
2061
2497
|
args = argument_tokens[: argument_tokens.index(and_token)]
|
|
2062
2498
|
argument_tokens = argument_tokens[argument_tokens.index(and_token) + 1 :]
|
|
2063
2499
|
has_and = True
|
|
@@ -2108,6 +2544,9 @@ class SemanticAnalyzer(Visitor):
|
|
|
2108
2544
|
|
|
2109
2545
|
while argument_tokens:
|
|
2110
2546
|
if argument_tokens[0].value == "ELSE" and len(argument_tokens) > 1:
|
|
2547
|
+
else_token = argument_tokens[0]
|
|
2548
|
+
if else_token.col_offset is not None:
|
|
2549
|
+
self._rk_separator_positions.add((else_token.lineno, else_token.col_offset))
|
|
2111
2550
|
kwt = argument_tokens[1]
|
|
2112
2551
|
argument_tokens = argument_tokens[2:]
|
|
2113
2552
|
args = skip_args()
|
|
@@ -2122,6 +2561,9 @@ class SemanticAnalyzer(Visitor):
|
|
|
2122
2561
|
break
|
|
2123
2562
|
|
|
2124
2563
|
if argument_tokens[0].value == "ELSE IF" and len(argument_tokens) > 2:
|
|
2564
|
+
else_if_token = argument_tokens[0]
|
|
2565
|
+
if else_if_token.col_offset is not None:
|
|
2566
|
+
self._rk_separator_positions.add((else_if_token.lineno, else_if_token.col_offset))
|
|
2125
2567
|
kwt = argument_tokens[2]
|
|
2126
2568
|
argument_tokens = argument_tokens[3:]
|
|
2127
2569
|
args = skip_args()
|
|
@@ -2150,6 +2592,12 @@ class SemanticAnalyzer(Visitor):
|
|
|
2150
2592
|
if keyword_doc is None:
|
|
2151
2593
|
return argument_tokens
|
|
2152
2594
|
|
|
2595
|
+
# BuiltIn's run-keyword variants are authoritative in the hardcoded
|
|
2596
|
+
# tables (condition counts, AND/ELSE splitting) — route them there
|
|
2597
|
+
# first regardless of register/type-hint data.
|
|
2598
|
+
if keyword_doc.is_any_run_keyword():
|
|
2599
|
+
return self._analyze_hardcoded_run_keyword(keyword_doc, node, argument_tokens)
|
|
2600
|
+
|
|
2153
2601
|
strategy = get_keyword_argument_strategy(keyword_doc)
|
|
2154
2602
|
if strategy is None:
|
|
2155
2603
|
return argument_tokens
|
|
@@ -2182,7 +2630,15 @@ class SemanticAnalyzer(Visitor):
|
|
|
2182
2630
|
|
|
2183
2631
|
def visit_Fixture(self, node: Fixture) -> None: # noqa: N802
|
|
2184
2632
|
keyword_token = node.get_token(Token.NAME)
|
|
2185
|
-
|
|
2633
|
+
# `NONE` / empty fixtures are not keyword calls, but the setting name
|
|
2634
|
+
# (and a literal `NONE`) still need SemanticTokens for highlighting.
|
|
2635
|
+
is_active = (
|
|
2636
|
+
keyword_token is not None and keyword_token.value and keyword_token.value.upper() not in ("", "NONE")
|
|
2637
|
+
)
|
|
2638
|
+
|
|
2639
|
+
kw_doc = None
|
|
2640
|
+
inner_calls: List[KeywordCallStatement] = []
|
|
2641
|
+
if is_active and keyword_token is not None:
|
|
2186
2642
|
self._analyze_token_variables(keyword_token)
|
|
2187
2643
|
self._visit_block_settings_statement(node)
|
|
2188
2644
|
|
|
@@ -2195,34 +2651,43 @@ class SemanticAnalyzer(Visitor):
|
|
|
2195
2651
|
)
|
|
2196
2652
|
inner_calls = self._last_inner_calls
|
|
2197
2653
|
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2654
|
+
tokens = self._build_keyword_call_tokens(node, keyword_token_type=Token.NAME, keyword_doc=kw_doc)
|
|
2655
|
+
if not tokens:
|
|
2656
|
+
return
|
|
2657
|
+
if inner_calls:
|
|
2658
|
+
stmt: KeywordCallStatement = RunKeywordCallStatement(
|
|
2659
|
+
kind=NodeKind.SETUP,
|
|
2660
|
+
line_start=node.lineno,
|
|
2661
|
+
line_end=node.end_lineno or node.lineno,
|
|
2662
|
+
keyword_doc=kw_doc,
|
|
2663
|
+
lib_entry=self._last_lib_entry,
|
|
2664
|
+
tokens=tokens,
|
|
2665
|
+
inner_calls=inner_calls,
|
|
2666
|
+
)
|
|
2667
|
+
else:
|
|
2668
|
+
stmt = KeywordCallStatement(
|
|
2669
|
+
kind=NodeKind.SETUP,
|
|
2670
|
+
line_start=node.lineno,
|
|
2671
|
+
line_end=node.end_lineno or node.lineno,
|
|
2672
|
+
keyword_doc=kw_doc,
|
|
2673
|
+
lib_entry=self._last_lib_entry,
|
|
2674
|
+
tokens=tokens,
|
|
2675
|
+
)
|
|
2676
|
+
self._add_statement(stmt)
|
|
2219
2677
|
|
|
2220
2678
|
def visit_Teardown(self, node: Fixture) -> None: # noqa: N802
|
|
2221
2679
|
keyword_token = node.get_token(Token.NAME)
|
|
2222
|
-
|
|
2680
|
+
is_active = (
|
|
2681
|
+
keyword_token is not None and keyword_token.value and keyword_token.value.upper() not in ("", "NONE")
|
|
2682
|
+
)
|
|
2683
|
+
|
|
2684
|
+
kw_doc = None
|
|
2685
|
+
inner_calls: List[KeywordCallStatement] = []
|
|
2686
|
+
if is_active and keyword_token is not None:
|
|
2687
|
+
active_token = keyword_token
|
|
2223
2688
|
|
|
2224
2689
|
def _handler() -> None:
|
|
2225
|
-
self._analyze_token_variables(
|
|
2690
|
+
self._analyze_token_variables(active_token)
|
|
2226
2691
|
self._analyze_statement_variables(node)
|
|
2227
2692
|
|
|
2228
2693
|
if self._end_block_handlers is not None:
|
|
@@ -2237,27 +2702,29 @@ class SemanticAnalyzer(Visitor):
|
|
|
2237
2702
|
)
|
|
2238
2703
|
inner_calls = self._last_inner_calls
|
|
2239
2704
|
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2705
|
+
tokens = self._build_keyword_call_tokens(node, keyword_token_type=Token.NAME, keyword_doc=kw_doc)
|
|
2706
|
+
if not tokens:
|
|
2707
|
+
return
|
|
2708
|
+
if inner_calls:
|
|
2709
|
+
stmt: KeywordCallStatement = RunKeywordCallStatement(
|
|
2710
|
+
kind=NodeKind.TEARDOWN,
|
|
2711
|
+
line_start=node.lineno,
|
|
2712
|
+
line_end=node.end_lineno or node.lineno,
|
|
2713
|
+
keyword_doc=kw_doc,
|
|
2714
|
+
lib_entry=self._last_lib_entry,
|
|
2715
|
+
tokens=tokens,
|
|
2716
|
+
inner_calls=inner_calls,
|
|
2717
|
+
)
|
|
2718
|
+
else:
|
|
2719
|
+
stmt = KeywordCallStatement(
|
|
2720
|
+
kind=NodeKind.TEARDOWN,
|
|
2721
|
+
line_start=node.lineno,
|
|
2722
|
+
line_end=node.end_lineno or node.lineno,
|
|
2723
|
+
keyword_doc=kw_doc,
|
|
2724
|
+
lib_entry=self._last_lib_entry,
|
|
2725
|
+
tokens=tokens,
|
|
2726
|
+
)
|
|
2727
|
+
self._add_statement(stmt)
|
|
2261
2728
|
|
|
2262
2729
|
# --- Template ---
|
|
2263
2730
|
|
|
@@ -2283,7 +2750,9 @@ class SemanticAnalyzer(Visitor):
|
|
|
2283
2750
|
line_end=node.end_lineno or node.lineno,
|
|
2284
2751
|
keyword_doc=kw_doc,
|
|
2285
2752
|
lib_entry=self._last_lib_entry,
|
|
2286
|
-
tokens=self._build_keyword_call_tokens(
|
|
2753
|
+
tokens=self._build_keyword_call_tokens(
|
|
2754
|
+
node, keyword_token_type=Token.NAME, keyword_doc=kw_doc, unresolved_as_argument=True
|
|
2755
|
+
),
|
|
2287
2756
|
)
|
|
2288
2757
|
self._add_statement(stmt)
|
|
2289
2758
|
|
|
@@ -2308,7 +2777,9 @@ class SemanticAnalyzer(Visitor):
|
|
|
2308
2777
|
line_end=node.end_lineno or node.lineno,
|
|
2309
2778
|
keyword_doc=kw_doc,
|
|
2310
2779
|
lib_entry=self._last_lib_entry,
|
|
2311
|
-
tokens=self._build_keyword_call_tokens(
|
|
2780
|
+
tokens=self._build_keyword_call_tokens(
|
|
2781
|
+
node, keyword_token_type=Token.NAME, keyword_doc=kw_doc, unresolved_as_argument=True
|
|
2782
|
+
),
|
|
2312
2783
|
)
|
|
2313
2784
|
self._add_statement(stmt)
|
|
2314
2785
|
|
|
@@ -2397,6 +2868,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
2397
2868
|
)
|
|
2398
2869
|
|
|
2399
2870
|
self._current_testcase_or_keyword_name = node.name
|
|
2871
|
+
self._in_testcase = True
|
|
2400
2872
|
old_variables = self._variables
|
|
2401
2873
|
self._variables = self._variables.copy()
|
|
2402
2874
|
self._end_block_handlers = []
|
|
@@ -2449,6 +2921,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
2449
2921
|
self._end_block_handlers = None
|
|
2450
2922
|
self._variables = old_variables
|
|
2451
2923
|
self._current_testcase_or_keyword_name = None
|
|
2924
|
+
self._in_testcase = False
|
|
2452
2925
|
self._template = None
|
|
2453
2926
|
self._current_definition = old_definition
|
|
2454
2927
|
self._current_definition_block = old_definition_block
|
|
@@ -2501,6 +2974,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
2501
2974
|
)
|
|
2502
2975
|
|
|
2503
2976
|
self._current_testcase_or_keyword_name = node.name
|
|
2977
|
+
self._in_keyword = True
|
|
2504
2978
|
old_variables = self._variables
|
|
2505
2979
|
self._variables = self._variables.copy()
|
|
2506
2980
|
self._end_block_handlers = []
|
|
@@ -2557,6 +3031,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
2557
3031
|
self._variables = old_variables
|
|
2558
3032
|
self._current_testcase_or_keyword_name = None
|
|
2559
3033
|
self._current_keyword_doc = None
|
|
3034
|
+
self._in_keyword = False
|
|
2560
3035
|
self._current_definition = old_definition
|
|
2561
3036
|
self._current_definition_block = old_definition_block
|
|
2562
3037
|
|
|
@@ -2834,8 +3309,10 @@ class SemanticAnalyzer(Visitor):
|
|
|
2834
3309
|
return self._build_header_tokens(
|
|
2835
3310
|
node,
|
|
2836
3311
|
special={
|
|
2837
|
-
Token.ASSIGN: lambda t: [
|
|
2838
|
-
|
|
3312
|
+
Token.ASSIGN: lambda t: [
|
|
3313
|
+
self._build_token_with_var_subtokens(t, TokenKind.VARIABLE_NAME, site=VariableSite.DECLARATION)
|
|
3314
|
+
],
|
|
3315
|
+
Token.ARGUMENT: lambda t: [self._build_condition_token(t)],
|
|
2839
3316
|
},
|
|
2840
3317
|
)
|
|
2841
3318
|
|
|
@@ -2917,7 +3394,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
2917
3394
|
for tok in stmt.tokens:
|
|
2918
3395
|
if tok.kind is TokenKind.VARIABLE_NAME:
|
|
2919
3396
|
parent.loop_variables.append(tok)
|
|
2920
|
-
elif tok.kind is TokenKind.
|
|
3397
|
+
elif tok.kind is TokenKind.FOR_SEPARATOR and tok.value in self._FOR_FLAVOR_LOOKUP:
|
|
2921
3398
|
parent.flavor = self._FOR_FLAVOR_LOOKUP[tok.value]
|
|
2922
3399
|
# Options are stored as NAMED_ARGUMENT_NAME / NAMED_ARGUMENT_VALUE pairs.
|
|
2923
3400
|
named_pairs = self._extract_named_pairs(stmt.tokens)
|
|
@@ -2930,18 +3407,27 @@ class SemanticAnalyzer(Visitor):
|
|
|
2930
3407
|
|
|
2931
3408
|
@staticmethod
|
|
2932
3409
|
def _extract_named_pairs(tokens: list[SemanticToken]) -> Dict[str, str]:
|
|
2933
|
-
"""Return a {name: value} dict for
|
|
2934
|
-
|
|
3410
|
+
"""Return a {name: value} dict for option tokens: OPTION parents (with
|
|
3411
|
+
OPTION_NAME / OPTION_VALUE sub-tokens) and direct OPTION_NAME /
|
|
3412
|
+
OPTION_VALUE sequences.
|
|
2935
3413
|
"""
|
|
3414
|
+
|
|
3415
|
+
def iter_flat(toks: list[SemanticToken]) -> Iterator[SemanticToken]:
|
|
3416
|
+
for t in toks:
|
|
3417
|
+
if t.kind is TokenKind.OPTION and t.sub_tokens:
|
|
3418
|
+
yield from t.sub_tokens
|
|
3419
|
+
else:
|
|
3420
|
+
yield t
|
|
3421
|
+
|
|
2936
3422
|
result: Dict[str, str] = {}
|
|
2937
3423
|
pending_name: Optional[str] = None
|
|
2938
|
-
for t in tokens:
|
|
2939
|
-
if t.kind is TokenKind.
|
|
3424
|
+
for t in iter_flat(tokens):
|
|
3425
|
+
if t.kind is TokenKind.OPTION_NAME:
|
|
2940
3426
|
pending_name = t.value
|
|
2941
|
-
elif t.kind is TokenKind.
|
|
3427
|
+
elif t.kind is TokenKind.OPTION_VALUE and pending_name is not None:
|
|
2942
3428
|
result[pending_name] = t.value
|
|
2943
3429
|
pending_name = None
|
|
2944
|
-
|
|
3430
|
+
elif t.kind is not TokenKind.OPERATOR:
|
|
2945
3431
|
pending_name = None
|
|
2946
3432
|
return result
|
|
2947
3433
|
|
|
@@ -2962,7 +3448,9 @@ class SemanticAnalyzer(Visitor):
|
|
|
2962
3448
|
return self._build_header_tokens(
|
|
2963
3449
|
node,
|
|
2964
3450
|
special={
|
|
2965
|
-
Token.VARIABLE: lambda t: [
|
|
3451
|
+
Token.VARIABLE: lambda t: [
|
|
3452
|
+
self._build_token_with_var_subtokens(t, TokenKind.VARIABLE_NAME, site=VariableSite.DECLARATION)
|
|
3453
|
+
],
|
|
2966
3454
|
Token.ARGUMENT: handle_argument,
|
|
2967
3455
|
Token.OPTION: lambda t: self._split_option_token(t),
|
|
2968
3456
|
},
|
|
@@ -3039,7 +3527,11 @@ class SemanticAnalyzer(Visitor):
|
|
|
3039
3527
|
special={
|
|
3040
3528
|
Token.ARGUMENT: handle_argument,
|
|
3041
3529
|
Token.OPTION: lambda t: self._split_option_token(t),
|
|
3042
|
-
Token.VARIABLE: lambda t: [
|
|
3530
|
+
Token.VARIABLE: lambda t: [
|
|
3531
|
+
self._build_token_with_var_subtokens(
|
|
3532
|
+
t, TokenKind.VARIABLE_NAME, site=VariableSite.UNTYPED_DECLARATION
|
|
3533
|
+
)
|
|
3534
|
+
],
|
|
3043
3535
|
},
|
|
3044
3536
|
)
|
|
3045
3537
|
|
|
@@ -3189,11 +3681,61 @@ class SemanticAnalyzer(Visitor):
|
|
|
3189
3681
|
line_start=node.lineno,
|
|
3190
3682
|
line_end=node.end_lineno or node.lineno,
|
|
3191
3683
|
setting_name="Arguments",
|
|
3192
|
-
|
|
3193
|
-
|
|
3684
|
+
tokens=self._build_header_tokens(
|
|
3685
|
+
node,
|
|
3686
|
+
special={Token.ARGUMENT: lambda t: [self._build_argument_definition_token(t)]},
|
|
3687
|
+
),
|
|
3194
3688
|
)
|
|
3195
3689
|
self._add_statement(stmt)
|
|
3196
3690
|
|
|
3691
|
+
def _build_argument_definition_token(self, rf_token: Token) -> SemanticToken:
|
|
3692
|
+
"""[Arguments] entry. `${x}` becomes a PARAMETER token whose sub-tokens
|
|
3693
|
+
split the variable as a declaration; `${x}=default` becomes an ARGUMENT
|
|
3694
|
+
with that PARAMETER, a VARIABLE_DEFAULT_SEPARATOR and the default value.
|
|
3695
|
+
The argument *definitions* themselves are carried on the enclosing
|
|
3696
|
+
definition's `local_variables`, not on these render tokens."""
|
|
3697
|
+
value = rf_token.value
|
|
3698
|
+
line = rf_token.lineno
|
|
3699
|
+
col = rf_token.col_offset
|
|
3700
|
+
name, default = split_from_equals(value)
|
|
3701
|
+
parameter = SemanticToken(kind=TokenKind.PARAMETER, value=name, line=line, col_offset=col, length=len(name))
|
|
3702
|
+
name_subs = build_variable_sub_tokens(
|
|
3703
|
+
name, line, col, site=VariableSite.DECLARATION, is_defined=self._is_variable_defined
|
|
3704
|
+
)
|
|
3705
|
+
if name_subs:
|
|
3706
|
+
parameter.sub_tokens = name_subs
|
|
3707
|
+
if default is None:
|
|
3708
|
+
return parameter
|
|
3709
|
+
parent = SemanticToken(
|
|
3710
|
+
kind=TokenKind.ARGUMENT,
|
|
3711
|
+
value=value,
|
|
3712
|
+
line=line,
|
|
3713
|
+
col_offset=col,
|
|
3714
|
+
length=len(value),
|
|
3715
|
+
)
|
|
3716
|
+
sub_tokens = [
|
|
3717
|
+
parameter,
|
|
3718
|
+
SemanticToken(
|
|
3719
|
+
kind=TokenKind.VARIABLE_DEFAULT_SEPARATOR, value="=", line=line, col_offset=col + len(name), length=1
|
|
3720
|
+
),
|
|
3721
|
+
]
|
|
3722
|
+
if default:
|
|
3723
|
+
default_col = col + len(name) + 1
|
|
3724
|
+
default_rf_token = Token(Token.ARGUMENT, default, line, default_col)
|
|
3725
|
+
default_subs = self._argument_sub_tokens(default_rf_token)
|
|
3726
|
+
sub_tokens.append(
|
|
3727
|
+
SemanticToken(
|
|
3728
|
+
kind=TokenKind.VARIABLE_DEFAULT_VALUE,
|
|
3729
|
+
value=default,
|
|
3730
|
+
line=line,
|
|
3731
|
+
col_offset=default_col,
|
|
3732
|
+
length=len(default),
|
|
3733
|
+
sub_tokens=default_subs,
|
|
3734
|
+
)
|
|
3735
|
+
)
|
|
3736
|
+
parent.sub_tokens = sub_tokens
|
|
3737
|
+
return parent
|
|
3738
|
+
|
|
3197
3739
|
def visit_KeywordTags(self, node: Statement) -> None: # noqa: N802
|
|
3198
3740
|
self._visit_settings_statement(node, DiagnosticSeverity.HINT)
|
|
3199
3741
|
self._collect_tag_references(node, self._keyword_tag_references)
|
|
@@ -3210,14 +3752,30 @@ class SemanticAnalyzer(Visitor):
|
|
|
3210
3752
|
def visit_DocumentationOrMetadata(self, node: Statement) -> None: # noqa: N802
|
|
3211
3753
|
self._visit_settings_statement(node, DiagnosticSeverity.HINT)
|
|
3212
3754
|
|
|
3213
|
-
|
|
3214
|
-
# subclass of DocumentationOrMetadata that adds a `name` attribute).
|
|
3215
|
-
is_metadata = type(node).__name__ == "Metadata"
|
|
3755
|
+
is_metadata = isinstance(node, Metadata)
|
|
3216
3756
|
|
|
3217
|
-
if is_metadata and
|
|
3757
|
+
if is_metadata and node.name:
|
|
3218
3758
|
name_token = node.get_token(Token.NAME)
|
|
3219
3759
|
if name_token is not None:
|
|
3220
|
-
self.
|
|
3760
|
+
if self._in_testcase:
|
|
3761
|
+
refs = self._testcase_metadata_references
|
|
3762
|
+
else:
|
|
3763
|
+
refs = self._metadata_references
|
|
3764
|
+
# metadata names are case, space and underscore insensitive in Robot Framework
|
|
3765
|
+
refs[normalize_metadata_name(node.name)].add(Location(self._document_uri, range_from_token(name_token)))
|
|
3766
|
+
|
|
3767
|
+
# Robot Framework 7.5 warns when a `Tags:` section of a keyword's documentation is not preceded by an empty row
|
|
3768
|
+
if RF_VERSION >= (7, 5) and self._in_keyword and isinstance(node, Documentation):
|
|
3769
|
+
tags_row = tags_row_without_empty_row(node)
|
|
3770
|
+
if tags_row:
|
|
3771
|
+
self._append_diagnostics(
|
|
3772
|
+
range=Range(start=range_from_token(tags_row[0]).start, end=range_from_token(tags_row[-1]).end),
|
|
3773
|
+
message=f"Invalid documentation in '{self._current_testcase_or_keyword_name}': "
|
|
3774
|
+
"Not having an empty row before 'Tags:' is deprecated.",
|
|
3775
|
+
severity=DiagnosticSeverity.WARNING,
|
|
3776
|
+
tags=[DiagnosticTag.DEPRECATED],
|
|
3777
|
+
code=Error.TAGS_WITHOUT_EMPTY_ROW,
|
|
3778
|
+
)
|
|
3221
3779
|
|
|
3222
3780
|
stmt = SettingStatement(
|
|
3223
3781
|
kind=NodeKind.SETTING_METADATA if is_metadata else NodeKind.SETTING_DOCUMENTATION,
|
|
@@ -3271,7 +3829,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
3271
3829
|
|
|
3272
3830
|
def visit_Tags(self, node: Statement) -> None: # noqa: N802
|
|
3273
3831
|
self._visit_settings_statement(node, DiagnosticSeverity.HINT)
|
|
3274
|
-
if
|
|
3832
|
+
if self._in_keyword:
|
|
3275
3833
|
self._collect_tag_references(node, self._keyword_tag_references)
|
|
3276
3834
|
else:
|
|
3277
3835
|
self._collect_tag_references(node, self._testcase_tag_references)
|
|
@@ -3407,7 +3965,12 @@ class SemanticAnalyzer(Visitor):
|
|
|
3407
3965
|
if v.import_source == self._source and v.import_range == range_from_token(name_token):
|
|
3408
3966
|
matched_entry = v
|
|
3409
3967
|
for k in self._namespace_references:
|
|
3410
|
-
|
|
3968
|
+
# the same library imported again, also with other arguments; two classes of one module differ
|
|
3969
|
+
if (
|
|
3970
|
+
type(k) is type(v)
|
|
3971
|
+
and k.library_doc.source_or_origin == v.library_doc.source_or_origin
|
|
3972
|
+
and k.library_doc.name == v.library_doc.name
|
|
3973
|
+
):
|
|
3411
3974
|
self._namespace_references[k].add(Location(self._document_uri, v.import_range))
|
|
3412
3975
|
break
|
|
3413
3976
|
else:
|
|
@@ -3464,18 +4027,22 @@ class SemanticAnalyzer(Visitor):
|
|
|
3464
4027
|
line_end=node.end_lineno or node.lineno,
|
|
3465
4028
|
import_type=import_type_enum,
|
|
3466
4029
|
import_name=name_token.value if name_token else None,
|
|
3467
|
-
tokens=self._build_import_tokens(node),
|
|
4030
|
+
tokens=self._build_import_tokens(node, init_keyword_doc=init_keyword_doc),
|
|
3468
4031
|
lib_entry=matched_entry,
|
|
3469
4032
|
init_keyword_doc=init_keyword_doc,
|
|
3470
4033
|
)
|
|
3471
4034
|
self._add_statement(stmt)
|
|
3472
4035
|
|
|
3473
|
-
def _build_import_tokens(
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
4036
|
+
def _build_import_tokens(
|
|
4037
|
+
self, node: Statement, init_keyword_doc: Optional[KeywordDoc] = None
|
|
4038
|
+
) -> List[SemanticToken]:
|
|
4039
|
+
"""Import tokens with final render semantics: the import word
|
|
4040
|
+
(Library/Resource/Variables) and the "WITH NAME"/"AS" marker are
|
|
4041
|
+
SETTING_IMPORT; the first Token.NAME is the import path (IMPORT_NAME
|
|
4042
|
+
with NAMESPACE text fragments + variable sub-tokens); the alias after
|
|
4043
|
+
the marker is NAMESPACE; Token.ARGUMENT carries import arguments —
|
|
4044
|
+
`name=value` arguments matching the import's init signature split into
|
|
4045
|
+
named-argument sub-tokens.
|
|
3479
4046
|
"""
|
|
3480
4047
|
# Closure-state for first-vs-subsequent NAME differentiation.
|
|
3481
4048
|
first_name_seen = [False]
|
|
@@ -3483,18 +4050,25 @@ class SemanticAnalyzer(Visitor):
|
|
|
3483
4050
|
def handle_name(t: Token) -> List[SemanticToken]:
|
|
3484
4051
|
if not first_name_seen[0]:
|
|
3485
4052
|
first_name_seen[0] = True
|
|
3486
|
-
return [self._build_token_with_var_subtokens(t, TokenKind.IMPORT_NAME)]
|
|
3487
|
-
# Alias after WITH NAME:
|
|
3488
|
-
return [
|
|
4053
|
+
return [self._build_token_with_var_subtokens(t, TokenKind.IMPORT_NAME, text_kind=TokenKind.NAMESPACE)]
|
|
4054
|
+
# Alias after WITH NAME / AS: a namespace name.
|
|
4055
|
+
return [
|
|
4056
|
+
SemanticToken(
|
|
4057
|
+
kind=TokenKind.NAMESPACE,
|
|
4058
|
+
value=t.value,
|
|
4059
|
+
line=t.lineno,
|
|
4060
|
+
col_offset=t.col_offset,
|
|
4061
|
+
length=len(t.value),
|
|
4062
|
+
)
|
|
4063
|
+
]
|
|
3489
4064
|
|
|
3490
4065
|
def handle_as(t: Token) -> List[SemanticToken]:
|
|
3491
|
-
#
|
|
3492
|
-
#
|
|
3493
|
-
#
|
|
3494
|
-
# type; in RF < 7.0 Token.WITH_NAME is a distinct type string.
|
|
4066
|
+
# "WITH NAME" / "AS" in the import context renders as a setting
|
|
4067
|
+
# import. In RF 7.0+ both are the same Token.AS type; in RF < 7.0
|
|
4068
|
+
# Token.WITH_NAME is a distinct type string.
|
|
3495
4069
|
return [
|
|
3496
4070
|
SemanticToken(
|
|
3497
|
-
kind=TokenKind.
|
|
4071
|
+
kind=TokenKind.SETTING_IMPORT,
|
|
3498
4072
|
value=t.value,
|
|
3499
4073
|
line=t.lineno,
|
|
3500
4074
|
col_offset=t.col_offset,
|
|
@@ -3504,7 +4078,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
3504
4078
|
|
|
3505
4079
|
special: Dict[str, Callable[[Token], Optional[List[SemanticToken]]]] = {
|
|
3506
4080
|
Token.NAME: handle_name,
|
|
3507
|
-
Token.ARGUMENT: lambda t: [self._build_argument_semantic_token(t, keyword_doc=
|
|
4081
|
+
Token.ARGUMENT: lambda t: [self._build_argument_semantic_token(t, keyword_doc=init_keyword_doc)],
|
|
3508
4082
|
Token.AS: handle_as,
|
|
3509
4083
|
}
|
|
3510
4084
|
# In RF < 7.0, `Token.WITH_NAME` is a distinct type ("WITH NAME"); in
|
|
@@ -3568,7 +4142,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
3568
4142
|
def _build_while_header_tokens(self, node: Statement) -> List[SemanticToken]:
|
|
3569
4143
|
"""WHILE header tokens: first ARGUMENT becomes CONDITION; subsequent
|
|
3570
4144
|
ARGUMENT tokens that match a known WHILE-option name (RF < 7.0) and
|
|
3571
|
-
Token.OPTION (RF 7.0+)
|
|
4145
|
+
Token.OPTION (RF 7.0+) become OPTION tokens with name, operator and value."""
|
|
3572
4146
|
# Closure-state: the first ARGUMENT is the condition, subsequent ones
|
|
3573
4147
|
# may be RF<7.0-style options.
|
|
3574
4148
|
condition_seen = [False]
|
|
@@ -3577,7 +4151,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
3577
4151
|
if condition_seen[0] and self._looks_like_named_option(t.value, self._WHILE_OPTION_NAMES):
|
|
3578
4152
|
return self._split_option_token(t)
|
|
3579
4153
|
condition_seen[0] = True
|
|
3580
|
-
return [self.
|
|
4154
|
+
return [self._build_condition_token(t)]
|
|
3581
4155
|
|
|
3582
4156
|
return self._build_header_tokens(
|
|
3583
4157
|
node,
|
|
@@ -3640,7 +4214,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
3640
4214
|
return self._build_header_tokens(
|
|
3641
4215
|
node,
|
|
3642
4216
|
special={
|
|
3643
|
-
Token.ARGUMENT: lambda t: [self.
|
|
4217
|
+
Token.ARGUMENT: lambda t: [self._build_condition_token(t)],
|
|
3644
4218
|
},
|
|
3645
4219
|
)
|
|
3646
4220
|
|
|
@@ -3732,7 +4306,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
3732
4306
|
|
|
3733
4307
|
def _find_variable(self, name: str) -> Optional[VariableDefinition]:
|
|
3734
4308
|
if name[:2] == "%{" and name[-1] == "}":
|
|
3735
|
-
var_name,
|
|
4309
|
+
var_name, sep, default_value = name[2:-1].partition("=")
|
|
3736
4310
|
return EnvironmentVariableDefinition(
|
|
3737
4311
|
0,
|
|
3738
4312
|
0,
|
|
@@ -3741,7 +4315,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
3741
4315
|
"",
|
|
3742
4316
|
f"%{{{var_name}}}",
|
|
3743
4317
|
None,
|
|
3744
|
-
default_value=default_value
|
|
4318
|
+
default_value=default_value if sep else None,
|
|
3745
4319
|
)
|
|
3746
4320
|
|
|
3747
4321
|
vars = (
|
|
@@ -3758,6 +4332,9 @@ class SemanticAnalyzer(Visitor):
|
|
|
3758
4332
|
except (VariableError, InvalidVariableError):
|
|
3759
4333
|
return None
|
|
3760
4334
|
|
|
4335
|
+
def _is_variable_defined(self, name: str) -> bool:
|
|
4336
|
+
return self._find_variable(name) is not None
|
|
4337
|
+
|
|
3761
4338
|
def _try_resolve_nested_variable_base(
|
|
3762
4339
|
self, identifier: str, base: str, name_token: Token
|
|
3763
4340
|
) -> Union[str, Literal[False], tuple[None, str]]:
|
|
@@ -3797,7 +4374,9 @@ class SemanticAnalyzer(Visitor):
|
|
|
3797
4374
|
- ``${scalar}`` → resolved value converted to string, multi-values joined with space
|
|
3798
4375
|
- ``@{list}`` → ``str(list_value)`` e.g. ``"['a', 'b']"
|
|
3799
4376
|
- ``&{dict}`` → ``str(dict_value)`` e.g. ``"{'a': '1'}"
|
|
3800
|
-
- ``%{ENV}`` → environment variable value or default
|
|
4377
|
+
- ``%{ENV}`` → environment variable value or default, ``False`` if a variable in its
|
|
4378
|
+
name or in the default of an unset variable would have to be resolved (a default
|
|
4379
|
+
without variables behind a name with a variable is still returned)
|
|
3801
4380
|
- ``${{expr}}`` → cannot evaluate statically → ``False``
|
|
3802
4381
|
|
|
3803
4382
|
Returns:
|
|
@@ -3817,11 +4396,20 @@ class SemanticAnalyzer(Visitor):
|
|
|
3817
4396
|
# Environment variable %{VAR} or %{VAR=default}
|
|
3818
4397
|
if sub_id == "%":
|
|
3819
4398
|
env_inner = var_ref[2:-1]
|
|
4399
|
+
# A variable in the name means the environment variable RF looks up is not known here.
|
|
4400
|
+
name, name_default = split_from_equals(env_inner)
|
|
4401
|
+
if contains_variable(name, "$@&%"):
|
|
4402
|
+
if name_default is not None and not contains_variable(name_default, "$@&%"):
|
|
4403
|
+
return name_default
|
|
4404
|
+
return False
|
|
3820
4405
|
env_name, sep, default = env_inner.partition("=")
|
|
3821
4406
|
env_val = os.environ.get(env_name)
|
|
3822
4407
|
if env_val is not None:
|
|
3823
4408
|
return env_val
|
|
3824
4409
|
if sep:
|
|
4410
|
+
# A variable in the default is not resolved here.
|
|
4411
|
+
if contains_variable(default, "$@&%"):
|
|
4412
|
+
return False
|
|
3825
4413
|
return default
|
|
3826
4414
|
return None
|
|
3827
4415
|
|
|
@@ -3994,6 +4582,7 @@ class SemanticAnalyzer(Visitor):
|
|
|
3994
4582
|
token,
|
|
3995
4583
|
identifiers="$@&%",
|
|
3996
4584
|
parse_type=parse_type,
|
|
4585
|
+
is_defined=self._is_variable_defined,
|
|
3997
4586
|
ignore_errors=True,
|
|
3998
4587
|
extra_types=None,
|
|
3999
4588
|
exception_handler=exception_handler,
|