Skip to content

Commit 9c6ea3d

Browse files
authored
feat: clear log on execution start (#1168)
1 parent 3471f30 commit 9c6ea3d

File tree

7 files changed

+43
-1
lines changed

7 files changed

+43
-1
lines changed

client/src/commands/run.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import {
1212
} from "vscode";
1313
import type { BaseLanguageClient } from "vscode-languageclient";
1414

15+
import { basename, extname } from "path";
16+
1517
import { showResult } from "../components/ResultPanel";
1618
import {
1719
appendExecutionLogFn,
1820
appendSessionLogFn,
21+
setFileName,
1922
} from "../components/logViewer";
2023
import { sasDiagnostic } from "../components/logViewer/sasDiagnostics";
2124
import { SASCodeDocument } from "../components/utils/SASCodeDocument";
@@ -112,6 +115,9 @@ async function runCode(selected?: boolean, uri?: Uri) {
112115
session.onExecutionLogFn = onExecutionLogFn;
113116
session.onSessionLogFn = appendSessionLogFn;
114117

118+
const fileName = basename(codeDoc.getUri(), extname(codeDoc.getUri()));
119+
setFileName(fileName);
120+
115121
await session.setup();
116122

117123
await window.withProgress(
@@ -222,6 +228,9 @@ async function _runTask(
222228
);
223229
session.onSessionLogFn = appendSessionLogFn;
224230

231+
const fileName = basename(codeDoc.getUri(), extname(codeDoc.getUri()));
232+
setFileName(fileName);
233+
225234
messageEmitter.fire(`${l10n.t("Connecting to SAS session...")}\r\n`);
226235
!cancelled && (await session.setup(true));
227236

client/src/components/logViewer/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { OnLogFn } from "../../connection";
1212
import { useLogStore, useRunStore } from "../../store";
1313
import { logSelectors, runSelectors } from "../../store/selectors";
1414
import {
15+
clearLogOnExecutionStart,
1516
showLogOnExecutionFinish,
1617
showLogOnExecutionStart,
1718
} from "../utils/settings";
@@ -20,6 +21,7 @@ const { setProducedExecutionLogOutput } = useLogStore.getState();
2021

2122
let outputChannel: OutputChannel;
2223
let data: string[] = [];
24+
let fileName = "";
2325

2426
export const legend = {
2527
tokenTypes: ["error", "warning", "note"],
@@ -66,9 +68,16 @@ export const appendLogToken = (type: string): void => {
6668
data.push(type);
6769
};
6870

71+
export const setFileName = (name: string) => {
72+
fileName = name;
73+
};
74+
6975
const appendLogLines: OnLogFn = (logs) => {
7076
if (!outputChannel) {
71-
outputChannel = window.createOutputChannel(l10n.t("SAS Log"), "sas-log");
77+
const name = clearLogOnExecutionStart()
78+
? l10n.t("SAS Log: {name}", { name: fileName })
79+
: l10n.t("SAS Log");
80+
outputChannel = window.createOutputChannel(name, "sas-log");
7281
}
7382
for (const line of logs) {
7483
appendLogToken(line.type);
@@ -100,6 +109,12 @@ useRunStore.subscribe(
100109
}
101110
} else if (isExecuting && !prevIsExecuting) {
102111
setProducedExecutionLogOutput(false);
112+
113+
if (clearLogOnExecutionStart() && outputChannel) {
114+
outputChannel.dispose();
115+
outputChannel = undefined;
116+
data = [];
117+
}
103118
}
104119
},
105120
);

client/src/components/utils/settings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export function showLogOnExecutionFinish(): boolean {
2626
return workspace.getConfiguration("SAS").get("log.showOnExecutionFinish");
2727
}
2828

29+
export function clearLogOnExecutionStart(): boolean {
30+
return workspace.getConfiguration("SAS").get("log.clearOnExecutionStart");
31+
}
32+
2933
export function isShowProblemsFromSASLogEnabled(): boolean {
3034
return workspace.getConfiguration("SAS").get("problems.log.enabled");
3135
}

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,12 @@
474474
"type": "boolean",
475475
"default": true,
476476
"description": "%configuration.SAS.log.showOnExecutionFinish%"
477+
},
478+
"SAS.log.clearOnExecutionStart": {
479+
"order": 9,
480+
"type": "boolean",
481+
"default": true,
482+
"description": "%configuration.SAS.log.clearOnExecutionStart%"
477483
}
478484
}
479485
}

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"configuration.SAS.flowConversionMode": "Choose the conversion mode for notebooks",
5555
"configuration.SAS.flowConversionModeNode": "Convert each notebook cell to a node",
5656
"configuration.SAS.flowConversionModeSwimlane": "Convert each notebook cell to a swimlane",
57+
"configuration.SAS.log.clearOnExecutionStart": "Clear SAS Log when code execution starts",
5758
"configuration.SAS.log.showOnExecutionFinish": "Show SAS Log when code execution is finished",
5859
"configuration.SAS.log.showOnExecutionStart": "Show SAS Log when code execution starts",
5960
"configuration.SAS.problems.log.enabled": "Show problems from SAS log",

package.nls.zh-cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"configuration.SAS.flowConversionMode": "选择笔记本的转换模式",
5555
"configuration.SAS.flowConversionModeNode": "将每个笔记本单元转换为一个节点",
5656
"configuration.SAS.flowConversionModeSwimlane": "将每个笔记本单元转换为泳道",
57+
"configuration.SAS.log.clearOnExecutionStart": "代码执行开始时清空 SAS 日志",
5758
"configuration.SAS.log.showOnExecutionFinish": "代码执行完成时显示 SAS 日志",
5859
"configuration.SAS.log.showOnExecutionStart": "代码执行开始时显示 SAS 日志",
5960
"configuration.SAS.problems.log.enabled": "显示SAS日志中报告的问题",

website/docs/Configurations/sasLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ Example
3737
}
3838
}
3939
```
40+
41+
:::tip
42+
43+
To view the SAS log as a text file, click the `...` icon on the top right of the OUTPUT panel, and select `Open Output in Editor`.
44+
45+
:::

0 commit comments

Comments
 (0)