refresh index for files
This commit is contained in:
parent
7e6deb6c6b
commit
2bb2e65575
7 changed files with 133 additions and 43 deletions
80
core/core.ts
80
core/core.ts
|
|
@ -83,7 +83,7 @@ export class Core {
|
|||
constructor(
|
||||
private readonly messenger: IMessenger<ToCoreProtocol, FromCoreProtocol>,
|
||||
private readonly ide: IDE,
|
||||
private readonly onWrite: (text: string) => Promise<void> = async () => { },
|
||||
private readonly onWrite: (text: string) => Promise<void> = async () => {},
|
||||
) {
|
||||
// Ensure .continue directory is created
|
||||
setupInitialDotContinueDirectory();
|
||||
|
|
@ -174,7 +174,7 @@ export class Core {
|
|||
this.configHandler,
|
||||
ide,
|
||||
getLlm,
|
||||
(e) => { },
|
||||
(e) => {},
|
||||
(..._) => Promise.resolve([]),
|
||||
);
|
||||
|
||||
|
|
@ -684,9 +684,14 @@ export class Core {
|
|||
await codebaseIndexer.clearIndexes();
|
||||
}
|
||||
|
||||
const dirs = data?.dirs ?? await this.ide.getWorkspaceDirs();
|
||||
const dirs = data?.dirs ?? (await this.ide.getWorkspaceDirs());
|
||||
await this.refreshCodebaseIndex(dirs);
|
||||
});
|
||||
on("index/forceReIndexFiles", async ({ data }) => {
|
||||
if (data?.files?.length) {
|
||||
await this.refreshCodebaseIndexFiles(data.files);
|
||||
}
|
||||
});
|
||||
on("index/setPaused", (msg) => {
|
||||
new GlobalContext().update("indexingPaused", msg.data);
|
||||
this.indexingPauseToken.paused = msg.data;
|
||||
|
|
@ -722,14 +727,29 @@ export class Core {
|
|||
}
|
||||
|
||||
private indexingCancellationController: AbortController | undefined;
|
||||
private async sendIndexingTelemetry(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(dirs: string[]) {
|
||||
private async refreshCodebaseIndex(paths: string[]) {
|
||||
if (this.indexingCancellationController) {
|
||||
this.indexingCancellationController.abort();
|
||||
}
|
||||
this.indexingCancellationController = new AbortController();
|
||||
for await (const update of (await this.codebaseIndexerPromise).refresh(
|
||||
dirs,
|
||||
for await (const update of (await this.codebaseIndexerPromise).refreshDirs(
|
||||
paths,
|
||||
this.indexingCancellationController.signal,
|
||||
)) {
|
||||
let updateToSend = { ...update };
|
||||
|
|
@ -743,19 +763,41 @@ export class Core {
|
|||
this.indexingState = updateToSend;
|
||||
|
||||
if (update.status === "failed") {
|
||||
console.debug(
|
||||
"Indexing failed with error: ",
|
||||
update.desc,
|
||||
update.debugInfo,
|
||||
);
|
||||
void Telemetry.capture(
|
||||
"indexing_error",
|
||||
{
|
||||
error: update.desc,
|
||||
stack: update.debugInfo,
|
||||
},
|
||||
false,
|
||||
);
|
||||
void this.sendIndexingTelemetry(update);
|
||||
}
|
||||
}
|
||||
|
||||
this.messenger.send("refreshSubmenuItems", undefined);
|
||||
}
|
||||
|
||||
private async refreshCodebaseIndexFiles(files: string[]) {
|
||||
// Can be cancelled by codebase index but not vice versa
|
||||
if (
|
||||
this.indexingCancellationController &&
|
||||
!this.indexingCancellationController.signal.aborted
|
||||
) {
|
||||
return console.debug(
|
||||
"Codebase indexing already in progress, skipping indexing of files\n" +
|
||||
files.join("\n"),
|
||||
);
|
||||
}
|
||||
this.indexingCancellationController = new AbortController();
|
||||
for await (const update of (await this.codebaseIndexerPromise).refreshFiles(
|
||||
files,
|
||||
this.indexingCancellationController.signal,
|
||||
)) {
|
||||
let updateToSend = { ...update };
|
||||
if (update.status === "failed") {
|
||||
updateToSend.status = "done";
|
||||
updateToSend.desc = "Indexing complete";
|
||||
updateToSend.progress = 1.0;
|
||||
}
|
||||
|
||||
void this.messenger.request("indexProgress", updateToSend);
|
||||
this.indexingState = updateToSend;
|
||||
|
||||
if (update.status === "failed") {
|
||||
void this.sendIndexingTelemetry(update);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import {
|
|||
RefreshIndexResults,
|
||||
} from "./types.js";
|
||||
import { walkDirAsync } from "./walkDir.js";
|
||||
import { getBasename } from "../util/index.js";
|
||||
|
||||
export class PauseToken {
|
||||
constructor(private _paused: boolean) {}
|
||||
|
|
@ -144,13 +145,61 @@ export class CodebaseIndexer {
|
|||
}
|
||||
}
|
||||
|
||||
async *refresh(
|
||||
workspaceDirs: string[],
|
||||
async *refreshFiles(
|
||||
files: string[],
|
||||
abortSignal: AbortSignal,
|
||||
): AsyncGenerator<IndexingProgressUpdate> {
|
||||
let progress = 0;
|
||||
if (files.length === 0) {
|
||||
yield {
|
||||
progress: 1,
|
||||
desc: "Indexing Complete",
|
||||
status: "done",
|
||||
};
|
||||
}
|
||||
|
||||
const progressPer = 1 / files.length;
|
||||
try {
|
||||
for (const file of files) {
|
||||
yield {
|
||||
progress,
|
||||
desc: `Indexing file ${file}...`,
|
||||
status: "indexing",
|
||||
};
|
||||
await this.refreshFile(file);
|
||||
|
||||
progress += progressPer;
|
||||
|
||||
if (this.pauseToken.paused) {
|
||||
yield* this.yieldUpdateAndPause();
|
||||
}
|
||||
if (abortSignal.aborted) {
|
||||
yield {
|
||||
progress: 1,
|
||||
desc: "Indexing cancelled",
|
||||
status: "disabled",
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
yield {
|
||||
progress: 1,
|
||||
desc: "Indexing Complete",
|
||||
status: "done",
|
||||
};
|
||||
} catch (err) {
|
||||
yield this.handleErrorAndGetProgressUpdate(err);
|
||||
}
|
||||
}
|
||||
|
||||
async *refreshDirs(
|
||||
dirs: string[],
|
||||
abortSignal: AbortSignal,
|
||||
): AsyncGenerator<IndexingProgressUpdate> {
|
||||
let progress = 0;
|
||||
|
||||
if (workspaceDirs.length === 0) {
|
||||
if (dirs.length === 0) {
|
||||
yield {
|
||||
progress,
|
||||
desc: "Nothing to index",
|
||||
|
|
@ -175,11 +224,9 @@ export class CodebaseIndexer {
|
|||
};
|
||||
}
|
||||
|
||||
let completedDirs = 0;
|
||||
|
||||
// Wait until Git Extension has loaded to report progress
|
||||
// so we don't appear stuck at 0% while waiting
|
||||
await this.ide.getRepoName(workspaceDirs[0]);
|
||||
await this.ide.getRepoName(dirs[0]);
|
||||
|
||||
yield {
|
||||
progress,
|
||||
|
|
@ -188,16 +235,16 @@ export class CodebaseIndexer {
|
|||
};
|
||||
const beginTime = Date.now();
|
||||
|
||||
for (const directory of workspaceDirs) {
|
||||
for (const directory of dirs) {
|
||||
const dirBasename = await this.basename(directory);
|
||||
yield {
|
||||
progress,
|
||||
desc: `Discovering files in ${dirBasename}...`,
|
||||
status: "indexing",
|
||||
};
|
||||
const workspaceFiles = [];
|
||||
const directoryFiles = [];
|
||||
for await (const p of walkDirAsync(directory, this.ide)) {
|
||||
workspaceFiles.push(p);
|
||||
directoryFiles.push(p);
|
||||
if (abortSignal.aborted) {
|
||||
yield {
|
||||
progress: 1,
|
||||
|
|
@ -218,7 +265,7 @@ export class CodebaseIndexer {
|
|||
try {
|
||||
for await (const updateDesc of this.indexFiles(
|
||||
directory,
|
||||
workspaceFiles,
|
||||
directoryFiles,
|
||||
branch,
|
||||
repoName,
|
||||
)) {
|
||||
|
|
@ -240,7 +287,7 @@ export class CodebaseIndexer {
|
|||
nextLogThreshold += 0.025;
|
||||
this.logProgress(
|
||||
beginTime,
|
||||
Math.floor(workspaceFiles.length * updateDesc.progress),
|
||||
Math.floor(directoryFiles.length * updateDesc.progress),
|
||||
updateDesc.progress,
|
||||
);
|
||||
}
|
||||
|
|
@ -347,18 +394,18 @@ export class CodebaseIndexer {
|
|||
}
|
||||
|
||||
private async *indexFiles(
|
||||
workspaceDir: string,
|
||||
workspaceFiles: string[],
|
||||
directory: string,
|
||||
files: string[],
|
||||
branch: string,
|
||||
repoName: string | undefined,
|
||||
): AsyncGenerator<IndexingProgressUpdate> {
|
||||
const stats = await this.ide.getLastModified(workspaceFiles);
|
||||
const stats = await this.ide.getLastModified(files);
|
||||
const indexesToBuild = await this.getIndexesToBuild();
|
||||
let completedIndexCount = 0;
|
||||
let progress = 0;
|
||||
for (const codebaseIndex of indexesToBuild) {
|
||||
const tag: IndexTag = {
|
||||
directory: workspaceDir,
|
||||
directory,
|
||||
branch,
|
||||
artifactId: codebaseIndex.artifactId,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
undefined | { dirs?: string[]; shouldClearIndexes?: boolean },
|
||||
void,
|
||||
];
|
||||
"index/forceReIndexFiles": [undefined | { files?: string[] }, void];
|
||||
"index/indexingProgressBarInitialized": [undefined, void];
|
||||
completeOnboarding: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"stats/getTokensPerModel",
|
||||
"index/setPaused",
|
||||
"index/forceReIndex",
|
||||
"index/forceReIndexFiles",
|
||||
"index/indexingProgressBarInitialized",
|
||||
"completeOnboarding",
|
||||
"addAutocompleteModel",
|
||||
|
|
@ -60,5 +61,5 @@ export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] =
|
|||
"isContinueInputFocused",
|
||||
"didChangeAvailableProfiles",
|
||||
"setTTSActive",
|
||||
"getWebviewHistoryLength"
|
||||
"getWebviewHistoryLength",
|
||||
];
|
||||
|
|
|
|||
|
|
@ -169,8 +169,8 @@ class ContinuePluginStartupActivity : StartupActivity, Disposable, DumbAware {
|
|||
|
||||
// Create a data map if there are any paths to re-index
|
||||
if (allPaths.isNotEmpty()) {
|
||||
val data = mapOf("dirs" to allPaths)
|
||||
continuePluginService.coreMessenger?.request("index/forceReIndex", data, null) { _ -> }
|
||||
val data = mapOf("files" to allPaths)
|
||||
continuePluginService.coreMessenger?.request("index/forceReIndexFiles", data, null) { _ -> }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ class ContinueBrowser(val project: Project, url: String) {
|
|||
"stats/getTokensPerModel",
|
||||
"index/setPaused",
|
||||
"index/forceReIndex",
|
||||
"index/forceReIndexFiles",
|
||||
"index/indexingProgressBarInitialized",
|
||||
"completeOnboarding",
|
||||
"addAutocompleteModel",
|
||||
|
|
|
|||
|
|
@ -297,17 +297,15 @@ export class VsCodeExtension {
|
|||
this.core.invoke("index/forceReIndex", undefined);
|
||||
} else {
|
||||
// Reindex the file
|
||||
this.core.invoke("index/forceReIndex", {
|
||||
dirs: [filepath],
|
||||
this.core.invoke("index/forceReIndexFiles", {
|
||||
files: [filepath],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
vscode.workspace.onDidDeleteFiles(async (event) => {
|
||||
this.core.invoke("index/forceReIndex", {
|
||||
dirs: event.files.map((file) =>
|
||||
file.fsPath.split("/").slice(0, -1).join("/"),
|
||||
),
|
||||
this.core.invoke("index/forceReIndexFiles", {
|
||||
files: event.files.map((file) => file.fsPath),
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue