Skip to content

Commit

Permalink
workaround for updating context provider schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ajshedivy committed Dec 20, 2024
1 parent 8e7501f commit 76a600e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/aiProviders/continue/listTablesContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -15,6 +18,8 @@ const listDb2Table: ContextProviderDescription = {
type: "submenu"
}

export let listDb2TableContextProvider: Boolean = false;

class ListDb2iTables implements IContextProvider {
get description(): ContextProviderDescription {
return listDb2Table;
Expand Down Expand Up @@ -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<ContextItem[]> {
return [];
}
async loadSubmenuItems(args: LoadSubmenuItemsArgs): Promise<ContextSubmenuItem[]> {
return [];
}

}

export async function registerDb2iTablesProvider() {
const provider = new ListDb2iTables();
const continueID = `Continue.continue`;
Expand All @@ -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;
}
}
}
4 changes: 4 additions & 0 deletions src/views/jobManager/jobManagerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -124,6 +125,9 @@ export class JobManagerView implements TreeDataProvider<any> {

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.`);
}
Expand Down

0 comments on commit 76a600e

Please sign in to comment.