|
21 | 21 | )
|
22 | 22 |
|
23 | 23 | from robot.parsing.lexer.tokens import Token
|
| 24 | +from robot.parsing.model.blocks import Section |
24 | 25 | from robot.parsing.model.statements import (
|
25 | 26 | Arguments,
|
26 | 27 | Documentation,
|
|
74 | 75 | if get_robot_version() >= (5, 0):
|
75 | 76 | from robot.parsing.model.statements import ExceptHeader, WhileHeader
|
76 | 77 |
|
| 78 | +if get_robot_version() >= (7, 0): |
| 79 | + from robot.parsing.model.blocks import InvalidSection |
| 80 | + |
77 | 81 | if TYPE_CHECKING:
|
78 | 82 | from ..protocol import RobotLanguageServerProtocol
|
79 | 83 |
|
@@ -981,7 +985,15 @@ def _collect_internal(
|
981 | 985 | last_col = 0
|
982 | 986 |
|
983 | 987 | def get_tokens() -> Iterator[Tuple[Token, ast.AST]]:
|
| 988 | + current_section: Optional[Section] = None |
| 989 | + in_invalid_section = False |
| 990 | + |
984 | 991 | for node in iter_nodes(model):
|
| 992 | + if cached_isinstance(node, Section): |
| 993 | + current_section = node |
| 994 | + if get_robot_version() >= (7, 0): |
| 995 | + in_invalid_section = cached_isinstance(current_section, InvalidSection) |
| 996 | + |
985 | 997 | check_current_task_canceled()
|
986 | 998 |
|
987 | 999 | if cached_isinstance(node, Statement):
|
@@ -1145,7 +1157,7 @@ def get_tokens() -> Iterator[Tuple[Token, ast.AST]]:
|
1145 | 1157 | continue
|
1146 | 1158 |
|
1147 | 1159 | for token in node.tokens:
|
1148 |
| - if token.type == Token.COMMENT: |
| 1160 | + if not in_invalid_section and token.type == Token.COMMENT: |
1149 | 1161 | continue
|
1150 | 1162 | yield token, node
|
1151 | 1163 |
|
|
0 commit comments