Skip to content

Commit dee91c4

Browse files
committed
fix(discover): wrong filename in diagnostics message on update single document
1 parent 7c5a6af commit dee91c4

File tree

3 files changed

+40
-49
lines changed

3 files changed

+40
-49
lines changed

packages/runner/src/robotcode/runner/cli/discover/discover.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import io
12
import os
23
import re
34
import sys
45
from dataclasses import dataclass
6+
from io import IOBase
57
from pathlib import Path
68
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
79

@@ -14,6 +16,7 @@
1416
from robot.output import LOGGER, Message
1517
from robot.running.builder import TestSuiteBuilder
1618
from robot.running.builder.builders import SuiteStructureParser
19+
from robot.utils.filereader import FileReader
1720
from robotcode.core.dataclasses import from_json
1821
from robotcode.core.lsp.types import Diagnostic, DiagnosticSeverity, DocumentUri, Position, Range
1922
from robotcode.core.uri import Uri
@@ -42,8 +45,6 @@ def _patch() -> None:
4245
__patched = True
4346

4447
if get_robot_version() <= (6, 1, 0, "a", 1, None):
45-
from robot.running.builder.parsers import RobotParser
46-
4748
if get_robot_version() > (5, 0) and get_robot_version() < (6, 0, 0) or get_robot_version() < (5, 0):
4849
from robot.running.builder.testsettings import TestDefaults # pyright: ignore[reportMissingImports]
4950
else:
@@ -81,20 +82,8 @@ def build_suite(self: SuiteStructureParser, structure: Any) -> Tuple[TestSuite,
8182

8283
SuiteStructureParser._build_suite = build_suite
8384

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-
9585
elif get_robot_version() >= (6, 1, 0, "a", 1, None):
9686
from robot.parsing.suitestructure import SuiteDirectory, SuiteFile
97-
from robot.running.builder.parsers import RobotParser
9887
from robot.running.builder.settings import TestDefaults # pyright: ignore[reportMissingImports]
9988

10089
old_validate_not_empty = TestSuiteBuilder._validate_not_empty
@@ -135,16 +124,18 @@ def build_suite_directory(
135124

136125
SuiteStructureParser._build_suite_directory = build_suite_directory
137126

138-
old_get_source = RobotParser._get_source
127+
old_get_file = FileReader._get_file
139128

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:
141132
if _stdin_data is not None and (data := _stdin_data.get(str(path))) is not None:
142133
if data is not None:
143-
return data
134+
return old_get_file(self, data, accept_text) # type: ignore
144135

145-
return old_get_source(self, path) # type: ignore
136+
return old_get_file(self, source, accept_text) # type: ignore
146137

147-
RobotParser._get_source = _get_source
138+
FileReader._get_file = get_file
148139

149140

150141
@dataclass
@@ -284,7 +275,7 @@ def build_diagnostics(messages: List[Message]) -> Dict[str, List[Diagnostic]]:
284275
def add_diagnostic(
285276
message: Message, source_uri: Optional[str] = None, line: Optional[int] = None, text: Optional[str] = None
286277
) -> 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()))
288279

289280
if source_uri not in result:
290281
result[source_uri] = []

vscode-client/pythonmanger.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ export class PythonManager {
236236
});
237237

238238
process.stderr.on("data", (data) => {
239-
this.outputChannel.append(data as string);
240239
stderr += data;
241240
});
242241

vscode-client/testcontrollermanager.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export class TestControllerManager {
533533
mode_args.push("--rpa");
534534
break;
535535
}
536-
return (await this.languageClientsManager.pythonManager.executeRobotCode(
536+
const result = (await this.languageClientsManager.pythonManager.executeRobotCode(
537537
folder,
538538
[
539539
...(profiles === undefined ? [] : profiles.flatMap((v) => ["--profile", v])),
@@ -548,6 +548,23 @@ export class TestControllerManager {
548548
stdioData,
549549
token
550550
)) as RobotCodeDiscoverResult;
551+
552+
if (result?.diagnostics) {
553+
for (const key of Object.keys(result?.diagnostics ?? {})) {
554+
const diagnostics = result.diagnostics[key];
555+
this.diagnosticCollection.set(
556+
vscode.Uri.parse(key),
557+
diagnostics.map((v) => {
558+
const r = new vscode.Diagnostic(toVsCodeRange(v.range), v.message, diagnosticsSeverityToVsCode(v.severity));
559+
r.source = v.source;
560+
r.code = v.code;
561+
return r;
562+
})
563+
);
564+
}
565+
}
566+
567+
return result;
551568
}
552569

553570
public async getTestsFromWorkspace(
@@ -566,6 +583,12 @@ export class TestControllerManager {
566583
}
567584
}
568585

586+
this.diagnosticCollection.forEach((uri, _diagnostics, collection) => {
587+
if (vscode.workspace.getWorkspaceFolder(uri) === folder) {
588+
collection.delete(uri);
589+
}
590+
});
591+
569592
const result = await this.discoverTests(
570593
folder,
571594
["discover", "--read-from-stdin", "all"],
@@ -574,30 +597,6 @@ export class TestControllerManager {
574597
token
575598
);
576599

577-
this.diagnosticCollection.forEach((uri, _diagnostics, collection) => {
578-
if (vscode.workspace.getWorkspaceFolder(uri) === folder) {
579-
collection.delete(uri);
580-
}
581-
});
582-
583-
if (result?.diagnostics) {
584-
for (const key of Object.keys(result?.diagnostics ?? {})) {
585-
const diagnostics = result.diagnostics[key];
586-
this.diagnosticCollection.set(
587-
vscode.Uri.parse(key),
588-
diagnostics.map((v) => {
589-
const r = new vscode.Diagnostic(
590-
toVsCodeRange(v.range),
591-
v.message,
592-
diagnosticsSeverityToVsCode(v.severity)
593-
);
594-
r.source = v.source;
595-
r.code = v.code;
596-
return r;
597-
})
598-
);
599-
}
600-
}
601600
return result?.items;
602601
} catch (e) {
603602
console.error(e);
@@ -627,6 +626,10 @@ export class TestControllerManager {
627626
const o: { [key: string]: string } = {};
628627
o[document.fileName] = document.getText();
629628

629+
if (this.diagnosticCollection.has(document.uri)) {
630+
this.diagnosticCollection.delete(document.uri);
631+
}
632+
630633
const result = await this.discoverTests(
631634
folder,
632635
["discover", "--read-from-stdin", "tests"],
@@ -767,9 +770,7 @@ export class TestControllerManager {
767770
testItem.label = robotTestItem.name;
768771
testItem.description = robotTestItem.description;
769772
if (robotTestItem.error !== undefined) {
770-
const error = new vscode.MarkdownString();
771-
error.appendCodeblock(robotTestItem.error);
772-
testItem.error = error;
773+
testItem.error = robotTestItem.error;
773774
}
774775

775776
const tags = this.convertTags(robotTestItem.tags);

0 commit comments

Comments
 (0)