1
- import vscode , { MarkdownString , ProgressLocation , ThemeIcon , TreeItem , TreeItemCollapsibleState , commands , env , window , workspace } from "vscode" ;
1
+ import vscode , { MarkdownString , ProgressLocation , ThemeIcon , TreeItem , TreeItemCollapsibleState , Uri , commands , env , window , workspace } from "vscode" ;
2
2
import { TreeDataProvider } from "vscode" ;
3
3
import { Config , JobManager } from "../../config" ;
4
- import { JobInfo } from "../../connection/manager" ;
4
+ import { JobInfo , SQLJobManager } from "../../connection/manager" ;
5
5
import { editJobUi } from "./editJob" ;
6
6
import { displayJobLog } from "./jobLog" ;
7
+ import { ServerTraceDest , ServerTraceLevel } from "../../connection/types" ;
8
+ import { ServerComponent } from "../../connection/serverComponent" ;
7
9
import { updateStatusBar } from "./statusBar" ;
8
10
import { TransactionEndType } from "../../connection/sqlJob" ;
9
11
import { ConfigGroup , ConfigManager } from "./ConfigManager" ;
@@ -24,9 +26,9 @@ export class JobManagerView implements TreeDataProvider<any> {
24
26
...ConfigManager . initialiseSaveCommands ( ) ,
25
27
26
28
vscode . commands . registerCommand ( `vscode-db2i.jobManager.newJob` , async ( ) => {
27
- await window . withProgress ( { location : ProgressLocation . Window } , async ( progress ) => {
29
+ await window . withProgress ( { location : ProgressLocation . Window } , async ( progress ) => {
28
30
try {
29
- progress . report ( { message : `Spinning up SQL job...` } ) ;
31
+ progress . report ( { message : `Spinning up SQL job...` } ) ;
30
32
await JobManager . newJob ( ) ;
31
33
} catch ( e ) {
32
34
window . showErrorMessage ( e . message ) ;
@@ -103,15 +105,15 @@ export class JobManagerView implements TreeDataProvider<any> {
103
105
if ( selected ) {
104
106
editJobUi ( selected . job . options , selected . name ) . then ( newOptions => {
105
107
if ( newOptions ) {
106
- window . withProgress ( { location : ProgressLocation . Window } , async ( progress ) => {
107
- progress . report ( { message : `Ending current job` } ) ;
108
+ window . withProgress ( { location : ProgressLocation . Window } , async ( progress ) => {
109
+ progress . report ( { message : `Ending current job` } ) ;
108
110
109
111
await selected . job . close ( ) ;
110
112
111
- progress . report ( { message : `Starting new job` } ) ;
113
+ progress . report ( { message : `Starting new job` } ) ;
112
114
113
115
selected . job . options = newOptions ;
114
-
116
+
115
117
try {
116
118
await selected . job . connect ( ) ;
117
119
} catch ( e ) {
@@ -125,6 +127,50 @@ export class JobManagerView implements TreeDataProvider<any> {
125
127
}
126
128
} ) ,
127
129
130
+ vscode . commands . registerCommand ( `vscode-db2i.jobManager.enableTracing` , async ( node ?: SQLJobItem ) => {
131
+ if ( node ) {
132
+ const id = node . label as string ;
133
+ const selected = await JobManager . getJob ( id ) ;
134
+
135
+ ServerComponent . writeOutput ( `Enabling tracing for ${ selected . name } (${ selected . job . id } )` , true ) ;
136
+
137
+ selected . job . setTraceConfig ( ServerTraceDest . IN_MEM , ServerTraceLevel . DATASTREAM ) ;
138
+ }
139
+ } ) ,
140
+
141
+ vscode . commands . registerCommand ( `vscode-db2i.jobManager.getTrace` , async ( node ?: SQLJobItem ) => {
142
+ if ( node ) {
143
+ const id = node . label as string ;
144
+ const selected = await JobManager . getJob ( id ) ;
145
+
146
+ const possibleFile = selected . job . getTraceFilePath ( ) ;
147
+
148
+ if ( possibleFile ) {
149
+ // Trace was written to a file
150
+ vscode . workspace . openTextDocument ( Uri . from ( {
151
+ scheme : `streamfile` ,
152
+ path : possibleFile
153
+ } ) ) . then ( doc => {
154
+ vscode . window . showTextDocument ( doc ) ;
155
+ } ) ;
156
+
157
+ } else {
158
+ // This likely means IN_MEM was used
159
+ const trace = await selected . job . getTraceData ( ) ;
160
+ if ( trace . success ) {
161
+ vscode . workspace . openTextDocument ( {
162
+ content : trace . tracedata . trim ( )
163
+ } ) . then ( doc => {
164
+ vscode . window . showTextDocument ( doc ) ;
165
+ } )
166
+
167
+ } else {
168
+ ServerComponent . writeOutput ( `Unable to get trace data for ${ selected . name } (${ selected . job . id } ):` , true ) ;
169
+ ServerComponent . writeOutput ( trace . error ) ;
170
+ }
171
+ }
172
+ }
173
+ } ) ,
128
174
vscode . commands . registerCommand ( `vscode-db2i.jobManager.jobCommit` , async ( node ?: SQLJobItem ) => {
129
175
const id = node ? node . label as string : undefined ;
130
176
let selected = id ? JobManager . getJob ( id ) : JobManager . getSelection ( ) ;
@@ -193,17 +239,17 @@ export class JobManagerView implements TreeDataProvider<any> {
193
239
async getChildren ( element : ConfigGroup ) : Promise < SQLJobItem [ ] > {
194
240
if ( element ) {
195
241
return ConfigManager . getConfigTreeItems ( ) ;
196
-
242
+
197
243
} else {
198
- let nodes =
244
+ let nodes =
199
245
JobManager
200
246
. getRunningJobs ( )
201
247
. map ( ( info , index ) => new SQLJobItem ( info , index === JobManager . selectedJob ) ) ;
202
248
203
249
if ( ConfigManager . hasSavedItems ( ) ) {
204
250
nodes . push ( new ConfigGroup ( ) ) ;
205
251
}
206
-
252
+
207
253
return nodes ;
208
254
}
209
255
}
0 commit comments