Skip to content

Commit fcb32a7

Browse files
committed
feat(vscode): show profiles from robot.toml in test explorer as test profile
1 parent c3d8b07 commit fcb32a7

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

vscode-client/testcontrollermanager.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
SUPPORTED_LANGUAGES,
1313
SUPPORTED_SUITE_FILE_EXTENSIONS,
1414
} from "./languageclientsmanger";
15-
import { filterAsync, Mutex, sleep, WeakValueMap } from "./utils";
15+
import { filterAsync, Mutex, sleep, truncateAndReplaceNewlines, WeakValueMap } from "./utils";
1616
import { CONFIG_SECTION } from "./config";
1717
import { Range, Diagnostic, DiagnosticSeverity } from "vscode-languageclient/node";
1818

@@ -189,6 +189,10 @@ export class TestControllerManager {
189189
break;
190190
}
191191
}
192+
this.updateRunProfiles().then(
193+
(_) => undefined,
194+
(_) => undefined,
195+
);
192196
}),
193197
vscode.workspace.onDidCloseTextDocument((document) => this.refreshDocument(document)),
194198
vscode.workspace.onDidSaveTextDocument((document) => this.refreshDocument(document)),
@@ -281,7 +285,7 @@ export class TestControllerManager {
281285
}
282286

283287
private async updateRunProfiles(): Promise<void> {
284-
await this.runProfilesMutex.dispatch(() => {
288+
await this.runProfilesMutex.dispatch(async () => {
285289
for (const a of this.runProfiles) {
286290
a.dispose();
287291
}
@@ -292,7 +296,7 @@ export class TestControllerManager {
292296
for (const folder of vscode.workspace.workspaceFolders ?? []) {
293297
const folderTag = this.getFolderTag(folder);
294298

295-
const folderName = multiFolders ? ` (${folder.name})` : "";
299+
const folderName = multiFolders ? ` [${folder.name}]` : "";
296300

297301
const runProfile = this.testController.createRunProfile(
298302
"Run" + folderName,
@@ -334,7 +338,9 @@ export class TestControllerManager {
334338

335339
configurations?.forEach((config, index) => {
336340
if (config.type === "robotcode" && config.purpose == "test-profile") {
337-
const name = ((config.name || `Profile ${index}`) as string) + folderName;
341+
const name =
342+
(config.name ? truncateAndReplaceNewlines((config.name as string).trim()) : `Profile ${index}`) +
343+
folderName;
338344

339345
const runProfile = this.testController.createRunProfile(
340346
"Run " + name,
@@ -357,6 +363,35 @@ export class TestControllerManager {
357363
this.runProfiles.push(debugProfile);
358364
}
359365
});
366+
367+
const profiles = await this.getRobotCodeProfiles(folder);
368+
369+
profiles.profiles.forEach((profile, index) => {
370+
const name =
371+
(truncateAndReplaceNewlines(profile.name.trim()) || `Profile ${index}`) +
372+
(profile.description ? ` - ${truncateAndReplaceNewlines(profile.description.trim())} ` : "") +
373+
folderName;
374+
375+
const runProfile = this.testController.createRunProfile(
376+
"Run " + name,
377+
vscode.TestRunProfileKind.Run,
378+
async (request, token) => this.runTests(request, token, [profile.name]),
379+
false,
380+
folderTag,
381+
);
382+
383+
this.runProfiles.push(runProfile);
384+
385+
const debugProfile = this.testController.createRunProfile(
386+
"Debug " + name,
387+
vscode.TestRunProfileKind.Debug,
388+
async (request, token) => this.runTests(request, token, [profile.name]),
389+
false,
390+
folderTag,
391+
);
392+
393+
this.runProfiles.push(debugProfile);
394+
});
360395
}
361396
});
362397
}

vscode-client/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,14 @@ export async function filterAsync<T>(arr: readonly T[], predicate: (value: T) =>
213213
[],
214214
);
215215
}
216+
217+
export function truncateAndReplaceNewlines(str: string, maxLength: number = 50): string {
218+
// Ersetzt alle Zeilenumbrüche durch Leerzeichen
219+
const processedString = str.replace(/\r\n|\n|\r/g, " ");
220+
221+
// Kürzt den String, falls er länger als maxLength ist
222+
if (processedString.length > maxLength) {
223+
return processedString.substring(0, maxLength - 3) + "...";
224+
}
225+
return processedString;
226+
}

0 commit comments

Comments
 (0)