robotcode-robot 2.9.0.dev186__tar.gz → 2.9.0.dev197__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.
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/PKG-INFO +2 -2
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/pyproject.toml +1 -1
- robotcode_robot-2.9.0.dev197/src/robotcode/robot/__version__.py +1 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/document_cache_helper.py +46 -9
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/imports_manager.py +2 -1
- robotcode_robot-2.9.0.dev197/src/robotcode/robot/document_formats.py +129 -0
- robotcode_robot-2.9.0.dev197/src/robotcode/robot/utils/markdown_blocks.py +123 -0
- robotcode_robot-2.9.0.dev186/src/robotcode/robot/__version__.py +0 -1
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/.gitignore +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/README.md +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/__init__.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/config/__init__.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/config/loader.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/config/model.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/config/utils.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/__init__.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/analyzer_result.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/data_cache.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/diagnostic_rules.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/diagnostics_modifier.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/entities.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/errors.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/import_resolver.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/keyword_finder.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/library_doc.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/model_helper.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/namespace.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/namespace_analyzer.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/project_index.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/scope_tree.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/semantic_analyzer/__init__.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/semantic_analyzer/analyzer.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/semantic_analyzer/enums.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/semantic_analyzer/json_dump.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/semantic_analyzer/model.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/semantic_analyzer/nodes.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/semantic_analyzer/run_keyword.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/semantic_analyzer/serialization.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/semantic_analyzer/variable_tokenizer.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/variable_scope.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/diagnostics/workspace_config.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/py.typed +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/__init__.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/ast.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/markdown_docs.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/markdownformatter.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/match.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/robot_patching.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/robot_path.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/stubs.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/variables.py +0 -0
- {robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/visitor.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: robotcode-robot
|
|
3
|
-
Version: 2.9.0-dev.
|
|
3
|
+
Version: 2.9.0-dev.197
|
|
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
|
|
@@ -27,7 +27,7 @@ Classifier: Topic :: Utilities
|
|
|
27
27
|
Classifier: Typing :: Typed
|
|
28
28
|
Requires-Python: >=3.10
|
|
29
29
|
Requires-Dist: platformdirs>=4.3
|
|
30
|
-
Requires-Dist: robotcode-core==2.9.0-dev.
|
|
30
|
+
Requires-Dist: robotcode-core==2.9.0-dev.197
|
|
31
31
|
Requires-Dist: robotframework>=5.0.0
|
|
32
32
|
Requires-Dist: tomli>=1.1.0; python_version < '3.11'
|
|
33
33
|
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.9.0-dev.197"
|
|
@@ -8,6 +8,7 @@ from logging import CRITICAL
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from typing import (
|
|
10
10
|
Any,
|
|
11
|
+
Callable,
|
|
11
12
|
Dict,
|
|
12
13
|
Iterable,
|
|
13
14
|
Iterator,
|
|
@@ -34,7 +35,9 @@ from robotcode.robot.diagnostics.diagnostics_modifier import (
|
|
|
34
35
|
)
|
|
35
36
|
|
|
36
37
|
from ..config.model import RobotBaseProfile
|
|
38
|
+
from ..document_formats import MARKDOWN_LANGUAGE_ID, is_markdown_file
|
|
37
39
|
from ..utils import RF_VERSION
|
|
40
|
+
from ..utils.markdown_blocks import RobotBlock, find_robot_blocks, read_markdown_data
|
|
38
41
|
from ..utils.stubs import Languages
|
|
39
42
|
from .data_cache import CacheSection
|
|
40
43
|
from .imports_manager import ImportsManager, NamespaceMetaData
|
|
@@ -60,6 +63,9 @@ class UnknownFileTypeError(Exception):
|
|
|
60
63
|
pass
|
|
61
64
|
|
|
62
65
|
|
|
66
|
+
DataReader = Callable[[str], Tuple[str, Dict[int, int]]]
|
|
67
|
+
|
|
68
|
+
|
|
63
69
|
def _namespace_cache_key(source: str, document_type: Optional[DocumentType]) -> str:
|
|
64
70
|
"""Disk-cache entry name for a namespace.
|
|
65
71
|
|
|
@@ -101,6 +107,8 @@ class DocumentsCacheHelper:
|
|
|
101
107
|
self.robot_profile = robot_profile or RobotBaseProfile()
|
|
102
108
|
self.analysis_config = analysis_config or WorkspaceAnalysisConfig()
|
|
103
109
|
|
|
110
|
+
self.data_readers: Dict[str, DataReader] = {MARKDOWN_LANGUAGE_ID: read_markdown_data}
|
|
111
|
+
|
|
104
112
|
self._imports_managers_lock = threading.RLock()
|
|
105
113
|
self._imports_managers: weakref.WeakKeyDictionary[WorkspaceFolder, ImportsManager] = weakref.WeakKeyDictionary()
|
|
106
114
|
self._default_imports_manager: Optional[ImportsManager] = None
|
|
@@ -242,9 +250,44 @@ class DocumentsCacheHelper:
|
|
|
242
250
|
return DocumentType.GENERAL
|
|
243
251
|
if suffix == ".resource":
|
|
244
252
|
return DocumentType.RESOURCE
|
|
253
|
+
if document.language_id == MARKDOWN_LANGUAGE_ID:
|
|
254
|
+
# like Robot Framework: `__init__.robot.md` is a suite file
|
|
255
|
+
return DocumentType.INIT if path.stem.lower() == "__init__" else DocumentType.GENERAL
|
|
245
256
|
|
|
246
257
|
return DocumentType.UNKNOWN
|
|
247
258
|
|
|
259
|
+
def get_markdown_blocks(self, document: TextDocument) -> List[RobotBlock]:
|
|
260
|
+
"""The code blocks Robot Framework executes, of a Markdown document."""
|
|
261
|
+
return document.get_cache(self.__get_markdown_blocks)
|
|
262
|
+
|
|
263
|
+
def __get_markdown_blocks(self, document: TextDocument) -> List[RobotBlock]:
|
|
264
|
+
return find_robot_blocks(document.text())
|
|
265
|
+
|
|
266
|
+
def __data_reader(self, document: TextDocument, resource: bool) -> Optional[DataReader]:
|
|
267
|
+
# Robot Framework picks the parser of a resource file by its suffix, also without an active format
|
|
268
|
+
if resource and is_markdown_file(document.uri.to_path()):
|
|
269
|
+
return read_markdown_data
|
|
270
|
+
|
|
271
|
+
return self.data_readers.get(document.language_id) if document.language_id is not None else None
|
|
272
|
+
|
|
273
|
+
def __tokenize(
|
|
274
|
+
self, document: TextDocument, tokenizer: Callable[..., Iterable[Token]], resource: bool = False
|
|
275
|
+
) -> List[Token]:
|
|
276
|
+
lang = self.get_languages_for_document(document)
|
|
277
|
+
|
|
278
|
+
reader = self.__data_reader(document, resource)
|
|
279
|
+
if reader is None:
|
|
280
|
+
with io.StringIO(document.text()) as content:
|
|
281
|
+
return [e for e in tokenizer(content, lang=lang)]
|
|
282
|
+
|
|
283
|
+
data, offsets = reader(document.text())
|
|
284
|
+
with io.StringIO(data) as content:
|
|
285
|
+
tokens: List[Token] = [e for e in tokenizer(content, lang=lang)]
|
|
286
|
+
if offsets:
|
|
287
|
+
for token in tokens:
|
|
288
|
+
token.col_offset += offsets.get(token.lineno, 0)
|
|
289
|
+
return tokens
|
|
290
|
+
|
|
248
291
|
def get_tokens(self, document: TextDocument) -> List[Token]:
|
|
249
292
|
document_type = self.get_document_type(document)
|
|
250
293
|
if document_type == DocumentType.INIT:
|
|
@@ -311,19 +354,13 @@ class DocumentsCacheHelper:
|
|
|
311
354
|
return robot.api.get_init_tokens(source, data_only=False, tokenize_variables=tokenize_variables)
|
|
312
355
|
|
|
313
356
|
def __get_general_tokens(self, document: TextDocument) -> List[Token]:
|
|
314
|
-
|
|
315
|
-
with io.StringIO(document.text()) as content:
|
|
316
|
-
return [e for e in self.__internal_get_tokens(content, lang=lang)]
|
|
357
|
+
return self.__tokenize(document, self.__internal_get_tokens)
|
|
317
358
|
|
|
318
359
|
def __get_resource_tokens(self, document: TextDocument) -> List[Token]:
|
|
319
|
-
|
|
320
|
-
with io.StringIO(document.text()) as content:
|
|
321
|
-
return [e for e in self.__internal_get_resource_tokens(content, lang=lang)]
|
|
360
|
+
return self.__tokenize(document, self.__internal_get_resource_tokens, resource=True)
|
|
322
361
|
|
|
323
362
|
def __get_init_tokens(self, document: TextDocument) -> List[Token]:
|
|
324
|
-
|
|
325
|
-
with io.StringIO(document.text()) as content:
|
|
326
|
-
return [e for e in self.__internal_get_init_tokens(content, lang=lang)]
|
|
363
|
+
return self.__tokenize(document, self.__internal_get_init_tokens)
|
|
327
364
|
|
|
328
365
|
def get_model(self, document: TextDocument) -> ast.AST:
|
|
329
366
|
document_type = self.get_document_type(document)
|
|
@@ -56,6 +56,7 @@ from robotcode.core.utils.path import (
|
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
from ..__version__ import __version__
|
|
59
|
+
from ..document_formats import MARKDOWN_LANGUAGE_ID
|
|
59
60
|
from ..utils import RF_VERSION
|
|
60
61
|
from ..utils.robot_path import find_file_ex
|
|
61
62
|
from ..utils.stubs import Languages
|
|
@@ -1272,7 +1273,7 @@ class ImportsManager:
|
|
|
1272
1273
|
# unresolved imports (file didn't exist yet) get invalidated and re-analyzed.
|
|
1273
1274
|
self.imports_changed(self, uri)
|
|
1274
1275
|
|
|
1275
|
-
@language_id("robotframework")
|
|
1276
|
+
@language_id("robotframework", MARKDOWN_LANGUAGE_ID)
|
|
1276
1277
|
def _on_possible_resource_document_modified(self, sender: Any, document: TextDocument) -> None:
|
|
1277
1278
|
run_as_task(self.__on_possible_resource_document_modified, sender, document)
|
|
1278
1279
|
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Callable, Dict, List, Optional, Tuple, Union
|
|
5
|
+
|
|
6
|
+
from robot.running.builder import TestSuiteBuilder
|
|
7
|
+
from robotcode.core.language import LanguageDefinition
|
|
8
|
+
from robotcode.core.utils.dataclasses import CamelSnakeMixin
|
|
9
|
+
|
|
10
|
+
from .config.model import RobotBaseProfile, StringExpression
|
|
11
|
+
from .utils import RF_VERSION
|
|
12
|
+
|
|
13
|
+
# Robot Framework reads Markdown files since 7.5, with line and column numbers of the file since 7.5.1
|
|
14
|
+
MARKDOWN_SUPPORTED = RF_VERSION >= (7, 5, 1)
|
|
15
|
+
|
|
16
|
+
if MARKDOWN_SUPPORTED:
|
|
17
|
+
from robot.parsing.suitestructure import IncludedFiles
|
|
18
|
+
|
|
19
|
+
ROBOT_FORMAT_NAME = "robot"
|
|
20
|
+
MARKDOWN_FORMAT_NAME = "markdown"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# TODO: with Gherkin, also list the formats of the custom parsers in the profile's `parsers`, from
|
|
24
|
+
# `TestSuiteBuilder(custom_parsers=...).custom_parsers` per profile (each parser's `name` and `extensions`)
|
|
25
|
+
def _robot_framework_formats() -> Tuple[Tuple[str, ...], Dict[str, str]]:
|
|
26
|
+
"""Robot Framework's default extensions, and the format of each extension it has a parser for."""
|
|
27
|
+
builder = TestSuiteBuilder()
|
|
28
|
+
defaults = tuple(e.lower().lstrip(".") for e in builder.included_extensions)
|
|
29
|
+
if RF_VERSION < (6, 1):
|
|
30
|
+
return defaults, {"rst": "rest", "rest": "rest"}
|
|
31
|
+
return defaults, {e: type(p).__name__.removesuffix("Parser").lower() for e, p in builder.standard_parsers.items()}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
DEFAULT_EXTENSIONS, _FORMAT_OF_EXTENSION = _robot_framework_formats()
|
|
35
|
+
|
|
36
|
+
# the language of the Markdown files Robot Framework parses; no editor sends it, the server detects it by file name
|
|
37
|
+
MARKDOWN_LANGUAGE_ID = "robotframework-markdown"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(frozen=True)
|
|
41
|
+
class DocumentFormat(CamelSnakeMixin):
|
|
42
|
+
"""A document format Robot Framework parses, with the extensions it parses with it (lower case, no dot)."""
|
|
43
|
+
|
|
44
|
+
name: str
|
|
45
|
+
extensions: List[str]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _evaluated(value: Union[str, StringExpression]) -> str:
|
|
49
|
+
return value if isinstance(value, str) else value.evaluate()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _parse_include_patterns(profile: RobotBaseProfile) -> List[str]:
|
|
53
|
+
return [_evaluated(p) for p in profile.parse_include or []]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _robot_framework_extensions(profile: RobotBaseProfile) -> List[str]:
|
|
57
|
+
"""Robot Framework's extension list for the profile: `extensions`, or the default extensions when it is not set,
|
|
58
|
+
plus the extension of each `parse-include` pattern, normalised like Robot Framework (lower case, no dot)."""
|
|
59
|
+
entries = _evaluated(profile.extensions).split(":") if profile.extensions else list(DEFAULT_EXTENSIONS)
|
|
60
|
+
entries += [os.path.splitext(p)[1] for p in _parse_include_patterns(profile)]
|
|
61
|
+
|
|
62
|
+
result: List[str] = []
|
|
63
|
+
for entry in entries:
|
|
64
|
+
extension = entry.lower().lstrip(".")
|
|
65
|
+
if extension and extension not in result:
|
|
66
|
+
result.append(extension)
|
|
67
|
+
return result
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def document_formats(profile: RobotBaseProfile) -> List[DocumentFormat]:
|
|
71
|
+
"""The document formats Robot Framework parses with the evaluated profile, in the order of their first extension."""
|
|
72
|
+
formats: Dict[str, List[str]] = {}
|
|
73
|
+
for extension in _robot_framework_extensions(profile):
|
|
74
|
+
formats.setdefault(_FORMAT_OF_EXTENSION.get(extension, ROBOT_FORMAT_NAME), []).append(extension)
|
|
75
|
+
return [DocumentFormat(name, extensions) for name, extensions in formats.items()]
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def markdown_extensions(profile: RobotBaseProfile) -> List[str]:
|
|
79
|
+
"""The extensions of the Markdown files RobotCode serves, from Robot Framework 7.5.1 on."""
|
|
80
|
+
if not MARKDOWN_SUPPORTED:
|
|
81
|
+
return []
|
|
82
|
+
return [e for f in document_formats(profile) if f.name == MARKDOWN_FORMAT_NAME for e in f.extensions]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _pattern_from_root(pattern: str, root: Path) -> str:
|
|
86
|
+
# Robot Framework resolves a pattern that holds a `/`, has no `.` or names an existing path from its working
|
|
87
|
+
# directory, the project root for `robotcode robot`; other patterns match file names
|
|
88
|
+
normalized = os.path.normpath(pattern).replace("\\", "/")
|
|
89
|
+
if "/" in normalized or "." not in normalized or (root / normalized).exists():
|
|
90
|
+
return str(root / normalized)
|
|
91
|
+
return pattern
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def parse_include_condition(profile: RobotBaseProfile, root: Path) -> Optional[Callable[[Path], bool]]:
|
|
95
|
+
"""Whether Robot Framework parses a file of a valid extension, by the `parse-include` patterns of the profile;
|
|
96
|
+
`None` when it sets none. An `__init__` file needs no pattern, as in Robot Framework."""
|
|
97
|
+
patterns = _parse_include_patterns(profile)
|
|
98
|
+
if not MARKDOWN_SUPPORTED or not patterns:
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
included = IncludedFiles([_pattern_from_root(p, root) for p in patterns])
|
|
102
|
+
|
|
103
|
+
def condition(path: Path) -> bool:
|
|
104
|
+
return path.stem.lower() == "__init__" or bool(included.match(path))
|
|
105
|
+
|
|
106
|
+
return condition
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def markdown_language_definition(profile: RobotBaseProfile, root: Path) -> Optional[LanguageDefinition]:
|
|
110
|
+
"""The language of the Markdown files Robot Framework parses with the profile in the project `root`; `None` when
|
|
111
|
+
no Markdown extension is active."""
|
|
112
|
+
extensions = [f".{e}" for e in markdown_extensions(profile)]
|
|
113
|
+
if not extensions:
|
|
114
|
+
return None
|
|
115
|
+
|
|
116
|
+
return LanguageDefinition(
|
|
117
|
+
id=MARKDOWN_LANGUAGE_ID,
|
|
118
|
+
extensions=extensions,
|
|
119
|
+
extensions_ignore_case=True,
|
|
120
|
+
file_condition=parse_include_condition(profile, root),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def is_markdown_file(path: Path) -> bool:
|
|
125
|
+
"""Whether Robot Framework reads the file with its Markdown parser, from its code blocks.
|
|
126
|
+
|
|
127
|
+
Robot Framework picks the parser of a resource file by its suffix, so this holds also without an active format.
|
|
128
|
+
"""
|
|
129
|
+
return MARKDOWN_SUPPORTED and path.suffix.lower() in (".md", ".markdown")
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import ast
|
|
2
|
+
import io
|
|
3
|
+
import re
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Dict, Iterator, List, Optional, Sequence, Tuple, cast
|
|
6
|
+
|
|
7
|
+
from robot.parsing.lexer.tokens import Token
|
|
8
|
+
from robot.parsing.model.statements import Statement
|
|
9
|
+
from robot.utils import FileReader
|
|
10
|
+
from robotcode.core.lsp.types import Range
|
|
11
|
+
|
|
12
|
+
from .ast import range_from_token
|
|
13
|
+
|
|
14
|
+
# Robot Framework's rule for the code blocks it executes, see `MarkdownParser._read_markdown_data`
|
|
15
|
+
_FENCE_OPEN = re.compile(r"(\s*)(`{3,}|~{3,})\s*(\S+)")
|
|
16
|
+
_ROBOT_LANGUAGES = ("robotframework", "robot")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class RobotBlock:
|
|
21
|
+
"""A code block of a Markdown file that Robot Framework executes, with 0-based line numbers."""
|
|
22
|
+
|
|
23
|
+
opening_fence: int
|
|
24
|
+
# `None` when the block runs to the end of the file
|
|
25
|
+
closing_fence: Optional[int]
|
|
26
|
+
# the indentation of the opening fence, which Robot Framework removes from the content lines
|
|
27
|
+
indent: int = 0
|
|
28
|
+
|
|
29
|
+
def contains(self, line: int) -> bool:
|
|
30
|
+
"""Whether the line is a content line of the block, between its fences."""
|
|
31
|
+
return line > self.opening_fence and (self.closing_fence is None or line < self.closing_fence)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _read_lines(text: str) -> Iterator[str]:
|
|
35
|
+
# the lines as Robot Framework reads a Markdown file, with `\r\n` turned into `\n`
|
|
36
|
+
with FileReader(io.StringIO(text)) as reader:
|
|
37
|
+
yield from reader.readlines()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def find_robot_blocks(text: str) -> List[RobotBlock]:
|
|
41
|
+
"""The `robot`/`robotframework` code blocks of a Markdown text."""
|
|
42
|
+
blocks: List[RobotBlock] = []
|
|
43
|
+
fence_close: Optional[re.Pattern[str]] = None
|
|
44
|
+
opening_fence = 0
|
|
45
|
+
fence_indent = 0
|
|
46
|
+
|
|
47
|
+
for line_index, line in enumerate(_read_lines(text)):
|
|
48
|
+
if fence_close is None:
|
|
49
|
+
match = _FENCE_OPEN.match(line)
|
|
50
|
+
if match:
|
|
51
|
+
indent, fence, lang = match.groups()
|
|
52
|
+
if lang.lower() in _ROBOT_LANGUAGES:
|
|
53
|
+
fence_close = re.compile(rf"\s*{fence[0]}{{{len(fence)},}}\s*")
|
|
54
|
+
opening_fence = line_index
|
|
55
|
+
fence_indent = len(indent)
|
|
56
|
+
elif fence_close.fullmatch(line):
|
|
57
|
+
blocks.append(RobotBlock(opening_fence, line_index, fence_indent))
|
|
58
|
+
fence_close = None
|
|
59
|
+
|
|
60
|
+
if fence_close is not None:
|
|
61
|
+
blocks.append(RobotBlock(opening_fence, None, fence_indent))
|
|
62
|
+
|
|
63
|
+
return blocks
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def indent_for_block(text: str, block: Optional[RobotBlock]) -> str:
|
|
67
|
+
"""The text with the indentation of the block before each line that is not empty, for code placed into it."""
|
|
68
|
+
if block is None or not block.indent:
|
|
69
|
+
return text
|
|
70
|
+
prefix = " " * block.indent
|
|
71
|
+
return "".join(prefix + line if line.strip() else line for line in text.splitlines(keepends=True))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def find_block(blocks: Sequence[RobotBlock], line: int) -> Optional[RobotBlock]:
|
|
75
|
+
"""The block that holds the 0-based line as a content line."""
|
|
76
|
+
for block in blocks:
|
|
77
|
+
if block.contains(line):
|
|
78
|
+
return block
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
_NON_DATA_TOKENS = {Token.SEPARATOR, Token.EOL, Token.EOS}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def range_in_blocks(node: ast.AST, blocks: Sequence[RobotBlock]) -> Optional[Range]:
|
|
86
|
+
"""The range of a node in a Markdown document, inside the code blocks; `None` when no token is in one.
|
|
87
|
+
|
|
88
|
+
In Robot Framework's data the prose and fence lines after a node are empty lines of the node, and so are the
|
|
89
|
+
empty lines of a following block without data. The range ends with the last line with data and the empty lines
|
|
90
|
+
after it in the same block.
|
|
91
|
+
"""
|
|
92
|
+
tokens = [
|
|
93
|
+
token
|
|
94
|
+
for statement in ast.walk(node)
|
|
95
|
+
if isinstance(statement, Statement)
|
|
96
|
+
for token in statement.tokens
|
|
97
|
+
if token.lineno >= 1 and find_block(blocks, token.lineno - 1) is not None
|
|
98
|
+
]
|
|
99
|
+
if not tokens:
|
|
100
|
+
return None
|
|
101
|
+
|
|
102
|
+
first = min(tokens, key=lambda t: (t.lineno, t.col_offset))
|
|
103
|
+
data = [t for t in tokens if t.type not in _NON_DATA_TOKENS]
|
|
104
|
+
if data:
|
|
105
|
+
last_data = max(data, key=lambda t: (t.lineno, t.end_col_offset))
|
|
106
|
+
block = find_block(blocks, last_data.lineno - 1)
|
|
107
|
+
tokens = [t for t in tokens if t.lineno >= last_data.lineno and find_block(blocks, t.lineno - 1) == block]
|
|
108
|
+
last = max(tokens, key=lambda t: (t.lineno, t.end_col_offset))
|
|
109
|
+
|
|
110
|
+
return Range(range_from_token(first).start, range_from_token(last).end)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def read_markdown_data(text: str) -> Tuple[str, Dict[int, int]]:
|
|
114
|
+
"""The Robot Framework data of a Markdown text and the column offsets of its dedented lines.
|
|
115
|
+
|
|
116
|
+
Lines outside the code blocks and the fence lines are empty; the offsets map 1-based line numbers to the
|
|
117
|
+
number of characters removed from the start of the line. Needs Robot Framework 7.5.1 or newer.
|
|
118
|
+
"""
|
|
119
|
+
from robot.running.builder.parsers import MarkdownParser
|
|
120
|
+
|
|
121
|
+
# a private method of Robot Framework, the only place that gives its dedent of indented blocks exactly
|
|
122
|
+
with FileReader(io.StringIO(text)) as reader:
|
|
123
|
+
return cast(Tuple[str, Dict[int, int]], MarkdownParser()._read_markdown_data(reader))
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.9.0-dev.186"
|
|
File without changes
|
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/__init__.py
RENAMED
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/config/__init__.py
RENAMED
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/config/loader.py
RENAMED
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/config/model.py
RENAMED
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/config/utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/__init__.py
RENAMED
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/ast.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/match.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/stubs.py
RENAMED
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/variables.py
RENAMED
|
File without changes
|
{robotcode_robot-2.9.0.dev186 → robotcode_robot-2.9.0.dev197}/src/robotcode/robot/utils/visitor.py
RENAMED
|
File without changes
|