Skip to content

Commit 8fe63d0

Browse files
committed
enable continue provider when there is active connection
1 parent b080eca commit 8fe63d0

File tree

4 files changed

+70
-66
lines changed

4 files changed

+70
-66
lines changed

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,9 +1026,8 @@
10261026
},
10271027
{
10281028
"command": "vscode-db2i.self.explainSelf",
1029-
"when": "view == vscode-db2i.self.nodes && viewItem == selfCodeNode && continueExtensionActive",
1030-
"group": "navigation",
1031-
"enablement": "vscode-db2i:continueExtensionActive"
1029+
"when": "view == vscode-db2i.self.nodes && viewItem == selfCodeNode && vscode-db2i:continueExtensionActive",
1030+
"group": "navigation"
10321031
}
10331032
],
10341033
"editor/title": [
@@ -1289,7 +1288,6 @@
12891288
"json-to-markdown-table": "^1.0.0",
12901289
"lru-cache": "^6.0.0",
12911290
"node-fetch": "^3.3.1",
1292-
"ollama": "^0.5.2",
12931291
"showdown": "^2.1.0",
12941292
"sql-formatter": "^14.0.0"
12951293
}

src/aiProviders/continue/continueContextProvider.ts

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from "vscode";
22
import { JobManager } from "../../config";
33
import { JobInfo } from "../../connection/manager";
44
import { SelfCodeNode } from "../../views/jobManager/selfCodes/nodes";
5-
import { findPossibleTables } from "../context";
5+
import { canTalkToDb, findPossibleTables } from "../context";
66
import {
77
ContextItem,
88
ContextProviderDescription,
@@ -106,66 +106,74 @@ export class db2ContextProvider implements IContextProvider {
106106
query: string,
107107
extras: ContextProviderExtras
108108
): Promise<ContextItem[]> {
109-
const job: JobInfo = this.getCurrentJob();
110-
const schema = this.getDefaultSchema();
111-
const fullInput = extras.fullInput;
112109
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 {
163169
}
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+
);
168175
}
176+
169177
}
170178
async loadSubmenuItems(
171179
args: LoadSubmenuItemsArgs

src/aiProviders/copilot/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import ollama, { ListResponse } from "ollama";
21
import * as vscode from "vscode";
32
import Statement from "../../database/statement";
43
import {

src/views/jobManager/selfCodes/contributes.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@
157157
},
158158
{
159159
"command": "vscode-db2i.self.explainSelf",
160-
"when": "view == vscode-db2i.self.nodes && viewItem == selfCodeNode && continueExtensionActive",
161-
"group": "navigation",
162-
"enablement": "vscode-db2i:continueExtensionActive"
160+
"when": "view == vscode-db2i.self.nodes && viewItem == selfCodeNode && vscode-db2i:continueExtensionActive",
161+
"group": "navigation"
163162
}
164163
]
165164
}

0 commit comments

Comments
 (0)