Skip to content

Commit ad0e371

Browse files
committed
Config for auto-refresh SELF view
Signed-off-by: worksofliam <[email protected]>
1 parent 5793d37 commit ad0e371

File tree

3 files changed

+41
-24
lines changed

3 files changed

+41
-24
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353
"title": "General",
5454
"order": 1,
5555
"properties": {
56+
"vscode-db2i.autoRefreshSelfCodesView": {
57+
"type": "boolean",
58+
"description": "Automatically refresh the SELF codes view every 5 seconds",
59+
"default": false
60+
},
5661
"vscode-db2i.pageSize": {
5762
"type": "number",
5863
"description": "Page size for Schema browser",

src/extension.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { SQLJobManager } from "./connection/manager";
1818
import { JDBCOptions } from "./connection/types";
1919
import { SQLJob } from "./connection/sqlJob";
2020
import { selfCodesResultsView } from "./views/jobManager/selfCodes/selfCodesResultsView";
21+
import Configuration from "./configuration";
2122

2223
export interface Db2i {
2324
sqlJobManager: SQLJobManager,
@@ -36,6 +37,7 @@ export function activate(context: vscode.ExtensionContext): Db2i {
3637
loadBase();
3738

3839
const exampleBrowser = new ExampleBrowser(context);
40+
const selfCodesView = new selfCodesResultsView(context);
3941

4042
context.subscriptions.push(
4143
...languageInit(),
@@ -58,7 +60,7 @@ export function activate(context: vscode.ExtensionContext): Db2i {
5860
),
5961
vscode.window.registerTreeDataProvider(
6062
'vscode-db2i.self.nodes',
61-
new selfCodesResultsView(context)
63+
selfCodesView
6264
)
6365
);
6466

@@ -81,6 +83,7 @@ export function activate(context: vscode.ExtensionContext): Db2i {
8183
determineFeatures();
8284
// Refresh the examples when we have it, so we only display certain examples
8385
exampleBrowser.refresh();
86+
selfCodesView.setRefreshEnabled(Configuration.get(`autoRefreshSelfCodesView`) || false)
8487
})
8588
});
8689

src/views/jobManager/selfCodes/selfCodesResultsView.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,10 @@ export class selfCodesResultsView implements TreeDataProvider<any> {
3636
}
3737
}),
3838
vscode.commands.registerCommand(`vscode-db2i.self.enableAutoRefresh`, async () => {
39-
this.autoRefresh = true;
40-
vscode.commands.executeCommand(`setContext`, `vscode-db2i.self.autoRefresh`, true);
41-
vscode.window.showInformationMessage("SELF Code Auto Refresh Enabled");
39+
this.setRefreshEnabled(true, true);
4240
}),
4341
vscode.commands.registerCommand(`vscode-db2i.self.disableAutoRefresh`, async () => {
44-
this.autoRefresh = false;
45-
vscode.commands.executeCommand(`setContext`, `vscode-db2i.self.autoRefresh`, false);
46-
vscode.window.showInformationMessage("SELF Code Auto Refresh Disabled");
42+
this.setRefreshEnabled(false, true);
4743
})
4844
);
4945
setInterval(async () => {
@@ -54,6 +50,15 @@ export class selfCodesResultsView implements TreeDataProvider<any> {
5450

5551
}
5652

53+
setRefreshEnabled(enabled: boolean, withMessage = false): void {
54+
this.autoRefresh = enabled;
55+
vscode.commands.executeCommand(`setContext`, `vscode-db2i.self.autoRefresh`, enabled);
56+
57+
if (withMessage) {
58+
vscode.window.showInformationMessage(`SELF Code Auto Refresh ${enabled ? 'Enabled' : 'Disabled'}`);
59+
}
60+
}
61+
5762
async getSelfCodes(): Promise<SelfCodeNode[]> {
5863
const selected = JobManager.getRunningJobs();
5964
if (selected) {
@@ -81,22 +86,27 @@ export class selfCodesResultsView implements TreeDataProvider<any> {
8186
return [];
8287
} else {
8388
const selfCodes = await this.getSelfCodes();
84-
return selfCodes.map((error) => {
85-
const hitsTxt = error.MATCHES.toString().padStart(10, ' ');
86-
const label = `${error.LOGGED_SQLSTATE} (${error.LOGGED_SQLCODE})`;
87-
const details = `${error.MESSAGE_TEXT} ${error.MATCHES < 100 ? hitsTxt : '💯'.padStart(10, ' ')} 🔥`;
88-
const hoverMessage = new vscode.MarkdownString(
89-
`**SQL Statement💻:** ${error.STMTTEXT}\n\n---\n\n**SQL Job🛠️:** ${error.JOB_NAME}\n\n---\n\n**Occurrences🔥:** ${error.MATCHES}\n\n---\n\n**Details✏️:** ${error.MESSAGE_SECOND_LEVEL_TEXT}`
90-
);
91-
hoverMessage.isTrusted = true;
92-
const treeItem = new SelfCodeTreeItem(
93-
label,
94-
details,
95-
hoverMessage,
96-
vscode.TreeItemCollapsibleState.None
97-
);
98-
return treeItem;
99-
});
89+
90+
if (selfCodes) {
91+
return selfCodes.map((error) => {
92+
const hitsTxt = error.MATCHES.toString().padStart(10, ' ');
93+
const label = `${error.LOGGED_SQLSTATE} (${error.LOGGED_SQLCODE})`;
94+
const details = `${error.MESSAGE_TEXT} ${error.MATCHES < 100 ? hitsTxt : '💯'.padStart(10, ' ')} 🔥`;
95+
const hoverMessage = new vscode.MarkdownString(
96+
`**SQL Statement💻:** ${error.STMTTEXT}\n\n---\n\n**SQL Job🛠️:** ${error.JOB_NAME}\n\n---\n\n**Occurrences🔥:** ${error.MATCHES}\n\n---\n\n**Details✏️:** ${error.MESSAGE_SECOND_LEVEL_TEXT}`
97+
);
98+
hoverMessage.isTrusted = true;
99+
const treeItem = new SelfCodeTreeItem(
100+
label,
101+
details,
102+
hoverMessage,
103+
vscode.TreeItemCollapsibleState.None
104+
);
105+
return treeItem;
106+
});
107+
}
108+
109+
return [];
100110
}
101111
}
102112
getParent?(element: any) {
@@ -128,7 +138,6 @@ export class SelfCodeTreeItem extends TreeItem {
128138
public readonly collapsibleState: vscode.TreeItemCollapsibleState
129139
) {
130140
super(errorMessage, collapsibleState);
131-
console.log(hoverMessage);
132141
this.tooltip = hoverMessage; // Hover text
133142
this.description = details; // Additional details shown in the tree view
134143
}

0 commit comments

Comments
 (0)