@@ -2,7 +2,7 @@ import * as vscode from "vscode";
2
2
import { JobManager } from "../../config" ;
3
3
import { JobInfo } from "../../connection/manager" ;
4
4
import { SelfCodeNode } from "../../views/jobManager/selfCodes/nodes" ;
5
- import { findPossibleTables } from "../context" ;
5
+ import { canTalkToDb , findPossibleTables } from "../context" ;
6
6
import {
7
7
ContextItem ,
8
8
ContextProviderDescription ,
@@ -106,66 +106,74 @@ export class db2ContextProvider implements IContextProvider {
106
106
query : string ,
107
107
extras : ContextProviderExtras
108
108
) : Promise < ContextItem [ ] > {
109
- const job : JobInfo = this . getCurrentJob ( ) ;
110
- const schema = this . getDefaultSchema ( ) ;
111
- const fullInput = extras . fullInput ;
112
109
const contextItems : ContextItem [ ] = [ ] ;
113
- contextItems . push ( {
114
- name : `SYSTEM PROMPT` ,
115
- description : `system prompt context` ,
116
- content : DB2_SYSTEM_PROMPT ,
117
- } ) ;
118
- try {
119
- switch ( true ) {
120
- case fullInput . includes ( `*SELF` ) || query ?. includes ( `*SELF` ) :
121
- // get current self code errors in job
122
- // build promt with error information
123
- // add to contextItems
124
-
125
- if ( job ) {
126
- const selfCodes = await this . getSelfCodes ( job ) ;
127
-
128
- let prompt = DB2_SELF_PROMPT . join ( " " ) ;
129
- prompt += JSON . stringify ( selfCodes , null , 2 ) ;
130
-
131
- contextItems . push ( {
132
- name : `${ job . name } -self` ,
133
- description : `SELF code errors for ${ job . name } ` ,
134
- content : prompt ,
135
- } ) ;
136
- }
137
-
138
- return contextItems ;
139
- default :
140
- // const contextItems: ContextItem[] = [];
141
- const tableRefs = await findPossibleTables (
142
- null ,
143
- schema ,
144
- fullInput . split ( ` ` )
145
- ) ;
146
- for ( const table of Object . keys ( tableRefs ) ) {
147
- const columnData : TableColumn [ ] = tableRefs [ table ] ;
148
- const tableSchema =
149
- columnData . length > 0 ? columnData [ 0 ] . TABLE_SCHEMA : null ;
150
-
151
- // create context item
152
- let prompt = `Db2 for i Table meta data for schema ${ tableSchema } table ${ table } \n` ;
153
- prompt += `Column Info: ${ JSON . stringify ( columnData ) } \n\n` ;
154
-
155
- contextItems . push ( {
156
- name : `${ job . name } -${ tableSchema } -${ table } ` ,
157
- description : `Schema and table information for ${ table } ` ,
158
- content : prompt ,
159
- } ) ;
160
- }
161
-
162
- return contextItems ;
110
+ if ( canTalkToDb ( ) ) {
111
+ const job : JobInfo = this . getCurrentJob ( ) ;
112
+ const schema = this . getDefaultSchema ( ) ;
113
+ const fullInput = extras . fullInput ;
114
+ contextItems . push ( {
115
+ name : `SYSTEM PROMPT` ,
116
+ description : `system prompt context` ,
117
+ content : DB2_SYSTEM_PROMPT ,
118
+ } ) ;
119
+ try {
120
+ switch ( true ) {
121
+ case fullInput . includes ( `*SELF` ) || query ?. includes ( `*SELF` ) :
122
+ // get current self code errors in job
123
+ // build promt with error information
124
+ // add to contextItems
125
+
126
+ if ( job ) {
127
+ const selfCodes = await this . getSelfCodes ( job ) ;
128
+
129
+ let prompt = DB2_SELF_PROMPT . join ( " " ) ;
130
+ prompt += JSON . stringify ( selfCodes , null , 2 ) ;
131
+
132
+ contextItems . push ( {
133
+ name : `${ job . name } -self` ,
134
+ description : `SELF code errors for ${ job . name } ` ,
135
+ content : prompt ,
136
+ } ) ;
137
+ }
138
+
139
+ return contextItems ;
140
+ default :
141
+ // const contextItems: ContextItem[] = [];
142
+ const tableRefs = await findPossibleTables (
143
+ null ,
144
+ schema ,
145
+ fullInput . split ( ` ` )
146
+ ) ;
147
+ for ( const table of Object . keys ( tableRefs ) ) {
148
+ const columnData : TableColumn [ ] = tableRefs [ table ] ;
149
+ const tableSchema =
150
+ columnData . length > 0 ? columnData [ 0 ] . TABLE_SCHEMA : null ;
151
+
152
+ // create context item
153
+ let prompt = `Db2 for i Table meta data for schema ${ tableSchema } table ${ table } \n` ;
154
+ prompt += `Column Info: ${ JSON . stringify ( columnData ) } \n\n` ;
155
+
156
+ contextItems . push ( {
157
+ name : `${ job . name } -${ tableSchema } -${ table } ` ,
158
+ description : `Schema and table information for ${ table } ` ,
159
+ content : prompt ,
160
+ } ) ;
161
+ }
162
+
163
+ return contextItems ;
164
+ }
165
+ } catch ( error ) {
166
+ vscode . window . showErrorMessage ( `Failed to query Db2i database: ${ error } ` ) ;
167
+ throw new Error ( `Failed to query Db2i database: ${ error } ` ) ;
168
+ } finally {
163
169
}
164
- } catch ( error ) {
165
- vscode . window . showErrorMessage ( `Failed to query Db2i database: ${ error } ` ) ;
166
- throw new Error ( `Failed to query Db2i database: ${ error } ` ) ;
167
- } finally {
170
+
171
+ } else {
172
+ throw new Error (
173
+ `Not connected to the database. Please check your configuration.`
174
+ ) ;
168
175
}
176
+
169
177
}
170
178
async loadSubmenuItems (
171
179
args : LoadSubmenuItemsArgs
0 commit comments