Skip to content

Commit fd2e3e7

Browse files
committed
optimize starting of tests
1 parent fedade1 commit fd2e3e7

File tree

4 files changed

+75
-44
lines changed

4 files changed

+75
-44
lines changed

robotcode/language_server/robotframework/parts/discovering.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
class GetAllTestsParams(Model):
2929
workspace_folder: str
3030
paths: Optional[List[str]]
31+
suites: Optional[List[str]] = None
3132

3233

3334
@dataclass(repr=False)
@@ -97,7 +98,9 @@ class DiscoveringProtocolPart(RobotLanguageServerProtocolPart):
9798
def __init__(self, parent: RobotLanguageServerProtocol) -> None:
9899
super().__init__(parent)
99100

100-
def _get_tests_from_workspace(self, workspace_folder: Path, paths: Optional[List[str]]) -> List[TestItem]:
101+
def _get_tests_from_workspace(
102+
self, workspace_folder: Path, paths: Optional[List[str]], suites: Optional[List[str]]
103+
) -> List[TestItem]:
101104
from robot.output.logger import LOGGER
102105
from robot.running import TestCase, TestSuite
103106

@@ -166,7 +169,11 @@ def nonexisting_paths(paths: List[str]) -> Iterator[str]:
166169
yield str(p)
167170

168171
valid_paths = [i for i in normalize_paths(paths)]
169-
suite: Optional[TestSuite] = TestSuite.from_file_system(*valid_paths) if valid_paths else None
172+
suite: Optional[TestSuite] = (
173+
TestSuite.from_file_system(*valid_paths, included_suites=suites if suites else None)
174+
if valid_paths
175+
else None
176+
)
170177
suite_item = [generate(suite)] if suite else []
171178

172179
return [
@@ -201,10 +208,11 @@ async def get_tests_from_workspace(
201208
self,
202209
workspace_folder: str,
203210
paths: Optional[List[str]],
211+
suites: Optional[List[str]],
204212
*args: Any,
205213
**kwargs: Any,
206214
) -> List[TestItem]:
207-
return await run_in_thread(self._get_tests_from_workspace, Uri(workspace_folder).to_path(), paths)
215+
return await run_in_thread(self._get_tests_from_workspace, Uri(workspace_folder).to_path(), paths, suites)
208216

209217
@rpc_method(name="robot/discovering/getTestsFromDocument", param_type=GetTestsParams)
210218
@_logger.call

vscode-client/debugmanager.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class RobotCodeDebugConfigurationProvider implements vscode.DebugConfigurationPr
4040
if (!debugConfiguration.python) debugConfiguration.python = this.pythonManager.getPythonCommand(folder);
4141

4242
debugConfiguration.robotPythonPath = [
43-
...config.get<Array<string>>("robot.pythonPath", []),
43+
...config.get<string[]>("robot.pythonPath", []),
4444
...(debugConfiguration.robotPythonPath ?? []),
4545
];
4646

47-
debugConfiguration.args = [...config.get<Array<string>>("robot.args", []), ...(debugConfiguration.args ?? [])];
47+
debugConfiguration.args = [...config.get<string[]>("robot.args", []), ...(debugConfiguration.args ?? [])];
4848

4949
debugConfiguration.variables = {
5050
...config.get<{ [Key: string]: unknown }>("robot.variables", {}),
@@ -112,9 +112,9 @@ class RobotCodeDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescr
112112
throw new Error("Can't get a valid python command.");
113113
}
114114

115-
const debugAdapterArgs = config.get<Array<string>>("debugAdapter.args", []);
115+
const debugAdapterArgs = config.get<string[]>("debugAdapter.args", []);
116116

117-
const args: Array<string> = ["-u", this.pythonManager.pythonDebugAdapterMain, "--mode", "stdio"].concat(
117+
const args: string[] = ["-u", this.pythonManager.pythonDebugAdapterMain, "--mode", "stdio"].concat(
118118
debugAdapterArgs
119119
);
120120

@@ -270,44 +270,51 @@ export class DebugManager {
270270

271271
static async runTests(
272272
folder: vscode.WorkspaceFolder,
273+
suites: string[],
273274
included: string[],
274275
excluded: string[],
275276
runId?: string,
276277
options?: vscode.DebugSessionOptions
277278
): Promise<void> {
278-
if (included.length) {
279-
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
279+
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, folder);
280+
281+
const args = [];
282+
283+
for (const s of suites) {
284+
args.push("--suite");
285+
args.push(s);
286+
}
280287

281-
const args = [];
288+
if (included.length > 0) {
282289
args.push("--prerunmodifier");
283290

284291
args.push(`robotcode.debugger.modifiers.ByLongName:${included.join(":")}`);
292+
}
285293

286-
if (excluded.length > 0) {
287-
args.push("--prerunmodifier");
294+
if (excluded.length > 0) {
295+
args.push("--prerunmodifier");
288296

289-
args.push(`robotcode.debugger.modifiers.ExcludedByLongName:${excluded.join(":")}`);
290-
}
291-
const template = config.get("debug.defaultConfiguration", {});
297+
args.push(`robotcode.debugger.modifiers.ExcludedByLongName:${excluded.join(":")}`);
298+
}
299+
const template = config.get("debug.defaultConfiguration", {});
292300

293-
await vscode.debug.startDebugging(
294-
folder,
295-
{
296-
...template,
297-
...{
298-
type: "robotcode",
299-
name: "robotcode: Run Tests",
300-
request: "launch",
301-
cwd: folder?.uri.fsPath,
302-
target: ".",
303-
args: args,
304-
console: config.get("debug.defaultConsole", "integratedTerminal"),
305-
runId: runId,
306-
},
301+
await vscode.debug.startDebugging(
302+
folder,
303+
{
304+
...template,
305+
...{
306+
type: "robotcode",
307+
name: "robotcode: Run Tests",
308+
request: "launch",
309+
cwd: folder?.uri.fsPath,
310+
target: ".",
311+
args: args,
312+
console: config.get("debug.defaultConsole", "integratedTerminal"),
313+
runId: runId,
307314
},
308-
options
309-
);
310-
}
315+
},
316+
options
317+
);
311318
}
312319

313320
static async OnDebugpyStarted(

vscode-client/languageclientsmanger.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ export class LanguageClientsManager {
179179
throw new Error("Can't find a valid python executable.");
180180
}
181181

182-
const serverArgs = config.get<Array<string>>("languageServer.args", []);
182+
const serverArgs = config.get<string[]>("languageServer.args", []);
183183

184-
const args: Array<string> = [
184+
const args: string[] = [
185185
"-u",
186186

187187
// "-m",
@@ -193,7 +193,7 @@ export class LanguageClientsManager {
193193
this.pythonManager.pythonLanguageServerMain,
194194
];
195195

196-
const debug_args: Array<string> = ["--log"];
196+
const debug_args: string[] = ["--log"];
197197

198198
const transport = { stdio: TransportKind.stdio, pipe: TransportKind.pipe, socket: TransportKind.socket }[mode];
199199

@@ -405,7 +405,8 @@ export class LanguageClientsManager {
405405

406406
public async getTestsFromWorkspace(
407407
workspaceFolder: vscode.WorkspaceFolder,
408-
paths?: Array<string>,
408+
paths?: string[],
409+
suites?: string[],
409410
token?: vscode.CancellationToken
410411
): Promise<RobotTestItem[] | undefined> {
411412
const client = await this.getLanguageClientForResource(workspaceFolder.uri);
@@ -419,6 +420,7 @@ export class LanguageClientsManager {
419420
{
420421
workspaceFolder: workspaceFolder.uri.toString(),
421422
paths: paths ?? ["."],
423+
suites,
422424
},
423425
token
424426
)

vscode-client/testcontrollermanager.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export class TestControllerManager {
332332
if (!this.robotTestItems.has(workspace) && this.robotTestItems.get(workspace) === undefined) {
333333
this.robotTestItems.set(
334334
workspace,
335-
await this.languageClientsManager.getTestsFromWorkspace(workspace, [], token)
335+
await this.languageClientsManager.getTestsFromWorkspace(workspace, [], undefined, token)
336336
);
337337
}
338338

@@ -550,13 +550,27 @@ export class TestControllerManager {
550550
};
551551
}
552552

553-
await DebugManager.runTests(
554-
workspace,
555-
id.map((i) => i.id),
556-
excluded.get(workspace)?.map((i) => i.id) ?? [],
557-
runId,
558-
options
559-
);
553+
const workspaceItem = this.findTestItemByUri(workspace.uri.toString());
554+
555+
if (includedItems.length === 1 && includedItems[0] === workspaceItem && excluded.size === 0) {
556+
await DebugManager.runTests(workspace, [], [], [], runId, options);
557+
} else {
558+
const includedInWs = id.map((i) => i.id);
559+
const excludedInWs = excluded.get(workspace)?.map((i) => i.id) ?? [];
560+
const suites = new Set<string>();
561+
562+
for (const t of [...includedInWs, ...excludedInWs]) {
563+
const testItem = this.findTestItemById(t);
564+
if (!testItem?.canResolveChildren) {
565+
if (testItem?.parent) {
566+
suites.add(testItem.parent.id);
567+
}
568+
} else {
569+
suites.add(t);
570+
}
571+
}
572+
await DebugManager.runTests(workspace, Array.from(suites), includedInWs, excludedInWs, runId, options);
573+
}
560574
}
561575
}
562576

0 commit comments

Comments
 (0)