Skip to content

Commit 7250709

Browse files
committed
fix: correct hovering, goto, etc. for if/else if/inline if statements
1 parent 633b6b5 commit 7250709

File tree

4,310 files changed

+60575
-53583
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,310 files changed

+60575
-53583
lines changed

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

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ async def _definition_default(
149149
]
150150
return None
151151

152-
async def definition_IfHeader( # noqa: N802
152+
async def _definition_IfElseHeader( # noqa: N802
153153
self, node: ast.AST, nodes: List[ast.AST], document: TextDocument, position: Position, collect_type: CollectType
154154
) -> Union[Location, List[Location], List[LocationLink], None]:
155155
from robot.parsing.lexer.tokens import Token as RobotToken
156-
from robot.parsing.model.statements import IfHeader
156+
from robot.parsing.model.statements import Statement
157157

158158
namespace = await self.parent.documents_cache.get_namespace(document)
159159

160-
header = cast(IfHeader, node)
160+
header = cast(Statement, node)
161161

162162
expression_token = header.get_token(RobotToken.ARGUMENT)
163163
if expression_token is not None and position in range_from_token(expression_token):
@@ -188,43 +188,20 @@ async def definition_IfHeader( # noqa: N802
188188

189189
return None
190190

191-
async def definition_WhileHeader( # noqa: N802
191+
async def definition_IfElseHeader( # noqa: N802
192192
self, node: ast.AST, nodes: List[ast.AST], document: TextDocument, position: Position, collect_type: CollectType
193193
) -> Union[Location, List[Location], List[LocationLink], None]:
194-
from robot.parsing.lexer.tokens import Token as RobotToken
195-
from robot.parsing.model.statements import WhileHeader
196-
197-
namespace = await self.parent.documents_cache.get_namespace(document)
194+
return await self._definition_IfElseHeader(node, nodes, document, position, collect_type)
198195

199-
header = cast(WhileHeader, node)
200-
201-
expression_token = header.get_token(RobotToken.ARGUMENT)
202-
if expression_token is not None and position in range_from_token(expression_token):
203-
token_and_var = await async_next(
204-
(
205-
(var_token, var)
206-
async for var_token, var in self.iter_expression_variables_from_token(
207-
expression_token, namespace, nodes, position, skip_commandline_variables=True
208-
)
209-
if position in range_from_token(var_token)
210-
),
211-
None,
212-
)
213-
if token_and_var is not None:
214-
var_token, variable = token_and_var
196+
async def definition_IfHeader( # noqa: N802
197+
self, node: ast.AST, nodes: List[ast.AST], document: TextDocument, position: Position, collect_type: CollectType
198+
) -> Union[Location, List[Location], List[LocationLink], None]:
199+
return await self._definition_IfElseHeader(node, nodes, document, position, collect_type)
215200

216-
if variable.source:
217-
return [
218-
LocationLink(
219-
origin_selection_range=range_from_token(var_token),
220-
target_uri=str(Uri.from_path(variable.source)),
221-
target_range=variable.range,
222-
target_selection_range=range_from_token(variable.name_token)
223-
if variable.name_token
224-
else variable.range,
225-
)
226-
]
227-
return None
201+
async def definition_WhileHeader( # noqa: N802
202+
self, node: ast.AST, nodes: List[ast.AST], document: TextDocument, position: Position, collect_type: CollectType
203+
) -> Union[Location, List[Location], List[LocationLink], None]:
204+
return await self._definition_IfElseHeader(node, nodes, document, position, collect_type)
228205

229206
async def definition_KeywordName( # noqa: N802
230207
self, node: ast.AST, nodes: List[ast.AST], document: TextDocument, position: Position, collect_type: CollectType

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

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,15 @@ async def _hover_default(self, nodes: List[ast.AST], document: TextDocument, pos
138138

139139
return None
140140

141-
async def hover_IfHeader( # noqa: N802
141+
async def _hover_IfElseHeader( # noqa: N802
142142
self, node: ast.AST, nodes: List[ast.AST], document: TextDocument, position: Position
143143
) -> Optional[Hover]:
144144
from robot.parsing.lexer.tokens import Token as RobotToken
145-
from robot.parsing.model.statements import IfHeader
145+
from robot.parsing.model.statements import Statement
146146

147147
namespace = await self.parent.documents_cache.get_namespace(document)
148148

149-
header = cast(IfHeader, node)
150-
151-
expression_token = header.get_token(RobotToken.ARGUMENT)
149+
expression_token = cast(Statement, node).get_token(RobotToken.ARGUMENT)
152150
if expression_token is not None and position in range_from_token(expression_token):
153151
token_and_var = await async_next(
154152
(
@@ -187,54 +185,20 @@ async def hover_IfHeader( # noqa: N802
187185

188186
return None
189187

190-
async def hover_WhileHeader( # noqa: N802
188+
async def hover_IfElseHeader( # noqa: N802
191189
self, node: ast.AST, nodes: List[ast.AST], document: TextDocument, position: Position
192190
) -> Optional[Hover]:
193-
from robot.parsing.lexer.tokens import Token as RobotToken
194-
from robot.parsing.model.statements import WhileHeader
195-
196-
namespace = await self.parent.documents_cache.get_namespace(document)
197-
198-
header = cast(WhileHeader, node)
191+
return await self._hover_IfElseHeader(node, nodes, document, position)
199192

200-
expression_token = header.get_token(RobotToken.ARGUMENT)
201-
if expression_token is not None and position in range_from_token(expression_token):
202-
token_and_var = await async_next(
203-
(
204-
(var_token, var)
205-
async for var_token, var in self.iter_expression_variables_from_token(
206-
expression_token, namespace, nodes, position
207-
)
208-
if position in range_from_token(var_token)
209-
),
210-
None,
211-
)
212-
if token_and_var is not None:
213-
var_token, variable = token_and_var
214-
215-
if variable.has_value or variable.resolvable:
216-
try:
217-
value = await namespace.imports_manager.resolve_variable(
218-
variable.name,
219-
str(document.uri.to_path().parent),
220-
await namespace.get_resolvable_variables(nodes, position),
221-
)
222-
except (asyncio.CancelledError, SystemExit, KeyboardInterrupt):
223-
raise
224-
except BaseException:
225-
value = ""
226-
else:
227-
value = ""
228-
229-
return Hover(
230-
contents=MarkupContent(
231-
kind=MarkupKind.MARKDOWN,
232-
value=f"({variable.type.value}) {variable.name} {f'= `{value}`' if value else ''}",
233-
),
234-
range=range_from_token(var_token),
235-
)
193+
async def hover_IfHeader( # noqa: N802
194+
self, node: ast.AST, nodes: List[ast.AST], document: TextDocument, position: Position
195+
) -> Optional[Hover]:
196+
return await self._hover_IfElseHeader(node, nodes, document, position)
236197

237-
return None
198+
async def hover_WhileHeader( # noqa: N802
199+
self, node: ast.AST, nodes: List[ast.AST], document: TextDocument, position: Position
200+
) -> Optional[Hover]:
201+
return await self._hover_IfElseHeader(node, nodes, document, position)
238202

239203
async def hover_KeywordCall( # noqa: N802
240204
self, node: ast.AST, nodes: List[ast.AST], document: TextDocument, position: Position

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,8 @@ def get_expression_statement_types(cls) -> Tuple[Type[Any]]:
522522
cls.__expression_statement_types = (robot.parsing.model.statements.IfHeader,)
523523

524524
if get_robot_version() >= (5, 0):
525-
cls.__expression_statement_types = ( # type: ignore
526-
robot.parsing.model.statements.IfHeader,
525+
cls.__expression_statement_types = ( # type: ignore[assignment]
526+
robot.parsing.model.statements.IfElseHeader,
527527
robot.parsing.model.statements.WhileHeader,
528528
)
529529

tests/robotcode/language_server/robotframework/parts/_regtest_outputs/rf41/test_document_highlight.test[document_highlight.robot-009-041-Variable_in_library_params].out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ result:
2626
range:
2727
end:
2828
character: 44
29-
line: 58
29+
line: 60
3030
start:
3131
character: 37
32-
line: 58
32+
line: 60

tests/robotcode/language_server/robotframework/parts/_regtest_outputs/rf41/test_document_highlight.test[document_highlight.robot-009-045-Variable_in_library_params].out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ result:
2626
range:
2727
end:
2828
character: 44
29-
line: 58
29+
line: 60
3030
start:
3131
character: 37
32-
line: 58
32+
line: 60

tests/robotcode/language_server/robotframework/parts/_regtest_outputs/rf41/test_document_highlight.test[document_highlight.robot-012-023-suite_fixture_keyword_call_with_namespace].out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,52 +26,52 @@ result:
2626
range:
2727
end:
2828
character: 29
29-
line: 26
29+
line: 28
3030
start:
3131
character: 15
32-
line: 26
32+
line: 28
3333
- !DocumentHighlight
3434
kind: !DocumentHighlightKind 'TEXT'
3535
range:
3636
end:
3737
character: 40
38-
line: 28
38+
line: 30
3939
start:
4040
character: 26
41-
line: 28
41+
line: 30
4242
- !DocumentHighlight
4343
kind: !DocumentHighlightKind 'TEXT'
4444
range:
4545
end:
4646
character: 18
47-
line: 32
47+
line: 34
4848
start:
4949
character: 4
50-
line: 32
50+
line: 34
5151
- !DocumentHighlight
5252
kind: !DocumentHighlightKind 'TEXT'
5353
range:
5454
end:
5555
character: 26
56-
line: 34
56+
line: 36
5757
start:
5858
character: 12
59-
line: 34
59+
line: 36
6060
- !DocumentHighlight
6161
kind: !DocumentHighlightKind 'TEXT'
6262
range:
6363
end:
6464
character: 32
65-
line: 41
65+
line: 43
6666
start:
6767
character: 18
68-
line: 41
68+
line: 43
6969
- !DocumentHighlight
7070
kind: !DocumentHighlightKind 'TEXT'
7171
range:
7272
end:
7373
character: 40
74-
line: 47
74+
line: 49
7575
start:
7676
character: 26
77-
line: 47
77+
line: 49

tests/robotcode/language_server/robotframework/parts/_regtest_outputs/rf41/test_document_highlight.test[document_highlight.robot-012-030-suite_fixture_keyword_call_with_namespace].out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,52 +26,52 @@ result:
2626
range:
2727
end:
2828
character: 29
29-
line: 26
29+
line: 28
3030
start:
3131
character: 15
32-
line: 26
32+
line: 28
3333
- !DocumentHighlight
3434
kind: !DocumentHighlightKind 'TEXT'
3535
range:
3636
end:
3737
character: 40
38-
line: 28
38+
line: 30
3939
start:
4040
character: 26
41-
line: 28
41+
line: 30
4242
- !DocumentHighlight
4343
kind: !DocumentHighlightKind 'TEXT'
4444
range:
4545
end:
4646
character: 18
47-
line: 32
47+
line: 34
4848
start:
4949
character: 4
50-
line: 32
50+
line: 34
5151
- !DocumentHighlight
5252
kind: !DocumentHighlightKind 'TEXT'
5353
range:
5454
end:
5555
character: 26
56-
line: 34
56+
line: 36
5757
start:
5858
character: 12
59-
line: 34
59+
line: 36
6060
- !DocumentHighlight
6161
kind: !DocumentHighlightKind 'TEXT'
6262
range:
6363
end:
6464
character: 32
65-
line: 41
65+
line: 43
6666
start:
6767
character: 18
68-
line: 41
68+
line: 43
6969
- !DocumentHighlight
7070
kind: !DocumentHighlightKind 'TEXT'
7171
range:
7272
end:
7373
character: 40
74-
line: 47
74+
line: 49
7575
start:
7676
character: 26
77-
line: 47
77+
line: 49

tests/robotcode/language_server/robotframework/parts/_regtest_outputs/rf41/test_document_highlight.test[document_highlight.robot-012-036-suite_fixture_keyword_call_with_namespace].out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,52 +26,52 @@ result:
2626
range:
2727
end:
2828
character: 29
29-
line: 26
29+
line: 28
3030
start:
3131
character: 15
32-
line: 26
32+
line: 28
3333
- !DocumentHighlight
3434
kind: !DocumentHighlightKind 'TEXT'
3535
range:
3636
end:
3737
character: 40
38-
line: 28
38+
line: 30
3939
start:
4040
character: 26
41-
line: 28
41+
line: 30
4242
- !DocumentHighlight
4343
kind: !DocumentHighlightKind 'TEXT'
4444
range:
4545
end:
4646
character: 18
47-
line: 32
47+
line: 34
4848
start:
4949
character: 4
50-
line: 32
50+
line: 34
5151
- !DocumentHighlight
5252
kind: !DocumentHighlightKind 'TEXT'
5353
range:
5454
end:
5555
character: 26
56-
line: 34
56+
line: 36
5757
start:
5858
character: 12
59-
line: 34
59+
line: 36
6060
- !DocumentHighlight
6161
kind: !DocumentHighlightKind 'TEXT'
6262
range:
6363
end:
6464
character: 32
65-
line: 41
65+
line: 43
6666
start:
6767
character: 18
68-
line: 41
68+
line: 43
6969
- !DocumentHighlight
7070
kind: !DocumentHighlightKind 'TEXT'
7171
range:
7272
end:
7373
character: 40
74-
line: 47
74+
line: 49
7575
start:
7676
character: 26
77-
line: 47
77+
line: 49

0 commit comments

Comments
 (0)