From 4b6430789af53a875acf596d3bfaecb1d7bf60cf Mon Sep 17 00:00:00 2001 From: Adam Shedivy Date: Tue, 3 Dec 2024 13:30:27 -0600 Subject: [PATCH 1/8] fix column null context --- src/aiProviders/continue/continueContextProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiProviders/continue/continueContextProvider.ts b/src/aiProviders/continue/continueContextProvider.ts index 6f08f8a5..117c9a32 100644 --- a/src/aiProviders/continue/continueContextProvider.ts +++ b/src/aiProviders/continue/continueContextProvider.ts @@ -148,7 +148,7 @@ export class db2ContextProvider implements IContextProvider { const columnData: TableColumn[] = tableRefs[table]; if (columnData && columnData.length > 0) { const tableSchema = - columnData.length > 0 ? columnData[0].TABLE_SCHEMA : null; + columnData[0].TABLE_SCHEMA ?? schema; // create context item let prompt = `Db2 for i Table meta data for schema ${tableSchema} table ${table}\n`; From 171f67936003db5db8004866320164239dba95ef Mon Sep 17 00:00:00 2001 From: Adam Shedivy Date: Fri, 13 Dec 2024 18:11:00 -0600 Subject: [PATCH 2/8] WIP: list tables context provider --- .../continue/continueContextProvider.ts | 43 +++++++++- .../continue/listTablesContextProvider.ts | 82 +++++++++++++++++++ src/extension.ts | 5 ++ 3 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 src/aiProviders/continue/listTablesContextProvider.ts diff --git a/src/aiProviders/continue/continueContextProvider.ts b/src/aiProviders/continue/continueContextProvider.ts index 117c9a32..e1ce80d5 100644 --- a/src/aiProviders/continue/continueContextProvider.ts +++ b/src/aiProviders/continue/continueContextProvider.ts @@ -2,7 +2,7 @@ import * as vscode from "vscode"; import { JobManager } from "../../config"; import { JobInfo } from "../../connection/manager"; import { SelfCodeNode } from "../../views/jobManager/selfCodes/nodes"; -import { canTalkToDb, findPossibleTables } from "../context"; +import { canTalkToDb, findPossibleTables, TableRefs } from "../context"; import { ContextItem, ContextProviderDescription, @@ -12,6 +12,7 @@ import { LoadSubmenuItemsArgs, } from "@continuedev/core"; import { DB2_SELF_PROMPT, DB2_SYSTEM_PROMPT } from "./prompts"; +import { table } from "console"; export let isContinueActive = false; @@ -102,6 +103,25 @@ export class db2ContextProvider implements IContextProvider { } } + parseSelectedCode(fullInput: string): string | null { + const regex = /```(?:.*?\n)?(.*?)```/gs; + + // Extract matches + const matches = fullInput.match(regex); + + if (matches && matches.length > 0) { + // Extract SQL code from the first match + let sqlCode = matches[0].replace(/```(?:.*?\n)?|```/g, '').trim(); + // Remove all newline characters + sqlCode = sqlCode.replace(/[\r\n]+/g, ' ').trim(); + return sqlCode; + } + + // Return null if no SQL code is found + return null; +} + + async getContextItems( query: string, extras: ContextProviderExtras @@ -111,6 +131,10 @@ export class db2ContextProvider implements IContextProvider { const job: JobInfo = this.getCurrentJob(); const schema = this.getDefaultSchema(); const fullInput = extras.fullInput; + const selectedCode = extras.selectedCode; + if (selectedCode) { + const parsedCode = this.parseSelectedCode(fullInput); + } contextItems.push({ name: `SYSTEM PROMPT`, description: `system prompt context`, @@ -138,14 +162,25 @@ export class db2ContextProvider implements IContextProvider { return contextItems; default: - // const contextItems: ContextItem[] = []; + + // check for selected code refs since these are apart of markdown string + let selectedCodeRefs: TableRefs = {}; + if (selectedCode.length > 0) { + const parsedCode = this.parseSelectedCode(fullInput); + selectedCodeRefs = await findPossibleTables(null, schema, parsedCode.split(` `)); + } + + // check full input for table refs const tableRefs = await findPossibleTables( null, schema, fullInput.split(` `) ); - for (const table of Object.keys(tableRefs)) { - const columnData: TableColumn[] = tableRefs[table]; + + // Merge selectedCodeRefs into tableRefs + const mergedRefs = { ...tableRefs, ...selectedCodeRefs }; + for (const table of Object.keys(mergedRefs)) { + const columnData: TableColumn[] = mergedRefs[table]; if (columnData && columnData.length > 0) { const tableSchema = columnData[0].TABLE_SCHEMA ?? schema; diff --git a/src/aiProviders/continue/listTablesContextProvider.ts b/src/aiProviders/continue/listTablesContextProvider.ts new file mode 100644 index 00000000..68c4d804 --- /dev/null +++ b/src/aiProviders/continue/listTablesContextProvider.ts @@ -0,0 +1,82 @@ +import * as vscode from "vscode"; +import { ContextItem, ContextProviderDescription, ContextProviderExtras, ContextSubmenuItem, IContextProvider, LoadSubmenuItemsArgs } from "@continuedev/core"; +import { JobInfo } from "../../connection/manager"; +import { JobManager } from "../../config"; +import { isContinueActive } from "./continueContextProvider"; +import { findPossibleTables } from "../context"; + +const listDb2Table: ContextProviderDescription = { + title: "list Db2i Tables", + displayTitle: "Db2i-tables", + description: "Add Db2i Table info to Context", + type: "submenu" +} + +class ListDb2iTables implements IContextProvider { + get description(): ContextProviderDescription { + return listDb2Table + } + + getCurrentJob(): JobInfo { + const currentJob: JobInfo = JobManager.getSelection(); + return currentJob; + } + + private getDefaultSchema = (): string => { + const currentJob: JobInfo = this.getCurrentJob(); + return currentJob?.job.options.libraries[0] || "QGPL"; + } + + async getTables() { + const schema = this.getDefaultSchema().toUpperCase(); + const sql = ` + SELECT TABLE_NAME, TABLE_SCHEMA + FROM QSYS2.SYSTABLES + WHERE TABLE_SCHEMA = '${schema}' + AND TABLE_TYPE = 'T' + ORDER BY TABLE_NAME + `; + + const result = await JobManager.runSQL(sql); + return result; + + + } + + async getContextItems(query: string, extras: ContextProviderExtras): Promise { + const tableInfo = await findPossibleTables(null, this.getDefaultSchema(), query.split(` `)); + return [{ + name: `${query}`, + content: JSON.stringify(tableInfo), + description: "table metadata" + + }] + } + async loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise { + const tables: any[] = await this.getTables(); + + return tables.map((table) => { + return { + id: table.TABLE_NAME, + title: table.TABLE_NAME, + description: `${table.TABLE_SCHEMA}-${table.TABLE_NAME}`, + } + }) + + } + +} + +export async function registerDb2iTablesProvider() { + const provider = new ListDb2iTables(); + const continueID = `Continue.continue`; + const continueEx = vscode.extensions.getExtension(continueID); + if (continueEx) { + if (!continueEx.isActive) { + await continueEx.activate(); + } + + const continueAPI = continueEx?.exports; + continueAPI?.registerCustomContextProvider(provider); + } +} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 2138f7c7..ed5782a9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -24,6 +24,7 @@ import { SelfTreeDecorationProvider, selfCodesResultsView } from "./views/jobMan import { registerContinueProvider } from "./aiProviders/continue/continueContextProvider"; import { queryHistory } from "./views/queryHistoryView"; import { activateChat, registerCopilotProvider } from "./aiProviders/copilot"; +import { registerDb2iTablesProvider } from "./aiProviders/continue/listTablesContextProvider"; export interface Db2i { sqlJobManager: SQLJobManager, @@ -98,6 +99,8 @@ export function activate(context: vscode.ExtensionContext): Db2i { onConnectOrServerInstall().then(() => { exampleBrowser.refresh(); selfCodesView.setRefreshEnabled(Configuration.get(`jobSelfViewAutoRefresh`) || false); + // register list tables + registerDb2iTablesProvider(); if (devMode && runTests) { runTests(); } @@ -110,6 +113,8 @@ export function activate(context: vscode.ExtensionContext): Db2i { // register continue provider registerContinueProvider(); + + instance.subscribe(context, `disconnected`, `db2i-disconnected`, () => ServerComponent.reset()); return { sqlJobManager: JobManager, sqlJob: (options?: JDBCOptions) => new OldSQLJob(options) }; From 437988885c206d17d4aeb9da111544d98898c37c Mon Sep 17 00:00:00 2001 From: Adam Shedivy Date: Mon, 16 Dec 2024 17:10:32 -0600 Subject: [PATCH 3/8] add schema context item to menu --- .../continue/listTablesContextProvider.ts | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/aiProviders/continue/listTablesContextProvider.ts b/src/aiProviders/continue/listTablesContextProvider.ts index 68c4d804..e5abfff9 100644 --- a/src/aiProviders/continue/listTablesContextProvider.ts +++ b/src/aiProviders/continue/listTablesContextProvider.ts @@ -4,6 +4,7 @@ import { JobInfo } from "../../connection/manager"; import { JobManager } from "../../config"; import { isContinueActive } from "./continueContextProvider"; import { findPossibleTables } from "../context"; +import Statement from "../../database/statement"; const listDb2Table: ContextProviderDescription = { title: "list Db2i Tables", @@ -27,8 +28,8 @@ class ListDb2iTables implements IContextProvider { return currentJob?.job.options.libraries[0] || "QGPL"; } - async getTables() { - const schema = this.getDefaultSchema().toUpperCase(); + async getTables(curSchema: string) { + const schema = Statement.delimName(curSchema, true); const sql = ` SELECT TABLE_NAME, TABLE_SCHEMA FROM QSYS2.SYSTABLES @@ -39,12 +40,31 @@ class ListDb2iTables implements IContextProvider { const result = await JobManager.runSQL(sql); return result; + } + + async getColumnInfoForAllTables(schema: string) { + const sql = ` + SELECT COLUMN_NAME, TABLE_NAME, DATA_TYPE + FROM QSYS2.SYSCOLUMNS + WHERE TABLE_SCHEMA = '${Statement.delimName(schema)}' + `; + const result = await JobManager.runSQL(sql); + return result; } async getContextItems(query: string, extras: ContextProviderExtras): Promise { - const tableInfo = await findPossibleTables(null, this.getDefaultSchema(), query.split(` `)); + const schema = this.getDefaultSchema(); + if (query.toUpperCase() === schema.toUpperCase()) { + const tableInfo = await this.getColumnInfoForAllTables(schema); + return [{ + name: `Info for all tables in ${schema}`, + content: JSON.stringify(tableInfo), + description: "table metadata" + }] + } + const tableInfo = await findPossibleTables(null, schema, query.split(` `)); return [{ name: `${query}`, content: JSON.stringify(tableInfo), @@ -52,17 +72,24 @@ class ListDb2iTables implements IContextProvider { }] } + async loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise { - const tables: any[] = await this.getTables(); + const schema = this.getDefaultSchema(); + const tables: any[] = await this.getTables(schema); + + const schemaSubmenuItem: ContextSubmenuItem = { + id: schema, + title: schema, + description: `All table info in schema: ${schema}` + }; - return tables.map((table) => { - return { - id: table.TABLE_NAME, - title: table.TABLE_NAME, - description: `${table.TABLE_SCHEMA}-${table.TABLE_NAME}`, - } - }) + const tableSubmenuItems: ContextSubmenuItem[] = tables.map((table) => ({ + id: table.TABLE_NAME, + title: table.TABLE_NAME, + description: `${table.TABLE_SCHEMA}-${table.TABLE_NAME}`, + })); + return [schemaSubmenuItem, ...tableSubmenuItems]; } } From 8e7501fb1d5ee3cb4a14b31f70f1dea10d6cecf9 Mon Sep 17 00:00:00 2001 From: Adam Shedivy Date: Tue, 17 Dec 2024 13:24:52 -0600 Subject: [PATCH 4/8] use internal APIs for querying table meta data --- .../continue/continueContextProvider.ts | 47 ++-------- .../continue/listTablesContextProvider.ts | 89 +++++++++---------- src/database/table.ts | 10 ++- 3 files changed, 57 insertions(+), 89 deletions(-) diff --git a/src/aiProviders/continue/continueContextProvider.ts b/src/aiProviders/continue/continueContextProvider.ts index e1ce80d5..e2464b88 100644 --- a/src/aiProviders/continue/continueContextProvider.ts +++ b/src/aiProviders/continue/continueContextProvider.ts @@ -2,7 +2,7 @@ import * as vscode from "vscode"; import { JobManager } from "../../config"; import { JobInfo } from "../../connection/manager"; import { SelfCodeNode } from "../../views/jobManager/selfCodes/nodes"; -import { canTalkToDb, findPossibleTables, TableRefs } from "../context"; +import { canTalkToDb, findPossibleTables } from "../context"; import { ContextItem, ContextProviderDescription, @@ -12,7 +12,6 @@ import { LoadSubmenuItemsArgs, } from "@continuedev/core"; import { DB2_SELF_PROMPT, DB2_SYSTEM_PROMPT } from "./prompts"; -import { table } from "console"; export let isContinueActive = false; @@ -103,25 +102,6 @@ export class db2ContextProvider implements IContextProvider { } } - parseSelectedCode(fullInput: string): string | null { - const regex = /```(?:.*?\n)?(.*?)```/gs; - - // Extract matches - const matches = fullInput.match(regex); - - if (matches && matches.length > 0) { - // Extract SQL code from the first match - let sqlCode = matches[0].replace(/```(?:.*?\n)?|```/g, '').trim(); - // Remove all newline characters - sqlCode = sqlCode.replace(/[\r\n]+/g, ' ').trim(); - return sqlCode; - } - - // Return null if no SQL code is found - return null; -} - - async getContextItems( query: string, extras: ContextProviderExtras @@ -131,10 +111,6 @@ export class db2ContextProvider implements IContextProvider { const job: JobInfo = this.getCurrentJob(); const schema = this.getDefaultSchema(); const fullInput = extras.fullInput; - const selectedCode = extras.selectedCode; - if (selectedCode) { - const parsedCode = this.parseSelectedCode(fullInput); - } contextItems.push({ name: `SYSTEM PROMPT`, description: `system prompt context`, @@ -162,31 +138,20 @@ export class db2ContextProvider implements IContextProvider { return contextItems; default: - - // check for selected code refs since these are apart of markdown string - let selectedCodeRefs: TableRefs = {}; - if (selectedCode.length > 0) { - const parsedCode = this.parseSelectedCode(fullInput); - selectedCodeRefs = await findPossibleTables(null, schema, parsedCode.split(` `)); - } - - // check full input for table refs + // const contextItems: ContextItem[] = []; const tableRefs = await findPossibleTables( null, schema, fullInput.split(` `) ); - - // Merge selectedCodeRefs into tableRefs - const mergedRefs = { ...tableRefs, ...selectedCodeRefs }; - for (const table of Object.keys(mergedRefs)) { - const columnData: TableColumn[] = mergedRefs[table]; + for (const table of Object.keys(tableRefs)) { + const columnData: TableColumn[] = tableRefs[table]; if (columnData && columnData.length > 0) { const tableSchema = - columnData[0].TABLE_SCHEMA ?? schema; + columnData.length > 0 ? columnData[0].TABLE_SCHEMA : null; // create context item - let prompt = `Db2 for i Table meta data for schema ${tableSchema} table ${table}\n`; + let prompt = `Db2 for i table Assistant: The following information is based on the ${table} table within the ${tableSchema} schema. Utilize the provided schema and table metadata to assist the user:\n`; prompt += `Column Info: ${JSON.stringify(columnData)}\n\n`; contextItems.push({ diff --git a/src/aiProviders/continue/listTablesContextProvider.ts b/src/aiProviders/continue/listTablesContextProvider.ts index e5abfff9..745057ff 100644 --- a/src/aiProviders/continue/listTablesContextProvider.ts +++ b/src/aiProviders/continue/listTablesContextProvider.ts @@ -5,6 +5,8 @@ import { JobManager } from "../../config"; import { isContinueActive } from "./continueContextProvider"; import { findPossibleTables } from "../context"; import Statement from "../../database/statement"; +import Schemas from "../../database/schemas"; +import Table from "../../database/table"; const listDb2Table: ContextProviderDescription = { title: "list Db2i Tables", @@ -15,7 +17,7 @@ const listDb2Table: ContextProviderDescription = { class ListDb2iTables implements IContextProvider { get description(): ContextProviderDescription { - return listDb2Table + return listDb2Table; } getCurrentJob(): JobInfo { @@ -26,72 +28,69 @@ class ListDb2iTables implements IContextProvider { private getDefaultSchema = (): string => { const currentJob: JobInfo = this.getCurrentJob(); return currentJob?.job.options.libraries[0] || "QGPL"; - } - - async getTables(curSchema: string) { - const schema = Statement.delimName(curSchema, true); - const sql = ` - SELECT TABLE_NAME, TABLE_SCHEMA - FROM QSYS2.SYSTABLES - WHERE TABLE_SCHEMA = '${schema}' - AND TABLE_TYPE = 'T' - ORDER BY TABLE_NAME - `; - - const result = await JobManager.runSQL(sql); - return result; - } + }; async getColumnInfoForAllTables(schema: string) { - const sql = ` - SELECT COLUMN_NAME, TABLE_NAME, DATA_TYPE - FROM QSYS2.SYSCOLUMNS - WHERE TABLE_SCHEMA = '${Statement.delimName(schema)}' - `; - - const result = await JobManager.runSQL(sql); - return result; + const items: TableColumn[] = await Table.getItems(schema); + return items.map((column) => ({ + table_name: column.TABLE_NAME, + schema: column.TABLE_SCHEMA, + column_name: column.COLUMN_NAME, + column_data_type: column.DATA_TYPE, + })); } - async getContextItems(query: string, extras: ContextProviderExtras): Promise { + async getContextItems( + query: string, + extras: ContextProviderExtras + ): Promise { + let contextitems: ContextItem[] = []; const schema = this.getDefaultSchema(); if (query.toUpperCase() === schema.toUpperCase()) { const tableInfo = await this.getColumnInfoForAllTables(schema); - return [{ + contextitems.push({ name: `Info for all tables in ${schema}`, - content: JSON.stringify(tableInfo), - description: "table metadata" - }] + content: `Db2 for i table Assistant: The following table and column information is from the ${query} schema. Utilize the provided schema and table metadata to assist the user:\n${JSON.stringify(tableInfo)}`, + description: "table metadata", + }); + } else { + const tableInfo = await findPossibleTables( + null, + schema, + query.split(` `) + ); + contextitems.push({ + name: `${query}`, + content: `Db2 for i table Assistant: The following information is based on the ${query} table within the ${schema} schema. Utilize the provided schema and table metadata to assist the user:\n${JSON.stringify(tableInfo)}`, + description: "table metadata", + }); } - const tableInfo = await findPossibleTables(null, schema, query.split(` `)); - return [{ - name: `${query}`, - content: JSON.stringify(tableInfo), - description: "table metadata" - - }] + return contextitems; } - - async loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise { + + async loadSubmenuItems( + args: LoadSubmenuItemsArgs + ): Promise { const schema = this.getDefaultSchema(); - const tables: any[] = await this.getTables(schema); - + const tables: BasicSQLObject[] = await Schemas.getObjects(schema, [ + `tables`, + ]); + const schemaSubmenuItem: ContextSubmenuItem = { id: schema, title: schema, - description: `All table info in schema: ${schema}` + description: `All table info in schema: ${schema}`, }; const tableSubmenuItems: ContextSubmenuItem[] = tables.map((table) => ({ - id: table.TABLE_NAME, - title: table.TABLE_NAME, - description: `${table.TABLE_SCHEMA}-${table.TABLE_NAME}`, + id: table.name, + title: table.name, + description: `${table.schema}-${table.name}`, })); return [schemaSubmenuItem, ...tableSubmenuItems]; } - } export async function registerDb2iTablesProvider() { diff --git a/src/database/table.ts b/src/database/table.ts index 06517510..91d3cf08 100644 --- a/src/database/table.ts +++ b/src/database/table.ts @@ -8,7 +8,8 @@ export default class Table { * @param {string} name Not user input * @returns {Promise} */ - static async getItems(schema: string, name: string): Promise { + static async getItems(schema: string, name?: string): Promise { + const params = name ? [schema, name] : [schema]; const sql = [ `SELECT `, ` column.TABLE_SCHEMA,`, @@ -30,11 +31,14 @@ export default class Table { ` column.table_schema = key.table_schema and`, ` column.table_name = key.table_name and`, ` column.column_name = key.column_name`, - `WHERE column.TABLE_SCHEMA = ? AND column.TABLE_NAME = ?`, + `WHERE column.TABLE_SCHEMA = ?`, + ...[ + name ? `AND column.TABLE_NAME = ${name}` : ``, + ], `ORDER BY column.ORDINAL_POSITION`, ].join(` `); - return JobManager.runSQL(sql, {parameters: [schema, name]}); + return JobManager.runSQL(sql, {parameters: params}); } /** From 76a600e5477a342a78c5a3362cacc43873e72286 Mon Sep 17 00:00:00 2001 From: Adam Shedivy Date: Fri, 20 Dec 2024 12:14:46 -0600 Subject: [PATCH 5/8] workaround for updating context provider schema --- .../continue/listTablesContextProvider.ts | 50 ++++++++++++++++++- src/views/jobManager/jobManagerView.ts | 4 ++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/aiProviders/continue/listTablesContextProvider.ts b/src/aiProviders/continue/listTablesContextProvider.ts index 745057ff..9e4a4d84 100644 --- a/src/aiProviders/continue/listTablesContextProvider.ts +++ b/src/aiProviders/continue/listTablesContextProvider.ts @@ -7,6 +7,9 @@ import { findPossibleTables } from "../context"; import Statement from "../../database/statement"; import Schemas from "../../database/schemas"; import Table from "../../database/table"; +import * as fs from 'fs'; +import * as path from 'path'; +import * as os from 'os'; const listDb2Table: ContextProviderDescription = { title: "list Db2i Tables", @@ -15,6 +18,8 @@ const listDb2Table: ContextProviderDescription = { type: "submenu" } +export let listDb2TableContextProvider: Boolean = false; + class ListDb2iTables implements IContextProvider { get description(): ContextProviderDescription { return listDb2Table; @@ -93,6 +98,24 @@ class ListDb2iTables implements IContextProvider { } } +class emptyContextProvider implements IContextProvider { + get description(): ContextProviderDescription { + return { + title: "", + displayTitle: "", + description: "", + type: "normal" + }; + } + async getContextItems(query: string, extras: ContextProviderExtras): Promise { + return []; + } + async loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise { + return []; + } + +} + export async function registerDb2iTablesProvider() { const provider = new ListDb2iTables(); const continueID = `Continue.continue`; @@ -103,6 +126,31 @@ export async function registerDb2iTablesProvider() { } const continueAPI = continueEx?.exports; - continueAPI?.registerCustomContextProvider(provider); + if (listDb2TableContextProvider) { + + // HACK: re register context provider work around + // save continue config file to trigger a config reload to update list tables provider + const configFile = path.join(os.homedir(), `.continue`, `config.json`); + + fs.readFile(configFile, `utf-8`, (err, data) => { + if (err) { + console.error('Error reading Continue config file: ', err); + } + + const updatedData = data + ``; + + fs.writeFile(configFile, updatedData, `utf-8`, (err) => { + if (err) { + console.error(`Error writing Continue config file`, err); + return; + } + vscode.window.showInformationMessage(`Updated @Db2-Tables!`) + }) + }) + + } else { + continueAPI?.registerCustomContextProvider(provider); + listDb2TableContextProvider = true; + } } } \ No newline at end of file diff --git a/src/views/jobManager/jobManagerView.ts b/src/views/jobManager/jobManagerView.ts index e967a3a5..71e7caf8 100644 --- a/src/views/jobManager/jobManagerView.ts +++ b/src/views/jobManager/jobManagerView.ts @@ -12,6 +12,7 @@ import { SelfCodesQuickPickItem } from "./selfCodes/selfCodesBrowser"; import { updateStatusBar } from "./statusBar"; import { setCancelButtonVisibility } from "../results"; import { JDBCOptions } from "@ibm/mapepire-js/dist/src/types"; +import { registerDb2iTablesProvider } from "../../aiProviders/continue/listTablesContextProvider"; const selectJobCommand = `vscode-db2i.jobManager.selectJob`; const activeColor = new vscode.ThemeColor(`minimapGutter.addedBackground`); @@ -124,6 +125,9 @@ export class JobManagerView implements TreeDataProvider { try { await selected.job.connect(); + + // re register tables provider with potential new Schema + await registerDb2iTablesProvider(); } catch (e) { window.showErrorMessage(`Failed to start new job with updated properties.`); } From 5beacad72b21e1758d215821bf8c59d035c0a13e Mon Sep 17 00:00:00 2001 From: Adam Shedivy Date: Fri, 20 Dec 2024 12:24:13 -0600 Subject: [PATCH 6/8] just update access info to "save" config --- .../continue/listTablesContextProvider.ts | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/aiProviders/continue/listTablesContextProvider.ts b/src/aiProviders/continue/listTablesContextProvider.ts index 9e4a4d84..b196273c 100644 --- a/src/aiProviders/continue/listTablesContextProvider.ts +++ b/src/aiProviders/continue/listTablesContextProvider.ts @@ -131,23 +131,14 @@ export async function registerDb2iTablesProvider() { // HACK: re register context provider work around // save continue config file to trigger a config reload to update list tables provider const configFile = path.join(os.homedir(), `.continue`, `config.json`); - - fs.readFile(configFile, `utf-8`, (err, data) => { + const now = new Date(); + fs.utimes(configFile, now, now, (err) => { if (err) { - console.error('Error reading Continue config file: ', err); + console.error('Error saving Continue config file:', err); + return; } - - const updatedData = data + ``; - - fs.writeFile(configFile, updatedData, `utf-8`, (err) => { - if (err) { - console.error(`Error writing Continue config file`, err); - return; - } - vscode.window.showInformationMessage(`Updated @Db2-Tables!`) - }) - }) - + vscode.window.showInformationMessage('Updated @Db2-Tables!'); + }); } else { continueAPI?.registerCustomContextProvider(provider); listDb2TableContextProvider = true; From 84413821d16b7bce5913c54ae3464c794a3af62e Mon Sep 17 00:00:00 2001 From: Adam Shedivy Date: Fri, 20 Dec 2024 12:27:42 -0600 Subject: [PATCH 7/8] format code --- .../continue/listTablesContextProvider.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/aiProviders/continue/listTablesContextProvider.ts b/src/aiProviders/continue/listTablesContextProvider.ts index b196273c..41559cbb 100644 --- a/src/aiProviders/continue/listTablesContextProvider.ts +++ b/src/aiProviders/continue/listTablesContextProvider.ts @@ -1,15 +1,13 @@ -import * as vscode from "vscode"; import { ContextItem, ContextProviderDescription, ContextProviderExtras, ContextSubmenuItem, IContextProvider, LoadSubmenuItemsArgs } from "@continuedev/core"; -import { JobInfo } from "../../connection/manager"; +import * as fs from 'fs'; +import * as os from 'os'; +import * as path from 'path'; +import * as vscode from "vscode"; import { JobManager } from "../../config"; -import { isContinueActive } from "./continueContextProvider"; -import { findPossibleTables } from "../context"; -import Statement from "../../database/statement"; +import { JobInfo } from "../../connection/manager"; import Schemas from "../../database/schemas"; import Table from "../../database/table"; -import * as fs from 'fs'; -import * as path from 'path'; -import * as os from 'os'; +import { findPossibleTables } from "../context"; const listDb2Table: ContextProviderDescription = { title: "list Db2i Tables", @@ -113,7 +111,7 @@ class emptyContextProvider implements IContextProvider { async loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise { return []; } - + } export async function registerDb2iTablesProvider() { @@ -124,7 +122,7 @@ export async function registerDb2iTablesProvider() { if (!continueEx.isActive) { await continueEx.activate(); } - + const continueAPI = continueEx?.exports; if (listDb2TableContextProvider) { From 54fe43b80da7ef39181984979e5c4eba52e2ca3d Mon Sep 17 00:00:00 2001 From: Adam Shedivy Date: Fri, 20 Dec 2024 12:28:05 -0600 Subject: [PATCH 8/8] remove empty context provider --- .../continue/listTablesContextProvider.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/aiProviders/continue/listTablesContextProvider.ts b/src/aiProviders/continue/listTablesContextProvider.ts index 41559cbb..9d6ab22e 100644 --- a/src/aiProviders/continue/listTablesContextProvider.ts +++ b/src/aiProviders/continue/listTablesContextProvider.ts @@ -96,24 +96,6 @@ class ListDb2iTables implements IContextProvider { } } -class emptyContextProvider implements IContextProvider { - get description(): ContextProviderDescription { - return { - title: "", - displayTitle: "", - description: "", - type: "normal" - }; - } - async getContextItems(query: string, extras: ContextProviderExtras): Promise { - return []; - } - async loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise { - return []; - } - -} - export async function registerDb2iTablesProvider() { const provider = new ListDb2iTables(); const continueID = `Continue.continue`;