robotcode-robot 1.3.0.dev3__py3-none-any.whl → 1.3.0.dev5__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.
@@ -1 +1 @@
1
- __version__ = "1.3.0-dev.3"
1
+ __version__ = "1.3.0-dev.5"
@@ -19,7 +19,7 @@ from robot.parsing.lexer.tokens import Token
19
19
  from robotcode.core.lsp.types import Position, Range
20
20
 
21
21
  from ..utils.ast import range_from_token
22
- from ..utils.variables import VariableMatcher
22
+ from ..utils.variables import VariableMatcher, search_variable
23
23
 
24
24
  if TYPE_CHECKING:
25
25
  from robotcode.robot.diagnostics.library_doc import KeywordDoc, LibraryDoc
@@ -187,10 +187,17 @@ class VariableDefinition(SourceEntity):
187
187
 
188
188
  value: Any = field(default=None, compare=False)
189
189
  value_is_native: bool = field(default=False, compare=False)
190
+ value_type: Optional[str] = field(default=None, compare=False)
190
191
 
191
192
  @functools.cached_property
192
193
  def matcher(self) -> VariableMatcher:
193
- return VariableMatcher(self.name)
194
+ return search_variable(self.name)
195
+
196
+ @functools.cached_property
197
+ def convertable_name(self) -> str:
198
+ m = self.matcher
199
+ value_type = f": {self.value_type}" if self.value_type else ""
200
+ return f"{m.identifier}{{{m.base.strip()}{value_type}}}"
194
201
 
195
202
  @single_call
196
203
  def __hash__(self) -> int:
@@ -268,6 +275,15 @@ class ArgumentDefinition(LocalVariableDefinition):
268
275
  return hash((type(self), self.name, self.type, self.range, self.source))
269
276
 
270
277
 
278
+ @dataclass
279
+ class EmbeddedArgumentDefinition(ArgumentDefinition):
280
+ pattern: Optional[str] = field(default=None, compare=False)
281
+
282
+ @single_call
283
+ def __hash__(self) -> int:
284
+ return hash((type(self), self.name, self.type, self.range, self.source))
285
+
286
+
271
287
  @dataclass
272
288
  class LibraryArgumentDefinition(ArgumentDefinition):
273
289
  @single_call
@@ -87,9 +87,25 @@ class KeywordFinder:
87
87
  try:
88
88
  result = self._find_keyword(name, handle_bdd_style)
89
89
  if result is None:
90
+ error_message = "No keyword with found."
91
+
92
+ if name and name.strip(": ").upper() == "FOR":
93
+ error_message = (
94
+ f"Support for the old FOR loop syntax has been removed. "
95
+ f"Replace '{name}' with 'FOR', end the loop with 'END', and "
96
+ f"remove escaping backslashes."
97
+ )
98
+ elif name and name == "\\":
99
+ error_message = (
100
+ "No keyword with name '\\' found. If it is used inside a for "
101
+ "loop, remove escaping backslashes and end the loop with 'END'."
102
+ )
103
+ else:
104
+ error_message = f"No keyword with name '{name}' found."
105
+
90
106
  self.diagnostics.append(
91
107
  DiagnosticsEntry(
92
- f"No keyword with name '{name}' found.",
108
+ error_message,
93
109
  DiagnosticSeverity.ERROR,
94
110
  Error.KEYWORD_NOT_FOUND,
95
111
  )
@@ -306,17 +322,32 @@ class KeywordFinder:
306
322
  return True
307
323
  return False
308
324
 
309
- def _is_better_match(
310
- self,
311
- candidate: Tuple[Optional[LibraryEntry], KeywordDoc],
312
- other: Tuple[Optional[LibraryEntry], KeywordDoc],
313
- ) -> bool:
314
- return (
315
- other[1].matcher.embedded_arguments is not None
316
- and candidate[1].matcher.embedded_arguments is not None
317
- and other[1].matcher.embedded_arguments.match(candidate[1].name) is not None
318
- and candidate[1].matcher.embedded_arguments.match(other[1].name) is None
319
- )
325
+ if get_robot_version() >= (7, 3):
326
+
327
+ def _is_better_match(
328
+ self,
329
+ candidate: Tuple[Optional[LibraryEntry], KeywordDoc],
330
+ other: Tuple[Optional[LibraryEntry], KeywordDoc],
331
+ ) -> bool:
332
+ return (
333
+ other[1].matcher.embedded_arguments is not None
334
+ and candidate[1].matcher.embedded_arguments is not None
335
+ and other[1].matcher.embedded_arguments.matches(candidate[1].name)
336
+ and not candidate[1].matcher.embedded_arguments.matches(other[1].name)
337
+ )
338
+ else:
339
+
340
+ def _is_better_match(
341
+ self,
342
+ candidate: Tuple[Optional[LibraryEntry], KeywordDoc],
343
+ other: Tuple[Optional[LibraryEntry], KeywordDoc],
344
+ ) -> bool:
345
+ return (
346
+ other[1].matcher.embedded_arguments is not None
347
+ and candidate[1].matcher.embedded_arguments is not None
348
+ and other[1].matcher.embedded_arguments.match(candidate[1].name) is not None
349
+ and candidate[1].matcher.embedded_arguments.match(other[1].name) is None
350
+ )
320
351
 
321
352
  @functools.cached_property
322
353
  def _resource_imports(self) -> List[ResourceEntry]:
@@ -67,7 +67,7 @@ from robotcode.core.utils.path import normalized_path
67
67
  from ..utils import get_robot_version
68
68
  from ..utils.ast import (
69
69
  cached_isinstance,
70
- get_variable_token,
70
+ get_first_variable_token,
71
71
  range_from_token,
72
72
  strip_variable_token,
73
73
  )
@@ -199,7 +199,7 @@ def convert_from_rest(text: str) -> str:
199
199
 
200
200
 
201
201
  if get_robot_version() >= (6, 0):
202
- # monkey patch robot framework
202
+ # monkey patch robot framework for performance reasons
203
203
  _old_from_name = EmbeddedArguments.from_name
204
204
 
205
205
  @functools.lru_cache(maxsize=8192)
@@ -214,8 +214,14 @@ if get_robot_version() >= (6, 0):
214
214
  except (VariableError, DataError):
215
215
  return ()
216
216
 
217
- def _match_embedded(embedded_arguments: EmbeddedArguments, name: str) -> bool:
218
- return embedded_arguments.match(name) is not None
217
+ if get_robot_version() >= (7, 3):
218
+
219
+ def _match_embedded(embedded_arguments: EmbeddedArguments, name: str) -> bool:
220
+ return bool(embedded_arguments.matches(name))
221
+ else:
222
+
223
+ def _match_embedded(embedded_arguments: EmbeddedArguments, name: str) -> bool:
224
+ return embedded_arguments.match(name) is not None
219
225
 
220
226
  else:
221
227
 
@@ -2779,7 +2785,7 @@ def _get_argument_definitions_from_line(
2779
2785
 
2780
2786
  for argument_token in (cast(RobotToken, e) for e in arguments):
2781
2787
  try:
2782
- argument = get_variable_token(argument_token)
2788
+ argument = get_first_variable_token(argument_token)
2783
2789
 
2784
2790
  if argument is not None and argument.value != "@{}":
2785
2791
  if argument.value not in args: