robotcode-robot 2.3.0__tar.gz → 2.4.0__tar.gz

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.
Files changed (33) hide show
  1. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/PKG-INFO +1 -1
  2. robotcode_robot-2.4.0/src/robotcode/robot/__version__.py +1 -0
  3. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/data_cache.py +1 -0
  4. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/diagnostics_modifier.py +8 -3
  5. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/document_cache_helper.py +50 -134
  6. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/imports_manager.py +212 -126
  7. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/library_doc.py +180 -11
  8. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/namespace.py +26 -195
  9. robotcode_robot-2.3.0/src/robotcode/robot/__version__.py +0 -1
  10. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/.gitignore +0 -0
  11. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/README.md +0 -0
  12. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/pyproject.toml +0 -0
  13. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/__init__.py +0 -0
  14. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/config/__init__.py +0 -0
  15. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/config/loader.py +0 -0
  16. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/config/model.py +0 -0
  17. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/config/utils.py +0 -0
  18. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/__init__.py +0 -0
  19. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/entities.py +0 -0
  20. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/errors.py +0 -0
  21. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/keyword_finder.py +0 -0
  22. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/model_helper.py +0 -0
  23. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/namespace_analyzer.py +0 -0
  24. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/diagnostics/workspace_config.py +0 -0
  25. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/py.typed +0 -0
  26. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/utils/__init__.py +0 -0
  27. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/utils/ast.py +0 -0
  28. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/utils/markdownformatter.py +0 -0
  29. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/utils/match.py +0 -0
  30. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/utils/robot_path.py +0 -0
  31. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/utils/stubs.py +0 -0
  32. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/utils/variables.py +0 -0
  33. {robotcode_robot-2.3.0 → robotcode_robot-2.4.0}/src/robotcode/robot/utils/visitor.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: robotcode-robot
3
- Version: 2.3.0
3
+ Version: 2.4.0
4
4
  Summary: Support classes for RobotCode for handling Robot Framework projects.
5
5
  Project-URL: Homepage, https://robotcode.io
6
6
  Project-URL: Donate, https://opencollective.com/robotcode
@@ -0,0 +1 @@
1
+ __version__ = "2.4.0"
@@ -12,6 +12,7 @@ _T = TypeVar("_T")
12
12
  class CacheSection(Enum):
13
13
  LIBRARY = "libdoc"
14
14
  VARIABLES = "variables"
15
+ RESOURCE = "resource"
15
16
 
16
17
 
17
18
  class DataCache(ABC):
@@ -46,6 +46,10 @@ _translation_table = str.maketrans("", "", "_- ")
46
46
  ROBOTCODE_MARKER = "robotcode:"
47
47
 
48
48
 
49
+ def text_contains_diagnostic_modifier(text: str) -> bool:
50
+ return ROBOTCODE_MARKER in text
51
+
52
+
49
53
  class ModifiersVisitor(Visitor):
50
54
  def __init__(self) -> None:
51
55
  super().__init__()
@@ -181,7 +185,7 @@ class DiagnosticModifiersConfig:
181
185
 
182
186
 
183
187
  class DiagnosticsModifier:
184
- def __init__(self, model: AST, config: Optional[DiagnosticModifiersConfig] = None) -> None:
188
+ def __init__(self, model: Optional[AST], config: Optional[DiagnosticModifiersConfig] = None) -> None:
185
189
  self.config = config or DiagnosticModifiersConfig()
186
190
 
187
191
  self.config.ignore = [i.translate(_translation_table).lower() for i in self.config.ignore]
@@ -190,12 +194,13 @@ class DiagnosticsModifier:
190
194
  self.config.information = [i.translate(_translation_table).lower() for i in self.config.information]
191
195
  self.config.hint = [i.translate(_translation_table).lower() for i in self.config.hint]
192
196
 
193
- self.model = model
197
+ self._model = model
194
198
 
195
199
  @functools.cached_property
196
200
  def rules_and_codes(self) -> RulesAndCodes:
197
201
  visitor = ModifiersVisitor()
198
- visitor.visit(self.model)
202
+ if self._model is not None:
203
+ visitor.visit(self._model)
199
204
  return visitor.rules_and_codes
200
205
 
201
206
  def modify_diagnostic(self, diagnostic: Diagnostic) -> Optional[Diagnostic]:
@@ -8,7 +8,6 @@ from logging import CRITICAL
8
8
  from pathlib import Path
9
9
  from typing import (
10
10
  Any,
11
- Callable,
12
11
  Iterable,
13
12
  Iterator,
14
13
  List,
@@ -26,7 +25,11 @@ from robotcode.core.text_document import TextDocument
26
25
  from robotcode.core.uri import Uri
27
26
  from robotcode.core.utils.logging import LoggingDescriptor
28
27
  from robotcode.core.workspace import Workspace, WorkspaceFolder
29
- from robotcode.robot.diagnostics.diagnostics_modifier import DiagnosticModifiersConfig, DiagnosticsModifier
28
+ from robotcode.robot.diagnostics.diagnostics_modifier import (
29
+ DiagnosticModifiersConfig,
30
+ DiagnosticsModifier,
31
+ text_contains_diagnostic_modifier,
32
+ )
30
33
 
31
34
  from ..config.model import RobotBaseProfile
32
35
  from ..utils import get_robot_version
@@ -172,43 +175,16 @@ class DocumentsCacheHelper:
172
175
  return DocumentType.UNKNOWN
173
176
 
174
177
  def get_tokens(self, document: TextDocument, data_only: bool = False) -> List[Token]:
175
- if data_only:
176
- return self.__get_tokens_data_only(document)
177
- return self.__get_tokens(document)
178
-
179
- def __get_tokens_data_only(self, document: TextDocument) -> List[Token]:
180
- document_type = self.get_document_type(document)
181
- if document_type == DocumentType.INIT:
182
- return self.get_init_tokens(document, True)
183
- if document_type == DocumentType.GENERAL:
184
- return self.get_general_tokens(document, True)
185
- if document_type == DocumentType.RESOURCE:
186
- return self.get_resource_tokens(document, True)
187
-
188
- raise UnknownFileTypeError(str(document.uri))
189
-
190
- def __get_tokens(self, document: TextDocument) -> List[Token]:
191
178
  document_type = self.get_document_type(document)
192
179
  if document_type == DocumentType.INIT:
193
- return self.get_init_tokens(document)
180
+ return self.__get_init_tokens(document, data_only)
194
181
  if document_type == DocumentType.GENERAL:
195
- return self.get_general_tokens(document)
182
+ return self.__get_general_tokens(document, data_only)
196
183
  if document_type == DocumentType.RESOURCE:
197
- return self.get_resource_tokens(document)
184
+ return self.__get_resource_tokens(document, data_only)
198
185
 
199
186
  raise UnknownFileTypeError(str(document.uri))
200
187
 
201
- def get_general_tokens(self, document: TextDocument, data_only: bool = False) -> List[Token]:
202
- if document.version is None:
203
- if data_only:
204
- return self.__get_general_tokens_data_only(document)
205
-
206
- return self.__get_general_tokens(document)
207
-
208
- if data_only:
209
- return document.get_cache(self.__get_general_tokens_data_only)
210
- return document.get_cache(self.__get_general_tokens)
211
-
212
188
  def __internal_get_tokens(
213
189
  self,
214
190
  source: Any,
@@ -266,85 +242,20 @@ class DocumentsCacheHelper:
266
242
 
267
243
  return robot.api.get_init_tokens(source, data_only=data_only, tokenize_variables=tokenize_variables)
268
244
 
269
- def __get_general_tokens_data_only(self, document: TextDocument) -> List[Token]:
245
+ def __get_general_tokens(self, document: TextDocument, data_only: bool = False) -> List[Token]:
270
246
  lang = self.get_languages_for_document(document)
247
+ with io.StringIO(document.text()) as content:
248
+ return [e for e in self.__internal_get_tokens(content, data_only, lang=lang)]
271
249
 
272
- def get(text: str) -> List[Token]:
273
- with io.StringIO(text) as content:
274
- return [e for e in self.__internal_get_tokens(content, True, lang=lang)]
275
-
276
- return self.__get_tokens_internal(document, get)
277
-
278
- def __get_general_tokens(self, document: TextDocument) -> List[Token]:
250
+ def __get_resource_tokens(self, document: TextDocument, data_only: bool = False) -> List[Token]:
279
251
  lang = self.get_languages_for_document(document)
252
+ with io.StringIO(document.text()) as content:
253
+ return [e for e in self.__internal_get_resource_tokens(content, data_only, lang=lang)]
280
254
 
281
- def get(text: str) -> List[Token]:
282
- with io.StringIO(text) as content:
283
- return [e for e in self.__internal_get_tokens(content, lang=lang)]
284
-
285
- return self.__get_tokens_internal(document, get)
286
-
287
- def __get_tokens_internal(self, document: TextDocument, get: Callable[[str], List[Token]]) -> List[Token]:
288
- return get(document.text())
289
-
290
- def get_resource_tokens(self, document: TextDocument, data_only: bool = False) -> List[Token]:
291
- if document.version is None:
292
- if data_only:
293
- return self.__get_resource_tokens_data_only(document)
294
-
295
- return self.__get_resource_tokens(document)
296
-
297
- if data_only:
298
- return document.get_cache(self.__get_resource_tokens_data_only)
299
-
300
- return document.get_cache(self.__get_resource_tokens)
301
-
302
- def __get_resource_tokens_data_only(self, document: TextDocument) -> List[Token]:
303
- lang = self.get_languages_for_document(document)
304
-
305
- def get(text: str) -> List[Token]:
306
- with io.StringIO(text) as content:
307
- return [e for e in self.__internal_get_resource_tokens(content, True, lang=lang)]
308
-
309
- return self.__get_tokens_internal(document, get)
310
-
311
- def __get_resource_tokens(self, document: TextDocument) -> List[Token]:
312
- lang = self.get_languages_for_document(document)
313
-
314
- def get(text: str) -> List[Token]:
315
- with io.StringIO(text) as content:
316
- return [e for e in self.__internal_get_resource_tokens(content, lang=lang)]
317
-
318
- return self.__get_tokens_internal(document, get)
319
-
320
- def get_init_tokens(self, document: TextDocument, data_only: bool = False) -> List[Token]:
321
- if document.version is None:
322
- if data_only:
323
- return self.__get_init_tokens_data_only(document)
324
-
325
- return self.__get_init_tokens(document)
326
-
327
- if data_only:
328
- return document.get_cache(self.__get_init_tokens_data_only)
329
- return document.get_cache(self.__get_init_tokens)
330
-
331
- def __get_init_tokens_data_only(self, document: TextDocument) -> List[Token]:
255
+ def __get_init_tokens(self, document: TextDocument, data_only: bool = False) -> List[Token]:
332
256
  lang = self.get_languages_for_document(document)
333
-
334
- def get(text: str) -> List[Token]:
335
- with io.StringIO(text) as content:
336
- return [e for e in self.__internal_get_init_tokens(content, True, lang=lang)]
337
-
338
- return self.__get_tokens_internal(document, get)
339
-
340
- def __get_init_tokens(self, document: TextDocument) -> List[Token]:
341
- lang = self.get_languages_for_document(document)
342
-
343
- def get(text: str) -> List[Token]:
344
- with io.StringIO(text) as content:
345
- return [e for e in self.__internal_get_init_tokens(content, lang=lang)]
346
-
347
- return self.__get_tokens_internal(document, get)
257
+ with io.StringIO(document.text()) as content:
258
+ return [e for e in self.__internal_get_init_tokens(content, data_only, lang=lang)]
348
259
 
349
260
  def get_model(self, document: TextDocument, data_only: bool = True) -> ast.AST:
350
261
  document_type = self.get_document_type(document)
@@ -383,59 +294,56 @@ class DocumentsCacheHelper:
383
294
  def get_general_model(self, document: TextDocument, data_only: bool = True) -> ast.AST:
384
295
  if document.version is None:
385
296
  if data_only:
386
- return self.__get_general_model_data_only(document, self.get_general_tokens(document, True))
297
+ return self.__get_general_model_data_only(document)
387
298
 
388
- return self.__get_general_model(document, self.get_general_tokens(document))
299
+ return self.__get_general_model(document)
389
300
 
390
301
  if data_only:
391
- return document.get_cache(self.__get_general_model_data_only, self.get_general_tokens(document, True))
302
+ return document.get_cache(self.__get_general_model_data_only)
392
303
 
393
- return document.get_cache(self.__get_general_model, self.get_general_tokens(document))
304
+ return document.get_cache(self.__get_general_model)
394
305
 
395
- def __get_general_model_data_only(self, document: TextDocument, tokens: Iterable[Any]) -> ast.AST:
396
- return self.__get_model(document, tokens, DocumentType.GENERAL)
306
+ def __get_general_model_data_only(self, document: TextDocument) -> ast.AST:
307
+ return self.__get_model(document, self.__get_general_tokens(document, True), DocumentType.GENERAL)
397
308
 
398
- def __get_general_model(self, document: TextDocument, tokens: Iterable[Any]) -> ast.AST:
399
- return self.__get_model(document, tokens, DocumentType.GENERAL)
309
+ def __get_general_model(self, document: TextDocument) -> ast.AST:
310
+ return self.__get_model(document, self.__get_general_tokens(document), DocumentType.GENERAL)
400
311
 
401
312
  def get_resource_model(self, document: TextDocument, data_only: bool = True) -> ast.AST:
402
313
  if document.version is None:
403
314
  if data_only:
404
- return self.__get_resource_model_data_only(document, self.get_resource_tokens(document, True))
315
+ return self.__get_resource_model_data_only(document)
405
316
 
406
- return self.__get_resource_model(document, self.get_resource_tokens(document))
317
+ return self.__get_resource_model(document)
407
318
 
408
319
  if data_only:
409
- return document.get_cache(
410
- self.__get_resource_model_data_only,
411
- self.get_resource_tokens(document, True),
412
- )
320
+ return document.get_cache(self.__get_resource_model_data_only)
413
321
 
414
- return document.get_cache(self.__get_resource_model, self.get_resource_tokens(document))
322
+ return document.get_cache(self.__get_resource_model)
415
323
 
416
- def __get_resource_model_data_only(self, document: TextDocument, tokens: Iterable[Any]) -> ast.AST:
417
- return self.__get_model(document, tokens, DocumentType.RESOURCE)
324
+ def __get_resource_model_data_only(self, document: TextDocument) -> ast.AST:
325
+ return self.__get_model(document, self.__get_resource_tokens(document, True), DocumentType.RESOURCE)
418
326
 
419
- def __get_resource_model(self, document: TextDocument, tokens: Iterable[Any]) -> ast.AST:
420
- return self.__get_model(document, tokens, DocumentType.RESOURCE)
327
+ def __get_resource_model(self, document: TextDocument) -> ast.AST:
328
+ return self.__get_model(document, self.__get_resource_tokens(document), DocumentType.RESOURCE)
421
329
 
422
330
  def get_init_model(self, document: TextDocument, data_only: bool = True) -> ast.AST:
423
331
  if document.version is None:
424
332
  if data_only:
425
- return self.__get_init_model_data_only(document, self.get_init_tokens(document, True))
333
+ return self.__get_init_model_data_only(document)
426
334
 
427
- return self.__get_init_model(document, self.get_init_tokens(document))
335
+ return self.__get_init_model(document)
428
336
 
429
337
  if data_only:
430
- return document.get_cache(self.__get_init_model_data_only, self.get_init_tokens(document, True))
338
+ return document.get_cache(self.__get_init_model_data_only)
431
339
 
432
- return document.get_cache(self.__get_init_model, self.get_init_tokens(document))
340
+ return document.get_cache(self.__get_init_model)
433
341
 
434
- def __get_init_model_data_only(self, document: TextDocument, tokens: Iterable[Any]) -> ast.AST:
435
- return self.__get_model(document, tokens, DocumentType.INIT)
342
+ def __get_init_model_data_only(self, document: TextDocument) -> ast.AST:
343
+ return self.__get_model(document, self.__get_init_tokens(document, True), DocumentType.INIT)
436
344
 
437
- def __get_init_model(self, document: TextDocument, tokens: Iterable[Any]) -> ast.AST:
438
- return self.__get_model(document, tokens, DocumentType.INIT)
345
+ def __get_init_model(self, document: TextDocument) -> ast.AST:
346
+ return self.__get_model(document, self.__get_init_tokens(document), DocumentType.INIT)
439
347
 
440
348
  def get_namespace(self, document: TextDocument) -> Namespace:
441
349
  document_type = self.get_document_type(document)
@@ -627,8 +535,16 @@ class DocumentsCacheHelper:
627
535
 
628
536
  def __get_diagnostic_modifier(self, document: TextDocument) -> DiagnosticsModifier:
629
537
  modifiers_config = self.workspace.get_configuration(AnalysisDiagnosticModifiersConfig, document.uri)
538
+
539
+ has_modifier = text_contains_diagnostic_modifier(document.text())
540
+
541
+ if has_modifier:
542
+ self._logger.debug(
543
+ lambda: f"Document {document.uri} contains diagnostic modifier comment, analyzing model for it"
544
+ )
545
+
630
546
  return DiagnosticsModifier(
631
- self.get_model(document, False),
547
+ self.get_model(document, False) if has_modifier else None,
632
548
  DiagnosticModifiersConfig(
633
549
  ignore=self.analysis_config.modifiers.ignore + modifiers_config.ignore,
634
550
  error=self.analysis_config.modifiers.error + modifiers_config.error,