Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.

Commit a9e96cd

Browse files
committed
chore(log): add log manager for tracing purposes
1 parent 74212e2 commit a9e96cd

File tree

5 files changed

+128
-61
lines changed

5 files changed

+128
-61
lines changed

.vscode/launch.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
{
66
"version": "0.2.0",
77
"configurations": [
8+
{
9+
"args": [
10+
"--extensionDevelopmentPath=${workspaceFolder}"
11+
],
12+
"name": "Launch Extension VSCE",
13+
"outFiles": [
14+
"${workspaceFolder}/out/**/*.js"
15+
],
16+
"preLaunchTask": "npm: compile",
17+
"request": "launch",
18+
"type": "extensionHost"
19+
},
820
{
921
"args": [
1022
"--extensionDevelopmentPath=${workspaceFolder}"

.vscode/tasks.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
"npm: watch-tests"
3636
],
3737
"problemMatcher": []
38+
},
39+
{
40+
"type": "npm",
41+
"script": "compile",
42+
"group": "build",
43+
"problemMatcher": [],
44+
"label": "npm: compile",
45+
"detail": "webpack --config ./build/node-extension.webpack.config.js"
3846
}
3947
]
4048
}

src/commands/handlers.ts

Lines changed: 77 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
import * as vscode from "vscode";
2-
import { RuleOverview } from "../panels/RuleOverviewPanel";
3-
import { SelectFlows } from "../libs/SelectFlows";
4-
import { SaveFlow } from "../libs/SaveFlow";
5-
import { ScanOverview } from "../panels/ScanOverviewPanel";
6-
import * as core from "lightning-flow-scanner-core";
7-
import { findFlowCoverage } from "../libs/FindFlowCoverage";
8-
import { CacheProvider } from "../providers/cache-provider";
9-
import { testdata } from "../store/testdata";
1+
import * as vscode from 'vscode';
2+
import { RuleOverview } from '../panels/RuleOverviewPanel';
3+
import { SelectFlows } from '../libs/SelectFlows';
4+
import { SaveFlow } from '../libs/SaveFlow';
5+
import { ScanOverview } from '../panels/ScanOverviewPanel';
6+
import * as core from 'lightning-flow-scanner-core';
7+
import { findFlowCoverage } from '../libs/FindFlowCoverage';
8+
import { CacheProvider } from '../providers/cache-provider';
9+
import { testdata } from '../store/testdata';
10+
import { OutputChannel } from '../providers/outputChannel';
1011

1112
export default class Commands {
1213
constructor(private context: vscode.ExtensionContext) {}
1314

1415
get handlers() {
1516
/* eslint-disable @typescript-eslint/naming-convention */
1617
return Object.entries({
17-
"lightningflowscanner.viewDefaulFlowRules": () =>
18+
'lightningflowscanner.viewDefaulFlowRules': () =>
1819
this.viewDefaulFlowRules(),
19-
"lightningflowscanner.configRules": () => this.configRules(),
20-
"lightningflowscanner.debugView": () => this.debugView(),
21-
"lightningflowscanner.scanFlows": () => this.scanFlows(),
22-
"lightningflowscanner.fixFlows": () => this.fixFlows(),
23-
"lightningflowscanner.calculateFlowTestCoverage": () =>
20+
'lightningflowscanner.configRules': () => this.configRules(),
21+
'lightningflowscanner.debugView': () => this.debugView(),
22+
'lightningflowscanner.scanFlows': () => this.scanFlows(),
23+
'lightningflowscanner.fixFlows': () => this.fixFlows(),
24+
'lightningflowscanner.calculateFlowTestCoverage': () =>
2425
this.calculateFlowTestCoverage(),
2526
});
2627
}
@@ -37,7 +38,7 @@ export default class Commands {
3738
return { label: rule.label, value: rule.name };
3839
});
3940
items.forEach((item) => {
40-
item["picked"] = true;
41+
item['picked'] = true;
4142
});
4243

4344
const selectedRules = await vscode.window.showQuickPick(items, {
@@ -46,76 +47,76 @@ export default class Commands {
4647

4748
for (const rule of allRules) {
4849
if (selectedRules.map((r) => r.value).includes(rule.name)) {
49-
ruleConfig.rules[rule.name] = { severity: "error" };
50+
ruleConfig.rules[rule.name] = { severity: 'error' };
5051
}
5152
}
52-
if (selectedRules.map((r) => r.value).includes("FlowName")) {
53+
if (selectedRules.map((r) => r.value).includes('FlowName')) {
5354
const namingConventionString = await vscode.window.showInputBox({
5455
prompt:
55-
"Readability of a flow is very important. Setting a naming convention for the Flow Name will improve the findability/searchability and overall consistency. You can define your default naming convention using REGEX.",
56-
placeHolder: "[A-Za-z0-9]+_[A-Za-z0-9]+",
57-
value: "[A-Za-z0-9]+_[A-Za-z0-9]+",
56+
'Readability of a flow is very important. Setting a naming convention for the Flow Name will improve the findability/searchability and overall consistency. You can define your default naming convention using REGEX.',
57+
placeHolder: '[A-Za-z0-9]+_[A-Za-z0-9]+',
58+
value: '[A-Za-z0-9]+_[A-Za-z0-9]+',
5859
});
59-
ruleConfig.rules["FlowName"] = {
60-
severity: "error",
60+
ruleConfig.rules['FlowName'] = {
61+
severity: 'error',
6162
expression: namingConventionString,
6263
};
6364
await vscode.workspace
6465
.getConfiguration()
6566
.update(
66-
"lightningFlowScanner.NamingConvention",
67+
'lightningFlowScanner.NamingConvention',
6768
namingConventionString,
6869
true
6970
);
7071
}
71-
if (selectedRules.map((r) => r.value).includes("APIVersion")) {
72+
if (selectedRules.map((r) => r.value).includes('APIVersion')) {
7273
const apiVersionEvalExpressionString = await vscode.window.showInputBox({
7374
prompt:
74-
" The Api Version has been available as an attribute on the Flow since API v50.0 and it is recommended to limit variation and to update them on a regular basis. Set an expression to set a valid range of API versions(Minimum 50).",
75-
placeHolder: ">50",
76-
value: ">50",
75+
' The Api Version has been available as an attribute on the Flow since API v50.0 and it is recommended to limit variation and to update them on a regular basis. Set an expression to set a valid range of API versions(Minimum 50).',
76+
placeHolder: '>50',
77+
value: '>50',
7778
});
78-
ruleConfig.rules["APIVersion"] = {
79-
severity: "error",
79+
ruleConfig.rules['APIVersion'] = {
80+
severity: 'error',
8081
expression: apiVersionEvalExpressionString,
8182
};
8283
await vscode.workspace
8384
.getConfiguration()
8485
.update(
85-
"lightningFlowScanner.APIVersion",
86+
'lightningFlowScanner.APIVersion',
8687
apiVersionEvalExpressionString,
8788
true
8889
);
8990
}
90-
await CacheProvider.instance.set("ruleconfig", ruleConfig);
91+
await CacheProvider.instance.set('ruleconfig', ruleConfig);
9192
}
9293

9394
private async debugView() {
9495
let results = testdata as unknown as core.ScanResult[];
95-
await CacheProvider.instance.set("results", results);
96+
await CacheProvider.instance.set('results', results);
9697
ScanOverview.createOrShow(this.context.extensionUri, results);
9798
await vscode.commands.executeCommand(
98-
"workbench.action.webview.openDeveloperTools"
99+
'workbench.action.webview.openDeveloperTools'
99100
);
100101
}
101102

102103
private async calculateFlowTestCoverage() {
103-
const results = CacheProvider.instance.get("results");
104+
const results = CacheProvider.instance.get('results');
104105
ScanOverview.createOrShow(this.context.extensionUri, []);
105106
if (results && results.length > 0) {
106107
const coverageMap = await findFlowCoverage(results);
107108
const newResults = [];
108109
for (let result of results) {
109110
let flowName = result.flow.name;
110111
const coverage = coverageMap.get(flowName);
111-
result["coverage"] = coverage;
112+
result['coverage'] = coverage;
112113
newResults.push(result);
113-
await CacheProvider.instance.set("results", newResults);
114+
await CacheProvider.instance.set('results', newResults);
114115
ScanOverview.createOrShow(this.context.extensionUri, newResults);
115116
}
116117
} else {
117118
vscode.window.showInformationMessage(
118-
"No results found. Please make sure to complete a scan before calculating coverage."
119+
'No results found. Please make sure to complete a scan before calculating coverage.'
119120
);
120121
}
121122
}
@@ -124,49 +125,78 @@ export default class Commands {
124125
const rootPath = vscode.workspace.workspaceFolders?.[0]?.uri;
125126
const selectedUris = await new SelectFlows(
126127
rootPath,
127-
"Select a root folder:"
128+
'Select a root folder:'
128129
).execute(rootPath);
130+
OutputChannel.getInstance().logChannel.debug(
131+
'Selected uris',
132+
...selectedUris
133+
);
129134
if (selectedUris.length > 0) {
130135
let results: core.ScanResult[] = [];
131136
const panel = ScanOverview.createOrShow(
132137
this.context.extensionUri,
133138
results
134139
);
140+
OutputChannel.getInstance().logChannel.trace('create panel');
135141
let configReset: vscode.WorkspaceConfiguration =
136142
vscode.workspace
137-
.getConfiguration("lightningFlowScanner")
138-
.get("Reset") ?? undefined;
143+
.getConfiguration('lightningFlowScanner')
144+
.get('Reset') ?? undefined;
145+
OutputChannel.getInstance().logChannel.trace(
146+
'load vscode stored configurations'
147+
);
139148
if (configReset) {
149+
OutputChannel.getInstance().logChannel.trace('reset configurations');
140150
await this.configRules();
141151
}
142-
const ruleConfig = CacheProvider.instance.get("ruleconfig");
152+
const ruleConfig = CacheProvider.instance.get('ruleconfig');
143153
results = core.scan(await core.parse(selectedUris), ruleConfig);
144-
await CacheProvider.instance.set("results", results);
154+
OutputChannel.getInstance().logChannel.debug('Scan Results', ...results);
155+
await CacheProvider.instance.set('results', results);
145156
ScanOverview.createOrShow(this.context.extensionUri, results);
146157
} else {
147-
vscode.window.showInformationMessage("No flow files found.");
158+
vscode.window.showInformationMessage('No flow files found.');
148159
}
149160
}
150161

151162
private async fixFlows() {
152-
const storedResults = CacheProvider.instance.get("results");
163+
const storedResults = CacheProvider.instance.get('results');
164+
OutputChannel.getInstance().logChannel.trace(
165+
'has scan results?',
166+
storedResults.length
167+
);
153168
if (storedResults && storedResults.length > 0) {
169+
OutputChannel.getInstance().logChannel.debug(
170+
'contains scan results',
171+
...storedResults
172+
);
154173
ScanOverview.createOrShow(this.context.extensionUri, []);
155174
const newResults: core.ScanResult[] = core.fix(storedResults);
175+
OutputChannel.getInstance().logChannel.debug(
176+
'invoked scanned results in total: ',
177+
newResults.length
178+
);
156179
for (const newResult of newResults) {
180+
OutputChannel.getInstance().logChannel.trace('Fixed File', newResult);
157181
const uri = vscode.Uri.file(newResult.flow.fsPath);
158182
await new SaveFlow().execute(newResult.flow, uri);
159183
}
160184
if (newResults && newResults.length > 0) {
161-
await CacheProvider.instance.set("results", newResults);
185+
OutputChannel.getInstance().logChannel.trace(
186+
'Has fixed results, storing inside cache'
187+
);
188+
await CacheProvider.instance.set('results', newResults);
162189
await ScanOverview.createOrShow(this.context.extensionUri, newResults);
163190
} else {
191+
OutputChannel.getInstance().logChannel.trace(
192+
'Nothing fixed, showing warning message'
193+
);
164194
await ScanOverview.createOrShow(
165195
this.context.extensionUri,
166196
storedResults
167197
);
168198
await vscode.window.showWarningMessage(
169-
"Fix Flows: UnusedVariable and UnconnectedElement rules are currently supported, stay tuned for more rules."
199+
'Fix Flows: UnusedVariable and UnconnectedElement rules are currently supported, stay tuned for more rules.'
170200
);
171201
}
172202
}

src/extension.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@ import * as vscode from 'vscode';
22
import { Sidebar } from './panels/SidebarPanel';
33
import Commands from './commands/handlers';
44
import { CacheProvider } from './providers/cache-provider';
5+
import { OutputChannel } from './providers/outputChannel';
56

67
export async function activate(context: vscode.ExtensionContext) {
8+
OutputChannel.getInstance().logChannel.debug('initialize');
79

8-
CacheProvider.init(context, {'results' : [], 'ruleconfig': {}});
10+
CacheProvider.init(context, { results: [], ruleconfig: {} });
911

10-
const sidebarPanel = new Sidebar(context.extensionUri);
11-
const commands = new Commands(context);
12-
context.subscriptions.push(
13-
vscode.window.registerWebviewViewProvider(
14-
'lfs-sb',
15-
sidebarPanel
16-
)
17-
);
18-
19-
commands.handlers.forEach(([cmd, fn]) =>
20-
context.subscriptions.push(vscode.commands.registerCommand(cmd, fn))
21-
);
12+
const sidebarPanel = new Sidebar(context.extensionUri);
13+
const commands = new Commands(context);
14+
context.subscriptions.push(
15+
vscode.window.registerWebviewViewProvider('lfs-sb', sidebarPanel)
16+
);
2217

18+
commands.handlers.forEach(([cmd, fn]) =>
19+
context.subscriptions.push(vscode.commands.registerCommand(cmd, fn))
20+
);
2321
}
2422

25-
export function deactivate() { }
23+
export function deactivate() {}

src/providers/outputChannel.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as vscode from 'vscode';
2+
3+
// Usage in the OutputChannel class
4+
export class OutputChannel {
5+
private static instance: OutputChannel;
6+
7+
private constructor(public logChannel: vscode.LogOutputChannel) {}
8+
9+
public static getInstance(): OutputChannel {
10+
if (!this.instance) {
11+
this.instance = new OutputChannel(
12+
vscode.window.createOutputChannel('Lightning Flow Scanner', {
13+
log: true,
14+
})
15+
);
16+
}
17+
return this.instance;
18+
}
19+
}

0 commit comments

Comments
 (0)