* 💄 image drag and drop improvements * 💄 further improvement to drag/drop hints * 🐛 fix image selector insertion * 🐛 fix dropdown width being larger than window width * 🐛 respect disableIndexing * 🐛 fix context items not refreshing when editing past message * ✨ llava chat template * 🩹 multiple small fixes * 🐛 a few docs crawling fixes * 🔊 log docs url * 🐛 small fixes to DocsContextProvider * 📝 update changelog and docs for DocsContextProvider * 🐛 show new docs in submenu after it is loaded
100 lines
3.1 KiB
TypeScript
100 lines
3.1 KiB
TypeScript
import { FullTextSearchCodebaseIndex } from "core/indexing/FullTextSearch";
|
|
import { LanceDbIndex } from "core/indexing/LanceDbIndex";
|
|
import { ChunkCodebaseIndex } from "core/indexing/chunk/ChunkCodebaseIndex";
|
|
import { getComputeDeleteAddRemove } from "core/indexing/refreshIndex";
|
|
import { CodebaseIndex, IndexTag, LastModifiedMap } from "core/indexing/types";
|
|
import * as vscode from "vscode";
|
|
import { ideProtocolClient } from "../activation/activate";
|
|
import { debugPanelWebview } from "../debugPanel";
|
|
import { VsCodeIde } from "../ideProtocol";
|
|
import { configHandler } from "../loadConfig";
|
|
|
|
const vscodeGetStats = async (
|
|
directory: string | undefined
|
|
): Promise<LastModifiedMap> => {
|
|
const files = await new VsCodeIde().listWorkspaceContents(directory);
|
|
const pathToLastModified: { [path: string]: number } = {};
|
|
await Promise.all(
|
|
files.map(async (file) => {
|
|
let stat = await vscode.workspace.fs.stat(vscode.Uri.file(file));
|
|
pathToLastModified[file] = stat.mtime;
|
|
})
|
|
);
|
|
|
|
return pathToLastModified;
|
|
};
|
|
|
|
async function getIndexesToBuild(): Promise<CodebaseIndex[]> {
|
|
const ide = new VsCodeIde();
|
|
const config = await configHandler.loadConfig(ide);
|
|
|
|
const indexes = [
|
|
new ChunkCodebaseIndex(ide.readFile), // Chunking must come first
|
|
new LanceDbIndex(config.embeddingsProvider, ide.readFile),
|
|
new FullTextSearchCodebaseIndex(),
|
|
];
|
|
|
|
return indexes;
|
|
}
|
|
|
|
export async function vsCodeIndexCodebase(workspaceDirs: string[]) {
|
|
const update = (progress: number, desc: string) => {
|
|
debugPanelWebview?.postMessage({ type: "indexProgress", progress, desc });
|
|
};
|
|
|
|
const config = await configHandler.loadConfig(new VsCodeIde());
|
|
if (config.disableIndexing) {
|
|
return;
|
|
}
|
|
|
|
const indexesToBuild = await getIndexesToBuild();
|
|
|
|
let completedDirs = 0;
|
|
|
|
for (let directory of workspaceDirs) {
|
|
const stats = await vscodeGetStats(directory);
|
|
const branch = await ideProtocolClient.getBranch(
|
|
vscode.Uri.file(directory)
|
|
);
|
|
let completedIndexes = 0;
|
|
|
|
try {
|
|
for (let codebaseIndex of indexesToBuild) {
|
|
const tag: IndexTag = {
|
|
directory,
|
|
branch,
|
|
artifactId: codebaseIndex.artifactId,
|
|
};
|
|
const [results, markComplete] = await getComputeDeleteAddRemove(
|
|
tag,
|
|
{ ...stats },
|
|
(filepath) => ideProtocolClient.readFile(filepath)
|
|
);
|
|
|
|
for await (let { progress, desc } of codebaseIndex.update(
|
|
tag,
|
|
results,
|
|
markComplete
|
|
)) {
|
|
update(
|
|
(completedDirs +
|
|
(completedIndexes + progress) / indexesToBuild.length) /
|
|
workspaceDirs.length,
|
|
desc
|
|
);
|
|
}
|
|
completedIndexes++;
|
|
update(
|
|
(completedDirs + completedIndexes / indexesToBuild.length) /
|
|
workspaceDirs.length,
|
|
"Completed indexing " + codebaseIndex.artifactId
|
|
);
|
|
}
|
|
} catch (e) {
|
|
console.warn("Error refreshing index: ", e);
|
|
}
|
|
|
|
completedDirs++;
|
|
update(completedDirs / workspaceDirs.length, "Indexing Complete");
|
|
}
|
|
}
|