Skip to content

Commit 94053fc

Browse files
committed
feat: Reintroduce of updating the tests when typing
1 parent ee5f0fb commit 94053fc

File tree

7 files changed

+86
-8
lines changed

7 files changed

+86
-8
lines changed

Diff for: .vscode/launch.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
// "--",
3939
// "--help"
4040
// "run"
41-
"--format", "toml",
41+
// "--format",
42+
// "toml",
4243
"--no-color",
4344
"--no-pager",
4445
"--default-path",
@@ -48,7 +49,8 @@
4849
"all",
4950
"--norpa",
5051
// "--by-longname", "asd:dasd",
51-
// "--suite",
52+
"--suite",
53+
"Data.Tests.Versions.Rf61.a suite with a custom Name"
5254
// "Robotframework.Atest.Testdata.Variables",
5355
//"."
5456
]

Diff for: packages/plugin/src/robotcode/plugin/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def verbose(
7373
message: Union[str, Callable[[], Any], None],
7474
file: Optional[IO[AnyStr]] = None,
7575
nl: bool = True,
76-
err: bool = False,
76+
err: bool = True,
7777
) -> None:
7878
if self.config.verbose:
7979
click.secho(

Diff for: packages/runner/src/robotcode/runner/cli/discover/discover.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
from dataclasses import dataclass
55
from pathlib import Path
6-
from typing import Any, Dict, Iterable, List, Optional, Tuple
6+
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
77

88
import click
99
import robot.running.model as running_model
@@ -14,6 +14,7 @@
1414
from robot.output import LOGGER, Message
1515
from robot.running.builder import TestSuiteBuilder
1616
from robot.running.builder.builders import SuiteStructureParser
17+
from robotcode.core.dataclasses import from_json
1718
from robotcode.core.lsp.types import Diagnostic, DiagnosticSeverity, DocumentUri, Position, Range
1819
from robotcode.core.uri import Uri
1920
from robotcode.plugin import Application, OutputFormat, UnknownError, pass_application
@@ -31,13 +32,18 @@ def __init__(self, *args: Any, error_message: str, **kwargs: Any) -> None:
3132
__patched = False
3233

3334

35+
_stdin_data: Optional[Dict[str, str]] = None
36+
37+
3438
def _patch() -> None:
3539
global __patched
3640
if __patched:
3741
return
3842
__patched = True
3943

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

7682
SuiteStructureParser._build_suite = build_suite
7783

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

82100
old_validate_not_empty = TestSuiteBuilder._validate_not_empty
@@ -117,6 +135,17 @@ def build_suite_directory(
117135

118136
SuiteStructureParser._build_suite_directory = build_suite_directory
119137

138+
old_get_source = RobotParser._get_source
139+
140+
def _get_source(self: RobotParser, path: Path) -> Union[Path, str]:
141+
if _stdin_data is not None and (data := _stdin_data.get(str(path))) is not None:
142+
if data is not None:
143+
return data
144+
145+
return old_get_source(self, path) # type: ignore
146+
147+
RobotParser._get_source = _get_source
148+
120149

121150
@dataclass
122151
class TestItem:
@@ -217,8 +246,9 @@ def visit_test(self, test: TestCase) -> None:
217246

218247

219248
@click.group(invoke_without_command=False)
249+
@click.option("--read-from-stdin", is_flag=True, help="Read file contents from stdin. This is an internal option.")
220250
@pass_application
221-
def discover(app: Application) -> None:
251+
def discover(app: Application, read_from_stdin: bool) -> None:
222252
"""\
223253
Commands to discover informations about the current project.
224254
@@ -229,6 +259,10 @@ def discover(app: Application) -> None:
229259
robotcode --profile regression discover tests
230260
```
231261
"""
262+
if read_from_stdin:
263+
global _stdin_data
264+
_stdin_data = from_json(sys.stdin.buffer.read(), Dict[str, str], strict=True)
265+
app.verbose(f"Read data from stdin: {repr(_stdin_data)}")
232266

233267

234268
RE_IN_FILE_LINE_MATCHER = re.compile(r".+\sin\sfile\s'(?P<file>.*)'\son\sline\s(?P<line>\d+):(?P<message>.*)")

Diff for: tests/robotcode/language_server/robotframework/parts/data/robot.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ default-profiles = ["devel"]
22
paths = ["."]
33
python-path = ["./lib", "./resources"]
44
output-dir = { expr = "f'results/run-{datetime.now().strftime(\"%d-%m-%Y-%H.%M.%S\")}'" }
5-
rpa = false
65

6+
7+
rpa = false
78
# [parsers]
89
# myparser = ["asd"]
910

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*** Settings ***
2+
# Name Test Suite for 61

Diff for: vscode-client/pythonmanger.ts

+11
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ export class PythonManager {
181181
public async executeRobotCode(
182182
folder: vscode.WorkspaceFolder,
183183
args: string[],
184+
stdioData?: string,
184185
token?: vscode.CancellationToken
185186
): Promise<unknown> {
187+
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
188+
const robotCodeExtraArgs = config.get<string[]>("extraArgs", []);
189+
186190
const pythonCommand = this.getPythonCommand(folder);
187191
if (pythonCommand === undefined) throw new Error("Can't find python executable.");
188192

@@ -191,6 +195,7 @@ export class PythonManager {
191195
"-X",
192196
"utf8",
193197
this.robotCodeMain,
198+
...robotCodeExtraArgs,
194199
"--format",
195200
"json",
196201
"--no-color",
@@ -220,12 +225,18 @@ export class PythonManager {
220225

221226
process.stdout.setEncoding("utf8");
222227
process.stderr.setEncoding("utf8");
228+
if (stdioData !== undefined) {
229+
process.stdin.cork();
230+
process.stdin.write(stdioData, "utf8");
231+
process.stdin.end();
232+
}
223233

224234
process.stdout.on("data", (data) => {
225235
stdout += data;
226236
});
227237

228238
process.stderr.on("data", (data) => {
239+
this.outputChannel.append(data as string);
229240
stderr += data;
230241
});
231242

Diff for: vscode-client/testcontrollermanager.ts

+30-2
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ export class TestControllerManager {
511511
folder: vscode.WorkspaceFolder,
512512
discoverArgs: string[],
513513
extraArgs: string[],
514+
stdioData?: string,
514515
token?: vscode.CancellationToken
515516
): Promise<RobotCodeDiscoverResult> {
516517
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
@@ -544,6 +545,7 @@ export class TestControllerManager {
544545
...robotArgs,
545546
...extraArgs,
546547
],
548+
stdioData,
547549
token
548550
)) as RobotCodeDiscoverResult;
549551
}
@@ -553,7 +555,24 @@ export class TestControllerManager {
553555
token?: vscode.CancellationToken
554556
): Promise<RobotTestItem[] | undefined> {
555557
try {
556-
const result = await this.discoverTests(folder, ["discover", "all"], [], token);
558+
const o: { [key: string]: string } = {};
559+
560+
for (const document of vscode.workspace.textDocuments) {
561+
if (
562+
SUPPORTED_LANGUAGES.includes(document.languageId) &&
563+
vscode.workspace.getWorkspaceFolder(document.uri) === folder
564+
) {
565+
o[document.fileName] = document.getText();
566+
}
567+
}
568+
569+
const result = await this.discoverTests(
570+
folder,
571+
["discover", "--read-from-stdin", "all"],
572+
[],
573+
JSON.stringify(o),
574+
token
575+
);
557576

558577
this.diagnosticCollection.forEach((uri, _diagnostics, collection) => {
559578
if (vscode.workspace.getWorkspaceFolder(uri) === folder) {
@@ -605,7 +624,16 @@ export class TestControllerManager {
605624
if (!folder) return undefined;
606625

607626
try {
608-
const result = await this.discoverTests(folder, ["discover", "tests"], ["--suite", testItem?.longname], token);
627+
const o: { [key: string]: string } = {};
628+
o[document.fileName] = document.getText();
629+
630+
const result = await this.discoverTests(
631+
folder,
632+
["discover", "--read-from-stdin", "tests"],
633+
["--suite", testItem?.longname],
634+
JSON.stringify(o),
635+
token
636+
);
609637

610638
return result?.items;
611639
} catch (e) {

0 commit comments

Comments
 (0)