Skip to content

Commit f69825e

Browse files
committed
Add SelfIleStackFrame and InitialStackData interfaces for SELF
Signed-off-by: worksofliam <[email protected]>
1 parent 1aaec65 commit f69825e

File tree

2 files changed

+119
-39
lines changed

2 files changed

+119
-39
lines changed

src/views/jobManager/selfCodes/nodes.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2+
export interface SelfIleStackFrame {
3+
ORD: number;
4+
TYPE: string;
5+
LIB: string;
6+
PGM: string;
7+
MODULE: string;
8+
PROC: string;
9+
STMT: string;
10+
ACTGRP: string;
11+
}
12+
13+
export interface InitialStackData {
14+
initial_stack: SelfIleStackFrame[];
15+
}
16+
117
export interface SelfCodeNode {
218
JOB_NAME: string,
319
USER_NAME: string;
@@ -9,6 +25,14 @@ export interface SelfCodeNode {
925
STMTTEXT: string;
1026
MESSAGE_TEXT: string;
1127
MESSAGE_SECOND_LEVEL_TEXT: string;
28+
29+
PROGRAM_LIBRARY: string;
30+
PROGRAM_NAME: string;
31+
PROGRAM_TYPE: "*PGM"|"*SRVPGM";
32+
MODULE_NAME: string;
33+
CLIENT_APPLNAME: string
34+
CLIENT_PROGRAMID: string;
35+
INITIAL_STACK: InitialStackData;
1236
}
1337

1438
export type SelfValue = "*ALL" | "*ERROR" | "*WARNING" | "*NONE";

src/views/jobManager/selfCodes/selfCodesResultsView.ts

Lines changed: 95 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
Disposable
1111
} from "vscode";
1212
import { JobManager } from "../../../config";
13-
import { SelfCodeNode } from "./nodes";
13+
import { SelfCodeNode, SelfIleStackFrame } from "./nodes";
1414

1515
type ChangeTreeDataEventType = SelfCodeTreeItem | undefined | null | void;
1616

@@ -42,14 +42,14 @@ export class selfCodesResultsView implements TreeDataProvider<any> {
4242
this.setRefreshEnabled(false, true);
4343
}),
4444
vscode.commands.registerCommand(`vscode-db2i.self.copySqlStatement`, async (item: SelfCodeTreeItem) => {
45-
if (item && item.selfCodeNode.STMTTEXT) {
46-
await vscode.env.clipboard.writeText(item.selfCodeNode.STMTTEXT);
45+
if (item && item.error.STMTTEXT) {
46+
await vscode.env.clipboard.writeText(item.error.STMTTEXT);
4747
vscode.window.showInformationMessage(`SQL statement copied to clipboard.`);
4848
}
4949
}),
5050
vscode.commands.registerCommand(`vscode-db2i.self.displayDetails`, async (item: SelfCodeTreeItem) => {
51-
if (item && item.selfCodeNode) {
52-
const jsonData = JSON.stringify(item.selfCodeNode, null, 2);
51+
if (item && item.error) {
52+
const jsonData = JSON.stringify(item.error, null, 2);
5353
const document = await vscode.workspace.openTextDocument({
5454
content: jsonData,
5555
language: `json`
@@ -81,13 +81,18 @@ export class selfCodesResultsView implements TreeDataProvider<any> {
8181
async getSelfCodes(): Promise<SelfCodeNode[]> {
8282
const selected = JobManager.getSelection();
8383
if (selected) {
84-
const content = `SELECT job_name, user_name, reason_code, logged_time, logged_sqlstate, logged_sqlcode, matches, stmttext,
85-
message_text, message_second_level_text
86-
FROM qsys2.sql_error_log, lateral
87-
(select * from TABLE(SYSTOOLS.SQLCODE_INFO(logged_sqlcode)))
84+
const content = `SELECT
85+
job_name, user_name, reason_code, logged_time, logged_sqlstate, logged_sqlcode, matches, stmttext, message_text, message_second_level_text,
86+
program_library, program_name, program_type, module_name, client_applname, client_programid, initial_stack
87+
FROM qsys2.sql_error_log, lateral (select * from TABLE(SYSTOOLS.SQLCODE_INFO(logged_sqlcode)))
8888
where user_name = current_user
8989
order by logged_time desc`;
90-
const data: SelfCodeNode[] = await JobManager.runSQL<SelfCodeNode>(content, undefined);
90+
91+
const data: SelfCodeNode[] = (await JobManager.runSQL<SelfCodeNode>(content)).map((row) => ({
92+
...row,
93+
INITIAL_STACK: JSON.parse(row.INITIAL_STACK as unknown as string)
94+
}));
95+
9196
return data;
9297
}
9398
return;
@@ -100,28 +105,20 @@ export class selfCodesResultsView implements TreeDataProvider<any> {
100105
getTreeItem(element: any): TreeItem | Thenable<TreeItem> {
101106
return element;
102107
}
103-
async getChildren(element?: any): Promise<any[]> {
108+
109+
async getChildren(element?: SelfCodeTreeItem|SelfErrorStackItem): Promise<any[]> {
104110
if (element) {
105-
return [];
111+
if (element instanceof SelfCodeTreeItem) {
112+
return element.getChilden();
113+
} else if (element instanceof SelfErrorStackItem) {
114+
return element.getChildren();
115+
}
106116
} else {
107117
const selfCodes = await this.getSelfCodes();
108118

109119
if (selfCodes) {
110120
return selfCodes.map((error) => {
111-
const label = `${error.LOGGED_SQLSTATE} (${error.LOGGED_SQLCODE}) ${error.REASON_CODE != null ? error.REASON_CODE : ""}`;
112-
const details = `${error.MESSAGE_TEXT}`; // ${error.MATCHES < 100 ? hitsTxt : '💯'.padStart(10, ' ')} 🔥`;
113-
const hoverMessage = new vscode.MarkdownString(
114-
`**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}`
115-
);
116-
hoverMessage.isTrusted = true;
117-
const treeItem = new SelfCodeTreeItem(
118-
label,
119-
details,
120-
hoverMessage,
121-
vscode.TreeItemCollapsibleState.None,
122-
error
123-
);
124-
treeItem.contextValue = `selfCodeNode`;
121+
const treeItem = new SelfCodeTreeItem(error);
125122
return treeItem;
126123
});
127124
}
@@ -148,24 +145,84 @@ export class selfCodesResultsView implements TreeDataProvider<any> {
148145
}
149146
}
150147
export class SelfCodeTreeItem extends TreeItem {
151-
selfCodeNode: SelfCodeNode;
152-
153148
constructor(
154-
public readonly errorMessage: string,
155-
public readonly details: string,
156-
public readonly hoverMessage: vscode.MarkdownString,
157-
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
158-
error: SelfCodeNode
149+
public error: SelfCodeNode
159150
) {
160-
super(errorMessage, collapsibleState);
161-
this.selfCodeNode = error;
162-
this.tooltip = hoverMessage; // Hover text
163-
this.description = details; // Additional details shown in the tree view
151+
const label = `${error.LOGGED_SQLSTATE} (${error.LOGGED_SQLCODE}) ${error.REASON_CODE != null ? error.REASON_CODE : ""}`;
152+
super(label, vscode.TreeItemCollapsibleState.Collapsed);
153+
154+
const hover = new vscode.MarkdownString(
155+
[
156+
`**💻 SQL Statement:** ${error.STMTTEXT}`,
157+
``, ``,
158+
`---`,
159+
``, ``,
160+
`**🛠️ SQL Job:** ${error.JOB_NAME}`,
161+
``, ``,
162+
`---`,
163+
``, ``,
164+
`**🔥 Occurrences:** ${error.MATCHES}`,
165+
``, ``,
166+
`---`,
167+
``, ``,
168+
`**✏️ Details:** ${error.MESSAGE_SECOND_LEVEL_TEXT}`
169+
].join(`\n`)
170+
);
171+
hover.isTrusted = true;
172+
173+
this.tooltip = hover;
174+
175+
this.description = error.MESSAGE_TEXT; // Additional details shown in the tree view
164176
this.resourceUri = vscode.Uri.from({
165177
scheme: `selfCodeTreeView`,
166178
path: error.MATCHES.toString()
167179
})
180+
168181
this.iconPath = error.LOGGED_SQLCODE < 0 ? new vscode.ThemeIcon(`error`): new vscode.ThemeIcon(`warning`);
182+
this.contextValue = `selfCodeNode`;
183+
}
184+
185+
getChilden(): SelfErrorNodeItem[] {
186+
return [
187+
new SelfErrorNodeItem(`Job`, this.error.JOB_NAME),
188+
new SelfErrorNodeItem(`Client Name`, this.error.CLIENT_APPLNAME),
189+
new SelfErrorNodeItem(`Client Program`, this.error.CLIENT_PROGRAMID),
190+
new SelfErrorNodeItem(`Object`, `${this.error.PROGRAM_LIBRARY}/${this.error.PROGRAM_NAME} (${this.error.PROGRAM_TYPE}, ${this.error.MODULE_NAME})`),
191+
new SelfErrorStackItem(this.error.INITIAL_STACK.initial_stack)
192+
]
193+
}
194+
}
195+
196+
class SelfErrorNodeItem extends TreeItem {
197+
constructor(label: string, description: string) {
198+
super(label, vscode.TreeItemCollapsibleState.None);
199+
this.iconPath = new vscode.ThemeIcon(`info`);
200+
this.description = description;
201+
}
202+
}
203+
204+
class SelfErrorStackItem extends TreeItem {
205+
constructor(private stack: SelfIleStackFrame[]) {
206+
super(`Stack`, vscode.TreeItemCollapsibleState.Collapsed);
207+
this.iconPath = new vscode.ThemeIcon(`debug`);
208+
this.contextValue = `selfCodeStack`;
209+
210+
this.resourceUri = vscode.Uri.from({
211+
scheme: `selfCodeTreeView`,
212+
path: stack.length.toString()
213+
})
214+
}
215+
216+
getChildren(): SelfErrorStackFrameItem[] {
217+
return this.stack.map((stackCall) => new SelfErrorStackFrameItem(stackCall));
218+
}
219+
}
220+
221+
class SelfErrorStackFrameItem extends TreeItem {
222+
constructor(stackCall: SelfIleStackFrame) {
223+
super(`${stackCall.PROC}:${stackCall.STMT}`, vscode.TreeItemCollapsibleState.None);
224+
this.description = `${stackCall.LIB}/${stackCall.PGM} (${stackCall.TYPE}, ${stackCall.MODULE})`;
225+
this.contextValue = `selfCodeStackCall`;
169226
}
170227
}
171228

@@ -185,8 +242,7 @@ export class SelfTreeDecorationProvider implements FileDecorationProvider {
185242

186243
if (!isNaN(errorCount) && errorCount > 0) {
187244
return {
188-
badge: errorCount < 100 ? errorCount.toString() : '💯',
189-
tooltip: `Occurrences: ${errorCount}`
245+
badge: errorCount < 100 ? errorCount.toString() : '💯'
190246
}
191247
}
192248
}

0 commit comments

Comments
 (0)