From 7a01d29b1bde7e44272d5d0edb373ef2a28ce56a Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 12 Mar 2024 01:17:06 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20polish=20code=20context=20provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config/load.ts | 38 ++++---------------- core/index.d.ts | 4 ++- core/indexing/CodeSnippetsIndex.ts | 4 +-- docs/docs/customization/context-providers.md | 10 +++++- extensions/vscode/config_schema.json | 6 ++-- 5 files changed, 24 insertions(+), 38 deletions(-) diff --git a/core/config/load.ts b/core/config/load.ts index d0df1aa06..e30980b4b 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -88,36 +88,12 @@ function loadSerializedConfig( config.allowAnonymousTelemetry = true; } - migrate("codebaseContextProvider", () => { - if ( - !config.contextProviders?.filter((cp) => cp.name === "codebase")?.length - ) { + migrate("codeContextProvider", () => { + if (!config.contextProviders?.filter((cp) => cp.name === "code")?.length) { config.contextProviders = [ ...(config.contextProviders || []), { - name: "codebase", - params: {}, - }, - ]; - } - - if (!config.embeddingsProvider) { - config.embeddingsProvider = { - provider: "transformers.js", - }; - } - - fs.writeFileSync(configPath, JSON.stringify(config, undefined, 2), "utf8"); - }); - - migrate("problemsContextProvider", () => { - if ( - !config.contextProviders?.filter((cp) => cp.name === "problems")?.length - ) { - config.contextProviders = [ - ...(config.contextProviders || []), - { - name: "problems", + name: "code", params: {}, }, ]; @@ -126,14 +102,12 @@ function loadSerializedConfig( fs.writeFileSync(configPath, JSON.stringify(config, undefined, 2), "utf8"); }); - migrate("foldersContextProvider", () => { - if ( - !config.contextProviders?.filter((cp) => cp.name === "folder")?.length - ) { + migrate("docsContextProvider1", () => { + if (!config.contextProviders?.filter((cp) => cp.name === "docs")?.length) { config.contextProviders = [ ...(config.contextProviders || []), { - name: "folder", + name: "docs", params: {}, }, ]; diff --git a/core/index.d.ts b/core/index.d.ts index 475fa60f5..18f88a2cd 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -426,7 +426,9 @@ type ContextProviderName = | "folder" | "jira" | "postgres" - | "database"; + | "database" + | "code" + | "docs"; type TemplateType = | "llama2" diff --git a/core/indexing/CodeSnippetsIndex.ts b/core/indexing/CodeSnippetsIndex.ts index 7694e6cc4..c1ab1c68d 100644 --- a/core/indexing/CodeSnippetsIndex.ts +++ b/core/indexing/CodeSnippetsIndex.ts @@ -155,7 +155,7 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { for (const snippet of snippetsWithPath) { await db.run( - `INSERT INTO code_snippet_tags (snippetId, tag) VALUES (?, ?)`, + `INSERT INTO code_snippets_tags (snippetId, tag) VALUES (?, ?)`, [snippet.id, tagString], ); } @@ -195,7 +195,7 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { const db = await SqliteDb.get(); try { const rows = await db.all( - `SELECT * + `SELECT cs.id, cs.path, cs.title FROM code_snippets cs JOIN code_snippets_tags cst ON cs.id = cst.snippetId WHERE cst.tag = ?; diff --git a/docs/docs/customization/context-providers.md b/docs/docs/customization/context-providers.md index d3985be04..3328f2fbb 100644 --- a/docs/docs/customization/context-providers.md +++ b/docs/docs/customization/context-providers.md @@ -16,6 +16,14 @@ As an example, say you are working on solving a new GitHub Issue. You type '@iss To use any of the built-in context providers, open `~/.continue/config.json` and add it to the `contextProviders` list. +### Code + +Type '@code' to reference specific functions or classes from throughout your project. + +`````json +{ "name": "code" } +``` + ### Git Diff Type '@diff' to reference all of the changes you've made to your current branch. This is useful if you want to summarize what you've done or ask for a general review of your work before committing. @@ -145,7 +153,7 @@ By default, the following query will be used to find issues: ```jql assignee = currentUser() AND resolution = Unresolved order by updated DESC -```` +````` You can override this query by setting the `issueQuery` parameter. diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index f41430f78..13e77c8c7 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -1045,7 +1045,8 @@ "tree", "highlights", "outline", - "postgres" + "postgres", + "code" ], "markdownEnumDescriptions": [ "Reference the contents of the current changes as given by `git diff`", @@ -1064,7 +1065,8 @@ "Include a repo map showing important code objects", "Displays important snippets of code from the currently open files", "Displays definition lines from the currently open files", - "References Postgres table schema and sample rows" + "References Postgres table schema and sample rows", + "Reference specific functions and classes from throughout your codebase" ], "type": "string" },