* 🎨 refactor out react context * 🎨 refactor local storage * 🎨 refactor IdeMessenger * 🔥 removing unused files * 🚚 move scripts * ✅ setup VSCode integration testing * 🎨 fix test-related stuff * 🚧 testing * 🎨 tweak terminal cmd+L * 🧑💻 install biome in core * 🎨 run biome check on core * 🎨 run biome check in vscode * 🎨 run biome check in binary * 🧑💻 global biome config * 🎨 run biome check on core * 🎨 run biome check in vscode * 🎨 fix a few biome warnings * 🚧 WIP on protocols * 🚧 progress, organizing, about to remove webviewCore protocol * 🚧 now running * 🚧 move indexing code to core * 🚧 WIP on JetBrains indexing implementation * 🎨 finish listDir * 🚧 gui fixes * 🏷️ update IMessenger.on return type * 🐛 fix jetbrains types + IDE detection * 🧑💻 set up debugging for binary with TcpMessenger * 👷 fix prepackage.js * 🧑💻 turn off debug mode for intellij * 🐛 merge fixes * 🐛 fixes after refactor * 🐛 merge fixes * 💄 increase font size in JB * 🔀 merge changes * 🩹 small fixes * 🐛 fix jetbrains build * 🩹 more jetbrains fixes * 🎨 jetbrains improvements * 🐛 fix lancedb prob in jetbrains build * 👷 update jetbrains build process * ✨ intellij problems context provider * 👷 add script utils file * 💚 fix jetbrains build regression * 🎨 dynamic import transformers.js * 🩹 small jetbrains updates * ✨ folder context provider in jetbrains * 🎨 many more jetbrains improvements * 🔀 merge fixes * ⚡️ small improvements * 🎨 tell users transformers.js not supported * 🎨 trial updates * 📝 update jetbrains readmej * ⚡️ only use smaller context for local autocomplete models * ⚡️ improve bracket filter * ✨ global .continue/.prompts folder * 💄 improved model setup process * 🥅 display VSCode req errs
124 lines
3.3 KiB
TypeScript
124 lines
3.3 KiB
TypeScript
import {
|
|
ContextItem,
|
|
ContextProviderDescription,
|
|
ContextProviderExtras,
|
|
ContextSubmenuItem,
|
|
LoadSubmenuItemsArgs,
|
|
} from "../../index.js";
|
|
import { BaseContextProvider } from "../index.js";
|
|
|
|
class DatabaseContextProvider extends BaseContextProvider {
|
|
static description: ContextProviderDescription = {
|
|
title: "database",
|
|
displayTitle: "Database",
|
|
description: "Table schemas",
|
|
type: "submenu",
|
|
};
|
|
|
|
async getContextItems(
|
|
query: string,
|
|
extras: ContextProviderExtras,
|
|
): Promise<ContextItem[]> {
|
|
const contextItems: ContextItem[] = [];
|
|
|
|
const connections = this.options?.connections;
|
|
|
|
if (connections === null) {
|
|
return contextItems;
|
|
}
|
|
|
|
const [connectionName, table] = query.split(".");
|
|
|
|
const getDatabaseAdapter = await require("dbinfoz");
|
|
|
|
for (const connection of connections) {
|
|
if (connection.name === connectionName) {
|
|
const adapter = getDatabaseAdapter(
|
|
connection.connection_type,
|
|
connection.connection,
|
|
);
|
|
const tablesAndSchemas = await adapter.getAllTablesAndSchemas(
|
|
connection.connection.database,
|
|
);
|
|
|
|
if (table === "all") {
|
|
let prompt = `Schema for all tables on ${connection.connection_type} is `;
|
|
prompt += JSON.stringify(tablesAndSchemas);
|
|
|
|
const contextItem = {
|
|
name: `${connectionName}-all-tables-schemas`,
|
|
description: "Schema for all tables.",
|
|
content: prompt,
|
|
};
|
|
|
|
contextItems.push(contextItem);
|
|
} else {
|
|
const tables = Object.keys(tablesAndSchemas);
|
|
|
|
tables.forEach((tableName) => {
|
|
if (table === tableName) {
|
|
let prompt = `Schema for ${tableName} on ${connection.connection_type} is `;
|
|
prompt += JSON.stringify(tablesAndSchemas[tableName]);
|
|
|
|
const contextItem = {
|
|
name: `${connectionName}-${tableName}-schema`,
|
|
description: `${tableName} Schema`,
|
|
content: prompt,
|
|
};
|
|
|
|
contextItems.push(contextItem);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
return contextItems;
|
|
}
|
|
|
|
async loadSubmenuItems(
|
|
args: LoadSubmenuItemsArgs,
|
|
): Promise<ContextSubmenuItem[]> {
|
|
const contextItems: ContextSubmenuItem[] = [];
|
|
const connections = this.options?.connections;
|
|
|
|
if (connections === null) {
|
|
return contextItems;
|
|
}
|
|
|
|
const getDatabaseAdapter = await require("dbinfoz");
|
|
|
|
for (const connection of connections) {
|
|
const adapter = getDatabaseAdapter(
|
|
connection.connection_type,
|
|
connection.connection,
|
|
);
|
|
const tablesAndSchemas = await adapter.getAllTablesAndSchemas(
|
|
connection.connection.database,
|
|
);
|
|
const tables = Object.keys(tablesAndSchemas);
|
|
|
|
const contextItem = {
|
|
id: `${connection.name}.all`,
|
|
title: `${connection.name} all table schemas`,
|
|
description: "",
|
|
};
|
|
|
|
contextItems.push(contextItem);
|
|
|
|
tables.forEach((tableName) => {
|
|
const contextItem = {
|
|
id: `${connection.name}.${tableName}`,
|
|
title: `${connection.name}.${tableName} schema`,
|
|
description: "",
|
|
};
|
|
|
|
contextItems.push(contextItem);
|
|
});
|
|
}
|
|
|
|
return contextItems;
|
|
}
|
|
}
|
|
|
|
export default DatabaseContextProvider;
|