-
Notifications
You must be signed in to change notification settings - Fork 52
list tables context provider #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4b64307
fix column null context
ajshedivy 171f679
WIP: list tables context provider
ajshedivy 4379888
add schema context item to menu
ajshedivy f95719a
Merge branch 'main' into fix/continue-context
ajshedivy 8e7501f
use internal APIs for querying table meta data
ajshedivy 76a600e
workaround for updating context provider schema
ajshedivy 5beacad
just update access info to "save" config
ajshedivy 8441382
format code
ajshedivy 54fe43b
remove empty context provider
ajshedivy e8b8aca
Merge branch 'main' into fix/continue-context
ajshedivy fc05435
cleanup list tables provider
ajshedivy b8ab3b8
use binding parameter
ajshedivy c7d4a9f
move register tables provider to refresh function
ajshedivy fc83050
check if schema has changed, then update provider
ajshedivy 14846f7
fix typo
ajshedivy 5ba9b37
improve checks for current job and current schema
ajshedivy 9ff1e73
add optional chaining operator to selected job
ajshedivy b0aa3c2
clean up logic
ajshedivy e03b84e
use same case in comparison
ajshedivy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import { | ||
| ContextItem, | ||
| ContextProviderDescription, | ||
| ContextProviderExtras, | ||
| ContextSubmenuItem, | ||
| IContextProvider, | ||
| LoadSubmenuItemsArgs, | ||
| } from "@continuedev/core"; | ||
| import * as fs from "fs"; | ||
| import * as os from "os"; | ||
| import * as path from "path"; | ||
| import * as vscode from "vscode"; | ||
| import Schemas from "../../database/schemas"; | ||
| import Table from "../../database/table"; | ||
| import { | ||
| createContinueContextItems, | ||
| findPossibleTables, | ||
| refsToMarkdown, | ||
| } from "../context"; | ||
|
|
||
| const listDb2Table: ContextProviderDescription = { | ||
| title: "list Db2i Tables", | ||
| displayTitle: "Db2i-tables", | ||
| description: "Add Db2i Table info to Context", | ||
| type: "submenu", | ||
| }; | ||
|
|
||
| export let provider: ListDb2iTables = undefined; | ||
|
|
||
| class ListDb2iTables implements IContextProvider { | ||
| constructor(private schema: string) { | ||
| this.schema = schema; | ||
| } | ||
|
|
||
| get description(): ContextProviderDescription { | ||
| return listDb2Table; | ||
| } | ||
|
|
||
| setCurrentSchema(schema: string) { | ||
| this.schema = schema; | ||
| } | ||
|
|
||
| getCurrentSchema() { | ||
| return this.schema; | ||
| } | ||
|
|
||
| async getColumnInfoForAllTables(schema: string) { | ||
| 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<ContextItem[]> { | ||
| let contextItems: ContextItem[] = []; | ||
| if (query.toUpperCase() === this.schema.toUpperCase()) { | ||
| const tableInfo = await this.getColumnInfoForAllTables(this.schema); | ||
| contextItems.push({ | ||
| name: `Info for all tables in ${this.schema}`, | ||
| 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, | ||
| this.schema, | ||
| query.split(` `) | ||
| ); | ||
| const markdownRefs = refsToMarkdown(tableInfo); | ||
|
|
||
| // add additional context for working with Db2 for i tables | ||
| contextItems.push({ | ||
| name: `Instructions`, | ||
| content: `Db2 for i table Assistant: The following information is based on the ${query} table within the ${this.schema} schema. Utilize the provided schema and table metadata to assist the user. Only use valid Db2 for i SQL syntax and conventions. If input is unclear ask user to clarify`, | ||
| description: "instructions for working with Db2 for i tables", | ||
| }); | ||
|
|
||
| contextItems.push(...createContinueContextItems(markdownRefs)); | ||
| } | ||
| return contextItems; | ||
| } | ||
|
|
||
| async loadSubmenuItems( | ||
| args: LoadSubmenuItemsArgs | ||
| ): Promise<ContextSubmenuItem[]> { | ||
| const tables: BasicSQLObject[] = await Schemas.getObjects(this.schema, [ | ||
| `tables`, | ||
| ]); | ||
|
|
||
| const schemaSubmenuItem: ContextSubmenuItem = { | ||
| id: this.schema, | ||
| title: this.schema, | ||
| description: `All table info in schema: ${this.schema}`, | ||
| }; | ||
|
|
||
| const tableSubmenuItems: ContextSubmenuItem[] = tables.map((table) => ({ | ||
| id: table.name, | ||
| title: table.name, | ||
| description: `${table.schema}-${table.name}`, | ||
| })); | ||
|
|
||
| return [schemaSubmenuItem, ...tableSubmenuItems]; | ||
| } | ||
| } | ||
|
|
||
| export async function registerDb2iTablesProvider(schema?: string) { | ||
| if (!schema) { | ||
| return; | ||
| } | ||
| const continueID = `Continue.continue`; | ||
| const continueEx = vscode.extensions.getExtension(continueID); | ||
| if (continueEx) { | ||
| if (!continueEx.isActive) { | ||
| await continueEx.activate(); | ||
| } | ||
|
|
||
| if (provider) { | ||
| provider.setCurrentSchema(schema); | ||
| // save continue config file to trigger a config reload to update list tables provider | ||
| const configFile = path.join(os.homedir(), `.continue`, `config.json`); | ||
| const now = new Date(); | ||
| fs.utimes(configFile, now, now, (err) => { | ||
| if (err) { | ||
| console.error("Error saving Continue config file:", err); | ||
| return; | ||
| } | ||
| }); | ||
| } else { | ||
| const continueAPI = continueEx?.exports; | ||
| provider = new ListDb2iTables(schema); | ||
| continueAPI?.registerCustomContextProvider(provider); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.