invalidation

This commit is contained in:
Dallin Romney 2025-03-10 21:32:14 -07:00
parent bf9cc74ace
commit eaef8cb2d7
2 changed files with 20 additions and 3 deletions

View file

@ -45,6 +45,7 @@ import {
} from ".";
import { shouldIgnore } from "./indexing/shouldIgnore";
import { walkDirCache } from "./indexing/walkDir";
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
import type { IMessenger, Message } from "./protocol/messenger";
@ -825,6 +826,7 @@ export class Core {
if (!config || config.disableIndexing) {
return; // TODO silent in case of commands?
}
walkDirCache.invalidate();
if (data?.shouldClearIndexes) {
const codebaseIndexer = await this.codebaseIndexerPromise;
await codebaseIndexer.clearIndexes();
@ -852,9 +854,8 @@ export class Core {
// TODO - remove remaining logic for these from IDEs where possible
on("files/changed", async ({ data }) => {
if (data?.uris?.length) {
walkDirCache.invalidate(); // safe approach for now - TODO - only invalidate on relevant changes
for (const uri of data.uris) {
// Listen for file changes in the workspace
// URI TODO is this equality statement valid?
const currentProfileUri =
this.configHandler.currentProfile?.profileDescription.uri ?? "";
@ -887,7 +888,6 @@ export class Core {
uri.endsWith(".gitignore")
) {
// Reindex the workspaces
// walkDirCache.invalidate();
this.invoke("index/forceReIndex", {
shouldClearIndexes: true,
});
@ -926,12 +926,14 @@ export class Core {
on("files/created", async ({ data }) => {
if (data?.uris?.length) {
walkDirCache.invalidate();
void refreshIfNotIgnored(data.uris);
}
});
on("files/deleted", async ({ data }) => {
if (data?.uris?.length) {
walkDirCache.invalidate();
void refreshIfNotIgnored(data.uris);
}
});

View file

@ -55,6 +55,20 @@ class WalkDirCache {
ignore: Promise<Ignore>;
}
> = new Map();
// The super safe approach for now
invalidate() {
this.dirListCache.clear();
this.dirIgnoreCache.clear();
}
// invalidateIgnore(uri: string) {
// this.dirIgnoreCache.delete(uri);
// }
// invalidateParent(uri: string) {
// const splitUri = fileUri.split("/");
// splitUri.pop();
// const parent = splitUri.join("/");
// this.dirListCache.delete(uri);
// }
}
export const walkDirCache = new WalkDirCache(); // todo - singleton approach better?
@ -102,6 +116,7 @@ class DFSWalker {
const stack = [rootContext];
for (let cur = stack.pop(); cur; cur = stack.pop()) {
// No caching approach:
// const entries = await this.ide.listDir(cur.walkableEntry.uri);
// const newIgnore = await getIgnoreContext(
// cur.walkableEntry.uri,