|
4 | 4 | from typing import TYPE_CHECKING, Any, Optional
|
5 | 5 |
|
6 | 6 | from robotcode.core.async_itertools import async_next
|
7 |
| -from robotcode.core.async_tools import run_coroutine_in_thread, threaded |
| 7 | +from robotcode.core.async_tools import threaded |
8 | 8 | from robotcode.core.dataclasses import CamelSnakeMixin
|
9 | 9 | from robotcode.core.logging import LoggingDescriptor
|
10 | 10 | from robotcode.core.lsp.types import Position, Range, TextDocumentIdentifier
|
@@ -53,55 +53,52 @@ async def _get_evaluatable_expression(
|
53 | 53 | ) -> Optional[EvaluatableExpression]:
|
54 | 54 | from robot.parsing.lexer.tokens import Token as RobotToken
|
55 | 55 |
|
56 |
| - async def run() -> Optional[EvaluatableExpression]: |
57 |
| - document = await self.parent.documents.get(text_document.uri) |
58 |
| - if document is None: |
59 |
| - return None |
| 56 | + document = await self.parent.documents.get(text_document.uri) |
| 57 | + if document is None: |
| 58 | + return None |
60 | 59 |
|
61 |
| - namespace = await self.parent.documents_cache.get_namespace(document) |
62 |
| - model = await self.parent.documents_cache.get_model(document, False) |
| 60 | + namespace = await self.parent.documents_cache.get_namespace(document) |
| 61 | + model = await self.parent.documents_cache.get_model(document, False) |
63 | 62 |
|
64 |
| - nodes = await get_nodes_at_position(model, position) |
65 |
| - node = nodes[-1] |
| 63 | + nodes = await get_nodes_at_position(model, position) |
| 64 | + node = nodes[-1] |
66 | 65 |
|
67 |
| - if not isinstance(node, HasTokens): |
68 |
| - return None |
| 66 | + if not isinstance(node, HasTokens): |
| 67 | + return None |
69 | 68 |
|
70 |
| - token = get_tokens_at_position(node, position)[-1] |
| 69 | + token = get_tokens_at_position(node, position)[-1] |
71 | 70 |
|
| 71 | + token_and_var = await async_next( |
| 72 | + ( |
| 73 | + (t, v) |
| 74 | + async for t, v in self.iter_variables_from_token(token, namespace, nodes, position) |
| 75 | + if position in range_from_token(t) |
| 76 | + ), |
| 77 | + None, |
| 78 | + ) |
| 79 | + |
| 80 | + if ( |
| 81 | + token_and_var is None |
| 82 | + and isinstance(node, self.get_expression_statement_types()) |
| 83 | + and (token := node.get_token(RobotToken.ARGUMENT)) is not None |
| 84 | + and position in range_from_token(token) |
| 85 | + ): |
72 | 86 | token_and_var = await async_next(
|
73 | 87 | (
|
74 |
| - (t, v) |
75 |
| - async for t, v in self.iter_variables_from_token(token, namespace, nodes, position) |
76 |
| - if position in range_from_token(t) |
| 88 | + (var_token, var) |
| 89 | + async for var_token, var in self.iter_expression_variables_from_token( |
| 90 | + token, namespace, nodes, position |
| 91 | + ) |
| 92 | + if position in range_from_token(var_token) |
77 | 93 | ),
|
78 | 94 | None,
|
79 | 95 | )
|
80 | 96 |
|
81 |
| - if ( |
82 |
| - token_and_var is None |
83 |
| - and isinstance(node, self.get_expression_statement_types()) |
84 |
| - and (token := node.get_token(RobotToken.ARGUMENT)) is not None |
85 |
| - and position in range_from_token(token) |
86 |
| - ): |
87 |
| - token_and_var = await async_next( |
88 |
| - ( |
89 |
| - (var_token, var) |
90 |
| - async for var_token, var in self.iter_expression_variables_from_token( |
91 |
| - token, namespace, nodes, position |
92 |
| - ) |
93 |
| - if position in range_from_token(var_token) |
94 |
| - ), |
95 |
| - None, |
96 |
| - ) |
97 |
| - |
98 |
| - if token_and_var is None: |
99 |
| - return None |
100 |
| - |
101 |
| - var_token, var = token_and_var |
102 |
| - if var.name == "${CURDIR}": |
103 |
| - return None |
104 |
| - |
105 |
| - return EvaluatableExpression(range_from_token(var_token), var.name) |
106 |
| - |
107 |
| - return await run_coroutine_in_thread(run) |
| 97 | + if token_and_var is None: |
| 98 | + return None |
| 99 | + |
| 100 | + var_token, var = token_and_var |
| 101 | + if var.name == "${CURDIR}": |
| 102 | + return None |
| 103 | + |
| 104 | + return EvaluatableExpression(range_from_token(var_token), var.name) |
0 commit comments