From 0770b21dbfe984954605ebeeabb191ac31db15e4 Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 7 May 2025 13:45:02 -0700 Subject: [PATCH 1/6] fix(files-context)-refresh-on-new-file-and-save --- core/core.ts | 97 +++++++++++++++++++++ core/index.d.ts | 4 +- core/tools/implementations/createNewFile.ts | 4 + 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/core/core.ts b/core/core.ts index 4fabefed3..648b1ed40 100644 --- a/core/core.ts +++ b/core/core.ts @@ -708,6 +708,7 @@ export class Core { tool, toolCallId: toolCall.id, onPartialOutput, + core: this, // Add a reference to the Core instance }); }); @@ -1008,4 +1009,100 @@ export class Core { return []; } }; + + private indexingCancellationController: AbortController | undefined; + private async sendIndexingErrorTelemetry(update: IndexingProgressUpdate) { + console.debug( + "Indexing failed with error: ", + update.desc, + update.debugInfo, + ); + void Telemetry.capture( + "indexing_error", + { + error: update.desc, + stack: update.debugInfo, + }, + false, + ); + } + + private async refreshCodebaseIndex(paths: string[]) { + if (this.indexingCancellationController) { + this.indexingCancellationController.abort(); + } + this.indexingCancellationController = new AbortController(); + try { + for await (const update of ( + await this.codebaseIndexerPromise + ).refreshDirs(paths, this.indexingCancellationController.signal)) { + let updateToSend = { ...update }; + + void this.messenger.request("indexProgress", updateToSend); + this.codebaseIndexingState = updateToSend; + + if (update.status === "failed") { + void this.sendIndexingErrorTelemetry(update); + } + } + } catch (e: any) { + console.log(`Failed refreshing codebase index directories : ${e}`); + this.handleIndexingError(e); + } + + this.messenger.send("refreshSubmenuItems", { + providers: "dependsOnIndexing", + }); + this.indexingCancellationController = undefined; + } + + private async refreshCodebaseIndexFiles(files: string[]) { + // Can be cancelled by codebase index but not vice versa + if ( + this.indexingCancellationController && + !this.indexingCancellationController.signal.aborted + ) { + return; + } + this.indexingCancellationController = new AbortController(); + try { + for await (const update of ( + await this.codebaseIndexerPromise + ).refreshFiles(files)) { + let updateToSend = { ...update }; + + void this.messenger.request("indexProgress", updateToSend); + this.codebaseIndexingState = updateToSend; + + if (update.status === "failed") { + void this.sendIndexingErrorTelemetry(update); + } + } + } catch (e: any) { + console.log(`Failed refreshing codebase index files : ${e}`); + this.handleIndexingError(e); + } + + this.messenger.send("refreshSubmenuItems", { + providers: "dependsOnIndexing", + }); + this.indexingCancellationController = undefined; + } + + // private + handleIndexingError(e: any) { + if (e instanceof LLMError) { + // Need to report this specific error to the IDE for special handling + void this.messenger.request("reportError", e); + } + // broadcast indexing error + let updateToSend: IndexingProgressUpdate = { + progress: 0, + status: "failed", + desc: e.message, + }; + void this.messenger.request("indexProgress", updateToSend); + this.codebaseIndexingState = updateToSend; + void this.sendIndexingErrorTelemetry(updateToSend); + } } diff --git a/core/index.d.ts b/core/index.d.ts index ad778d3d8..195ab6c47 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -5,6 +5,8 @@ import { } from "@continuedev/config-yaml"; import Parser from "web-tree-sitter"; import { LLMConfigurationStatuses } from "./llm/constants"; +import { GetGhTokenArgs } from "./protocol/ide"; +import { Core } from "./core"; declare global { interface Window { @@ -968,7 +970,7 @@ export interface ToolExtras { toolCallId: string; contextItems: ContextItem[]; }) => void; - config: ContinueConfig; + core?: Core; // Reference to the Core instance } export interface Tool { diff --git a/core/tools/implementations/createNewFile.ts b/core/tools/implementations/createNewFile.ts index 5a89141eb..4e211b32e 100644 --- a/core/tools/implementations/createNewFile.ts +++ b/core/tools/implementations/createNewFile.ts @@ -17,6 +17,10 @@ export const createNewFileImpl: ToolImpl = async (args, extras) => { } await extras.ide.writeFile(resolvedFileUri, args.contents); await extras.ide.openFile(resolvedFileUri); + await extras.ide.saveFile(resolvedFileUri); + if (extras.core) { + await extras.core.refreshCodebaseIndexFiles([resolvedFileUri]); + } return [ { name: getUriPathBasename(resolvedFileUri), From b27420981e976a8e98f10d63237c893c1bc8cccb Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 4 Jun 2025 17:47:48 -0700 Subject: [PATCH 2/6] refactor to using CodeBaseIndexer instead of Core --- core/core.ts | 81 +------------------------------------------------ core/index.d.ts | 3 +- 2 files changed, 3 insertions(+), 81 deletions(-) diff --git a/core/core.ts b/core/core.ts index 648b1ed40..992b930eb 100644 --- a/core/core.ts +++ b/core/core.ts @@ -708,7 +708,7 @@ export class Core { tool, toolCallId: toolCall.id, onPartialOutput, - core: this, // Add a reference to the Core instance + codeBaseIndexer: this.codeBaseIndexer, }); }); @@ -1026,83 +1026,4 @@ export class Core { false, ); } - - private async refreshCodebaseIndex(paths: string[]) { - if (this.indexingCancellationController) { - this.indexingCancellationController.abort(); - } - this.indexingCancellationController = new AbortController(); - try { - for await (const update of ( - await this.codebaseIndexerPromise - ).refreshDirs(paths, this.indexingCancellationController.signal)) { - let updateToSend = { ...update }; - - void this.messenger.request("indexProgress", updateToSend); - this.codebaseIndexingState = updateToSend; - - if (update.status === "failed") { - void this.sendIndexingErrorTelemetry(update); - } - } - } catch (e: any) { - console.log(`Failed refreshing codebase index directories : ${e}`); - this.handleIndexingError(e); - } - - this.messenger.send("refreshSubmenuItems", { - providers: "dependsOnIndexing", - }); - this.indexingCancellationController = undefined; - } - - private async refreshCodebaseIndexFiles(files: string[]) { - // Can be cancelled by codebase index but not vice versa - if ( - this.indexingCancellationController && - !this.indexingCancellationController.signal.aborted - ) { - return; - } - this.indexingCancellationController = new AbortController(); - try { - for await (const update of ( - await this.codebaseIndexerPromise - ).refreshFiles(files)) { - let updateToSend = { ...update }; - - void this.messenger.request("indexProgress", updateToSend); - this.codebaseIndexingState = updateToSend; - - if (update.status === "failed") { - void this.sendIndexingErrorTelemetry(update); - } - } - } catch (e: any) { - console.log(`Failed refreshing codebase index files : ${e}`); - this.handleIndexingError(e); - } - - this.messenger.send("refreshSubmenuItems", { - providers: "dependsOnIndexing", - }); - this.indexingCancellationController = undefined; - } - - // private - handleIndexingError(e: any) { - if (e instanceof LLMError) { - // Need to report this specific error to the IDE for special handling - void this.messenger.request("reportError", e); - } - // broadcast indexing error - let updateToSend: IndexingProgressUpdate = { - progress: 0, - status: "failed", - desc: e.message, - }; - void this.messenger.request("indexProgress", updateToSend); - this.codebaseIndexingState = updateToSend; - void this.sendIndexingErrorTelemetry(updateToSend); - } } diff --git a/core/index.d.ts b/core/index.d.ts index 195ab6c47..3613344ea 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -7,6 +7,7 @@ import Parser from "web-tree-sitter"; import { LLMConfigurationStatuses } from "./llm/constants"; import { GetGhTokenArgs } from "./protocol/ide"; import { Core } from "./core"; +import { CodebaseIndexer } from "./indexing/CodebaseIndexer"; declare global { interface Window { @@ -970,7 +971,7 @@ export interface ToolExtras { toolCallId: string; contextItems: ContextItem[]; }) => void; - core?: Core; // Reference to the Core instance + codeBaseIndexer?: CodebaseIndexer; } export interface Tool { From 41975879fd54bcdee922ef6b306ef26cee50c71c Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 4 Jun 2025 17:52:56 -0700 Subject: [PATCH 3/6] More cleanup --- core/core.ts | 17 ----------------- core/index.d.ts | 1 + 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/core/core.ts b/core/core.ts index 992b930eb..fdcf9ee58 100644 --- a/core/core.ts +++ b/core/core.ts @@ -1009,21 +1009,4 @@ export class Core { return []; } }; - - private indexingCancellationController: AbortController | undefined; - private async sendIndexingErrorTelemetry(update: IndexingProgressUpdate) { - console.debug( - "Indexing failed with error: ", - update.desc, - update.debugInfo, - ); - void Telemetry.capture( - "indexing_error", - { - error: update.desc, - stack: update.debugInfo, - }, - false, - ); - } } diff --git a/core/index.d.ts b/core/index.d.ts index 3613344ea..0226e236f 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -971,6 +971,7 @@ export interface ToolExtras { toolCallId: string; contextItems: ContextItem[]; }) => void; + config: ContinueConfig; codeBaseIndexer?: CodebaseIndexer; } From 26c3771b5aae545a9bfbe1d2c8aeb79208f2d27f Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 4 Jun 2025 17:55:34 -0700 Subject: [PATCH 4/6] more cleanup --- core/index.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index 0226e236f..c24487a55 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -4,10 +4,8 @@ import { PromptTemplates, } from "@continuedev/config-yaml"; import Parser from "web-tree-sitter"; -import { LLMConfigurationStatuses } from "./llm/constants"; -import { GetGhTokenArgs } from "./protocol/ide"; -import { Core } from "./core"; import { CodebaseIndexer } from "./indexing/CodebaseIndexer"; +import { LLMConfigurationStatuses } from "./llm/constants"; declare global { interface Window { From f1a44194fb3d6bfdb657f79d26c343f1ea0c280d Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 4 Jun 2025 18:04:08 -0700 Subject: [PATCH 5/6] more cleanup --- core/indexing/CodebaseIndexer.test.ts | 2 +- core/indexing/CodebaseIndexer.ts | 6 ++++-- core/tools/implementations/createNewFile.ts | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/indexing/CodebaseIndexer.test.ts b/core/indexing/CodebaseIndexer.test.ts index 7ba08594d..b697520aa 100644 --- a/core/indexing/CodebaseIndexer.test.ts +++ b/core/indexing/CodebaseIndexer.test.ts @@ -278,7 +278,7 @@ describe("CodebaseIndexer", () => { expect.anything(), ); expect(mockMessenger.send).toHaveBeenCalledWith("refreshSubmenuItems", { - providers: "dependsOnIndexing", + providers: "all", }); }); diff --git a/core/indexing/CodebaseIndexer.ts b/core/indexing/CodebaseIndexer.ts index 719c95aec..db4bdd9ca 100644 --- a/core/indexing/CodebaseIndexer.ts +++ b/core/indexing/CodebaseIndexer.ts @@ -596,7 +596,7 @@ export class CodebaseIndexer { // Directly refresh submenu items if (this.messenger) { this.messenger.send("refreshSubmenuItems", { - providers: "dependsOnIndexing", + providers: "all", }); } this.indexingCancellationController = undefined; @@ -626,7 +626,9 @@ export class CodebaseIndexer { // Directly refresh submenu items if (this.messenger) { - this.messenger.send("refreshSubmenuItems", { providers: "all" }); + this.messenger.send("refreshSubmenuItems", { + providers: "all", + }); } this.indexingCancellationController = undefined; } diff --git a/core/tools/implementations/createNewFile.ts b/core/tools/implementations/createNewFile.ts index 4e211b32e..2818dc4b2 100644 --- a/core/tools/implementations/createNewFile.ts +++ b/core/tools/implementations/createNewFile.ts @@ -18,8 +18,8 @@ export const createNewFileImpl: ToolImpl = async (args, extras) => { await extras.ide.writeFile(resolvedFileUri, args.contents); await extras.ide.openFile(resolvedFileUri); await extras.ide.saveFile(resolvedFileUri); - if (extras.core) { - await extras.core.refreshCodebaseIndexFiles([resolvedFileUri]); + if (extras.codeBaseIndexer) { + await extras.codeBaseIndexer?.refreshCodebaseIndexFiles([resolvedFileUri]); } return [ { From 0c7cecd53d33d28fc16afb9abd70eb2f669b52ec Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 4 Jun 2025 22:02:59 -0700 Subject: [PATCH 6/6] Updates to use codebase indexer --- core/indexing/CodebaseIndexer.ts | 2 +- core/tools/implementations/createNewFile.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/indexing/CodebaseIndexer.ts b/core/indexing/CodebaseIndexer.ts index db4bdd9ca..0a0432ccf 100644 --- a/core/indexing/CodebaseIndexer.ts +++ b/core/indexing/CodebaseIndexer.ts @@ -552,7 +552,7 @@ export class CodebaseIndexer { private async updateProgress(update: IndexingProgressUpdate) { this.codebaseIndexingState = update; if (this.messenger) { - await this.messenger.request("indexProgress", update); + void this.messenger.request("indexProgress", update); } } diff --git a/core/tools/implementations/createNewFile.ts b/core/tools/implementations/createNewFile.ts index 2818dc4b2..5b18f03d3 100644 --- a/core/tools/implementations/createNewFile.ts +++ b/core/tools/implementations/createNewFile.ts @@ -19,7 +19,7 @@ export const createNewFileImpl: ToolImpl = async (args, extras) => { await extras.ide.openFile(resolvedFileUri); await extras.ide.saveFile(resolvedFileUri); if (extras.codeBaseIndexer) { - await extras.codeBaseIndexer?.refreshCodebaseIndexFiles([resolvedFileUri]); + void extras.codeBaseIndexer?.refreshCodebaseIndexFiles([resolvedFileUri]); } return [ {