@@ -10,7 +10,7 @@ import {
1010 Disposable
1111} from "vscode" ;
1212import { JobManager } from "../../../config" ;
13- import { SelfCodeNode } from "./nodes" ;
13+ import { SelfCodeNode , SelfIleStackFrame } from "./nodes" ;
1414
1515type 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}
150147export 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