diff --git a/core/indexing/CodebaseIndexer.test.ts b/core/indexing/CodebaseIndexer.test.ts index 5b59c39fa..ee2f108f7 100644 --- a/core/indexing/CodebaseIndexer.test.ts +++ b/core/indexing/CodebaseIndexer.test.ts @@ -89,7 +89,7 @@ describe("CodebaseIndexer", () => { const abortSignal = abortController.signal; const updates = []; - for await (const update of codebaseIndexer.refresh( + for await (const update of codebaseIndexer.refreshDirs( [TEST_DIR], abortSignal, )) { @@ -98,6 +98,16 @@ describe("CodebaseIndexer", () => { return updates; } + async function refreshIndexFiles(files: string[]) { + const updates = []; + for await (const update of codebaseIndexer.refreshFiles( + files, + )) { + updates.push(update); + } + return updates; + } + async function getAllIndexedFiles() { const files = await testIndex.getIndexedFilesForTags( await testIde.getTags(testIndex.artifactId), @@ -158,6 +168,15 @@ describe("CodebaseIndexer", () => { expect(indexed.some((file) => file.endsWith("main.py"))).toBe(true); }); + test("should successfuly re-index specific files", async () => { + // Could add more specific tests for this but uses similar logic + const before = await getAllIndexedFiles(); + await refreshIndexFiles(before); + + const after = await getAllIndexedFiles(); + expect(after.length).toBe(before.length); + }); + test("should successfully re-index after adding a file", async () => { addToTestDir([["main.rs", TEST_RS]]); diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index bb46e7466..84d0a667c 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -309,6 +309,12 @@ export class VsCodeExtension { }); }); + vscode.workspace.onDidCreateFiles(async (event) => { + this.core.invoke("index/forceReIndexFiles", { + files: event.files.map((file) => file.fsPath), + }); + }); + // When GitHub sign-in status changes, reload config vscode.authentication.onDidChangeSessions(async (e) => { if (e.provider.id === "github") {