From a758d75c4a5fa5cc690e973c73c926df8d6446d3 Mon Sep 17 00:00:00 2001 From: Josh Vera Date: Mon, 22 Jul 2024 16:22:55 -0400 Subject: [PATCH] Index on file change (#1785) * Reload the submenu items when the context provider data is refreshed * update version * Just call refreshSubmenuItems * remove log statements * cleanup * Remove the Promise declaration * Copy currentFiles to a new dict since we're going to mutate it Don't mutate the caller's currentFiles unexpectedly * Remove reIndexFile and just call index/forceReIndex * We MUST await the refreshCodebaseIndex call * Expose send on core * remove unused import * Reindex the workspaces on save * Call core.send Ideally, we can implement externalRequest on the webview later so we don't have to expose messenger to the VSCode extension * Always refreshSubmenuItems in refreshCodebaseIndex * whitespace * Change messenger back to private --- binary/package-lock.json | 1 + core/core.ts | 12 +++++++++++- core/indexing/refreshIndex.ts | 9 +++++---- extensions/vscode/package-lock.json | 4 ++-- extensions/vscode/package.json | 2 +- extensions/vscode/src/extension/VsCodeExtension.ts | 5 ++++- 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/binary/package-lock.json b/binary/package-lock.json index 41875c6b2..d5108f7ad 100644 --- a/binary/package-lock.json +++ b/binary/package-lock.json @@ -109,6 +109,7 @@ "eslint": "^8", "eslint-plugin-import": "^2.29.1", "jest": "^29.7.0", + "myers-diff": "^2.1.0", "onnxruntime-common": "1.14.0", "onnxruntime-web": "1.14.0", "ts-jest": "^29.1.1" diff --git a/core/core.ts b/core/core.ts index 688f0c8a9..79cfa2a6d 100644 --- a/core/core.ts +++ b/core/core.ts @@ -66,6 +66,14 @@ export class Core { return this.messenger.invoke(messageType, data); } + send( + messageType: T, + data: FromCoreProtocol[T][0], + messageId?: string, + ): string { + return this.messenger.send(messageType, data); + } + // TODO: It shouldn't actually need an IDE type, because this can happen // through the messenger (it does in the case of any non-VS Code IDEs already) constructor( @@ -615,7 +623,7 @@ export class Core { }); on("index/forceReIndex", async (msg) => { const dirs = msg.data ? [msg.data] : await this.ide.getWorkspaceDirs(); - this.refreshCodebaseIndex(dirs); + await this.refreshCodebaseIndex(dirs); }); on("index/setPaused", (msg) => { new GlobalContext().update("indexingPaused", msg.data); @@ -651,6 +659,8 @@ export class Core { this.messenger.request("indexProgress", update); this.indexingState = update; } + + this.messenger.send("refreshSubmenuItems", undefined); } private async shouldReindexDocsOnNewEmbeddingsProvider( diff --git a/core/indexing/refreshIndex.ts b/core/indexing/refreshIndex.ts index 2dcc976d3..db69c8725 100644 --- a/core/indexing/refreshIndex.ts +++ b/core/indexing/refreshIndex.ts @@ -137,6 +137,7 @@ async function getAddRemoveForTag( ] > { const newLastUpdatedTimestamp = Date.now(); + const files = { ...currentFiles }; const saved = await getSavedItemsForTag(tag); @@ -149,12 +150,12 @@ async function getAddRemoveForTag( for (const item of saved) { const { lastUpdated, ...pathAndCacheKey } = item; - if (currentFiles[item.path] === undefined) { + if (files[item.path] === undefined) { // Was indexed, but no longer exists. Remove remove.push(pathAndCacheKey); } else { // Exists in old and new, so determine whether it was updated - if (lastUpdated < currentFiles[item.path]) { + if (lastUpdated < files[item.path]) { // Change was made after last update const newHash = calculateHash(await readFile(pathAndCacheKey.path)); if (pathAndCacheKey.cacheKey !== newHash) { @@ -171,14 +172,14 @@ async function getAddRemoveForTag( } // Remove so we can check leftovers afterward - delete currentFiles[item.path]; + delete files[item.path]; } } // Any leftover in current files need to be added add.push( ...(await Promise.all( - Object.keys(currentFiles).map(async (path) => { + Object.keys(files).map(async (path) => { const fileContents = await readFile(path); return { path, cacheKey: calculateHash(fileContents) }; }), diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 0903bae7e..118fd459d 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.186", + "version": "0.9.189", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.186", + "version": "0.9.189", "license": "Apache-2.0", "dependencies": { "@electron/rebuild": "^3.2.10", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index ce591b2e4..5c727b255 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -1,7 +1,7 @@ { "name": "continue", "icon": "media/icon.png", - "version": "0.9.186", + "version": "0.9.189", "repository": { "type": "git", "url": "https://github.com/continuedev/continue" diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index a4db8ed6d..771b41d1d 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -221,7 +221,7 @@ export class VsCodeExtension { this.configHandler.reloadConfig(); }); - vscode.workspace.onDidSaveTextDocument((event) => { + vscode.workspace.onDidSaveTextDocument(async (event) => { // Listen for file changes in the workspace const filepath = event.uri.fsPath; @@ -254,6 +254,9 @@ export class VsCodeExtension { ) { // Update embeddings! (TODO) } + + // Reindex the workspaces + this.core.invoke("index/forceReIndex", undefined); }); // When GitHub sign-in status changes, reload config