fix(files-context)-refresh-on-new-file-and-save

This commit is contained in:
chezsmithy 2025-05-07 13:45:02 -07:00
parent 3c5332ac0a
commit 0770b21dbf
3 changed files with 104 additions and 1 deletions

View file

@ -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);
}
}

4
core/index.d.ts vendored
View file

@ -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 {

View file

@ -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),