index files test

This commit is contained in:
Dallin Romney 2024-11-14 19:42:46 -08:00
parent 77aa657d8b
commit 6e5301657a
2 changed files with 26 additions and 1 deletions

View file

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

View file

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