Skip to content

Commit f471f6a

Browse files
committed
Rename setting openReportAfterRun to openOutputAfterRun and make it possible to specify it in launch config
1 parent 8923892 commit f471f6a

File tree

3 files changed

+90
-22
lines changed

3 files changed

+90
-22
lines changed

package.json

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,22 @@
370370
"default": "default",
371371
"scope": "resource"
372372
},
373+
"robotcode.run.openOutputAfterRun": {
374+
"type": "string",
375+
"enum": [
376+
"none",
377+
"report",
378+
"log"
379+
],
380+
"enumDescriptions": [
381+
"Do not open anyting",
382+
"Open the report html file.",
383+
"Open the log.html file."
384+
],
385+
"default": "none",
386+
"description": "Defines if the report or log file should be opened after a run.",
387+
"scope": "resource"
388+
},
373389
"robotcode.debug.defaultConfiguration": {
374390
"type": "object",
375391
"default": {},
@@ -425,13 +441,7 @@
425441
"robotcode.syntax.sectionStyle": {
426442
"type": "string",
427443
"default": null,
428-
"description": "Defines the section style format. If not defined ```*** section ***``` is used.",
429-
"scope": "resource"
430-
},
431-
"robotcode.run.openReportAfterRun": {
432-
"type": "boolean",
433-
"default": false,
434-
"description": "Defines if the report should be opened after a run.",
444+
"markdownDescription": "Defines the section style format. If not defined ```*** section ***``` is used.",
435445
"scope": "resource"
436446
},
437447
"robotcode.robocop.enabled": {
@@ -764,6 +774,21 @@
764774
"Use this configuration when running or debugging tests."
765775
]
766776
}
777+
},
778+
"openOutputAfterRun": {
779+
"type": "string",
780+
"enum": [
781+
"none",
782+
"report",
783+
"log"
784+
],
785+
"enumDescriptions": [
786+
"Do not open anyting",
787+
"Open the report html file.",
788+
"Open the log.html file."
789+
],
790+
"default": "none",
791+
"description": "Defines if the report or log file should be opened after a run."
767792
}
768793
}
769794
}

vscode-client/debugmanager.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@ import { CONFIG_SECTION } from "./config";
88
import { LanguageClientsManager, toVsCodeRange } from "./languageclientsmanger";
99
import { WeakValueSet } from "./utils";
1010

11+
async function openPreviewOrExternal(uri: vscode.Uri) {
12+
let livePreviewResult = false;
13+
try {
14+
const ex = vscode.extensions.getExtension("ms-vscode.live-server");
15+
if (ex) {
16+
await ex.activate();
17+
if ((await vscode.commands.getCommands()).includes("livePreview.start.preview.atFile")) {
18+
await vscode.commands.executeCommand("livePreview.start.preview.atFile", uri);
19+
livePreviewResult = true;
20+
}
21+
}
22+
} catch {
23+
livePreviewResult = false;
24+
}
25+
26+
if (!livePreviewResult) {
27+
vscode.env.openExternal(uri).then(
28+
() => undefined,
29+
() => undefined
30+
);
31+
}
32+
}
33+
1134
const DEBUG_ADAPTER_DEFAULT_TCP_PORT = 6611;
1235
const DEBUG_ADAPTER_DEFAULT_HOST = "127.0.0.1";
1336

@@ -85,8 +108,6 @@ class RobotCodeDebugConfigurationProvider implements vscode.DebugConfigurationPr
85108
(v?.purpose === "default" || (Array.isArray(v?.purpose) && v?.purpose?.indexOf("default") > -1))
86109
) ?? {};
87110

88-
console.log(defaultLaunchConfig);
89-
90111
debugConfiguration = { ...template, ...defaultLaunchConfig, ...debugConfiguration };
91112

92113
try {
@@ -125,6 +146,9 @@ class RobotCodeDebugConfigurationProvider implements vscode.DebugConfigurationPr
125146
...(debugConfiguration.env ?? {}),
126147
};
127148

149+
debugConfiguration.openOutputAfterRun =
150+
debugConfiguration?.openOutputAfterRun ?? config.get<string | undefined>("run.openOutputAfterRun", undefined);
151+
128152
debugConfiguration.outputDir =
129153
debugConfiguration?.outputDir ?? config.get<string | undefined>("robot.outputDir", undefined);
130154

@@ -425,15 +449,13 @@ export class DebugManager {
425449
private static async OnRobotExited(
426450
session: vscode.DebugSession,
427451
_outputFile?: string,
428-
_logFile?: string,
452+
logFile?: string,
429453
reportFile?: string
430454
): Promise<void> {
431-
if (reportFile) {
432-
const config = vscode.workspace.getConfiguration(CONFIG_SECTION, session.workspaceFolder);
433-
434-
if (config.get<boolean>("run.openReportAfterRun")) {
435-
await vscode.env.openExternal(vscode.Uri.file(reportFile));
436-
}
455+
if (session.configuration?.openOutputAfterRun === "report" && reportFile) {
456+
await openPreviewOrExternal(vscode.Uri.file(reportFile));
457+
} else if (session.configuration?.openOutputAfterRun === "log" && logFile) {
458+
await openPreviewOrExternal(vscode.Uri.file(logFile));
437459
}
438460
}
439461
}

vscode-client/extension.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ export async function activateAsync(context: vscode.ExtensionContext): Promise<v
3030
languageClientManger,
3131
debugManager,
3232
testControllerManger,
33-
33+
vscode.commands.registerCommand("robotcode.showDocumentation", async (url: string) => {
34+
await vscode.commands.executeCommand("simpleBrowser.api.open", url, {
35+
preserveFocus: true,
36+
viewColumn: vscode.ViewColumn.Beside,
37+
});
38+
}),
3439
vscode.window.registerTerminalLinkProvider({
3540
provideTerminalLinks(terminalContext: vscode.TerminalLinkContext, _token: vscode.CancellationToken) {
3641
const line = terminalContext.line.trimEnd();
@@ -52,11 +57,27 @@ export async function activateAsync(context: vscode.ExtensionContext): Promise<v
5257

5358
return [];
5459
},
55-
handleTerminalLink(link: TerminalLink) {
56-
vscode.env.openExternal(vscode.Uri.file(link.path)).then(
57-
() => undefined,
58-
() => undefined
59-
);
60+
async handleTerminalLink(link: TerminalLink) {
61+
let livePreviewResult = false;
62+
try {
63+
const ex = vscode.extensions.getExtension("ms-vscode.live-server");
64+
if (ex) {
65+
await ex.activate();
66+
if ((await vscode.commands.getCommands()).includes("livePreview.start.preview.atFile")) {
67+
await vscode.commands.executeCommand("livePreview.start.preview.atFile", vscode.Uri.file(link.path));
68+
livePreviewResult = true;
69+
}
70+
}
71+
} catch {
72+
livePreviewResult = false;
73+
}
74+
75+
if (!livePreviewResult) {
76+
vscode.env.openExternal(vscode.Uri.file(link.path)).then(
77+
() => undefined,
78+
() => undefined
79+
);
80+
}
6081
},
6182
})
6283
);

0 commit comments

Comments
 (0)