|
| 1 | +import io |
1 | 2 | import os |
2 | 3 | import re |
3 | 4 | import sys |
4 | 5 | from dataclasses import dataclass |
| 6 | +from io import IOBase |
5 | 7 | from pathlib import Path |
6 | 8 | from typing import Any, Dict, Iterable, List, Optional, Tuple, Union |
7 | 9 |
|
|
14 | 16 | from robot.output import LOGGER, Message |
15 | 17 | from robot.running.builder import TestSuiteBuilder |
16 | 18 | from robot.running.builder.builders import SuiteStructureParser |
| 19 | +from robot.utils.filereader import FileReader |
17 | 20 | from robotcode.core.dataclasses import from_json |
18 | 21 | from robotcode.core.lsp.types import Diagnostic, DiagnosticSeverity, DocumentUri, Position, Range |
19 | 22 | from robotcode.core.uri import Uri |
@@ -42,8 +45,6 @@ def _patch() -> None: |
42 | 45 | __patched = True |
43 | 46 |
|
44 | 47 | if get_robot_version() <= (6, 1, 0, "a", 1, None): |
45 | | - from robot.running.builder.parsers import RobotParser |
46 | | - |
47 | 48 | if get_robot_version() > (5, 0) and get_robot_version() < (6, 0, 0) or get_robot_version() < (5, 0): |
48 | 49 | from robot.running.builder.testsettings import TestDefaults # pyright: ignore[reportMissingImports] |
49 | 50 | else: |
@@ -81,20 +82,8 @@ def build_suite(self: SuiteStructureParser, structure: Any) -> Tuple[TestSuite, |
81 | 82 |
|
82 | 83 | SuiteStructureParser._build_suite = build_suite |
83 | 84 |
|
84 | | - old_get_source = RobotParser._get_source |
85 | | - |
86 | | - def _get_source(self: RobotParser, path: Path) -> Union[Path, str]: |
87 | | - if _stdin_data is not None and (data := _stdin_data.get(str(path))) is not None: |
88 | | - if data is not None: |
89 | | - return data |
90 | | - |
91 | | - return old_get_source(self, path) # type: ignore |
92 | | - |
93 | | - RobotParser._get_source = _get_source |
94 | | - |
95 | 85 | elif get_robot_version() >= (6, 1, 0, "a", 1, None): |
96 | 86 | from robot.parsing.suitestructure import SuiteDirectory, SuiteFile |
97 | | - from robot.running.builder.parsers import RobotParser |
98 | 87 | from robot.running.builder.settings import TestDefaults # pyright: ignore[reportMissingImports] |
99 | 88 |
|
100 | 89 | old_validate_not_empty = TestSuiteBuilder._validate_not_empty |
@@ -135,16 +124,18 @@ def build_suite_directory( |
135 | 124 |
|
136 | 125 | SuiteStructureParser._build_suite_directory = build_suite_directory |
137 | 126 |
|
138 | | - old_get_source = RobotParser._get_source |
| 127 | + old_get_file = FileReader._get_file |
139 | 128 |
|
140 | | - def _get_source(self: RobotParser, path: Path) -> Union[Path, str]: |
| 129 | + def get_file(self: FileReader, source: Union[str, Path, IOBase], accept_text: bool) -> Tuple[io.IOBase, bool]: |
| 130 | + path = self._get_path(source, accept_text) |
| 131 | + if path: |
141 | 132 | if _stdin_data is not None and (data := _stdin_data.get(str(path))) is not None: |
142 | 133 | if data is not None: |
143 | | - return data |
| 134 | + return old_get_file(self, data, accept_text) # type: ignore |
144 | 135 |
|
145 | | - return old_get_source(self, path) # type: ignore |
| 136 | + return old_get_file(self, source, accept_text) # type: ignore |
146 | 137 |
|
147 | | - RobotParser._get_source = _get_source |
| 138 | + FileReader._get_file = get_file |
148 | 139 |
|
149 | 140 |
|
150 | 141 | @dataclass |
@@ -284,7 +275,7 @@ def build_diagnostics(messages: List[Message]) -> Dict[str, List[Diagnostic]]: |
284 | 275 | def add_diagnostic( |
285 | 276 | message: Message, source_uri: Optional[str] = None, line: Optional[int] = None, text: Optional[str] = None |
286 | 277 | ) -> None: |
287 | | - source_uri = str(Uri.from_path(Path(source_uri) if source_uri else Path.cwd())) |
| 278 | + source_uri = str(Uri.from_path(Path(source_uri).absolute() if source_uri else Path.cwd())) |
288 | 279 |
|
289 | 280 | if source_uri not in result: |
290 | 281 | result[source_uri] = [] |
|
0 commit comments