add new indexTypes for context indexing

This commit is contained in:
uinstinct 2025-06-27 17:44:49 +05:30
parent 78426cc224
commit c64dd93193
7 changed files with 58 additions and 31 deletions

View file

@ -16,7 +16,7 @@ class CodeContextProvider extends BaseContextProvider {
displayTitle: "Code",
description: "Type to search",
type: "submenu",
dependsOnIndexing: true,
indexTypes: ["chunk", "codeSnippets"],
};
async getContextItems(

View file

@ -13,6 +13,7 @@ class CodebaseContextProvider extends BaseContextProvider {
description: "Automatically find relevant files",
type: "normal",
renderInlineAs: "",
indexTypes: ["embeddings", "fullTextSearch", "chunk"],
};
async getContextItems(

View file

@ -19,7 +19,7 @@ class FolderContextProvider extends BaseContextProvider {
displayTitle: "Folder",
description: "Type to search",
type: "submenu",
dependsOnIndexing: true,
indexTypes: ["embeddings"],
};
async getContextItems(

7
core/index.d.ts vendored
View file

@ -165,6 +165,11 @@ export interface ModelInstaller {
}
export type ContextProviderType = "normal" | "query" | "submenu";
export type ContextIndexingType =
| "chunk"
| "embeddings"
| "fullTextSearch"
| "codeSnippets";
export interface ContextProviderDescription {
title: ContextProviderName;
@ -172,7 +177,7 @@ export interface ContextProviderDescription {
description: string;
renderInlineAs?: string;
type: ContextProviderType;
dependsOnIndexing?: boolean;
indexTypes?: ContextIndexingType[];
}
export type FetchFunction = (url: string | URL, init?: any) => Promise<any>;

View file

@ -1,7 +1,12 @@
import * as fs from "fs/promises";
import { ConfigHandler } from "../config/ConfigHandler.js";
import { IDE, IndexingProgressUpdate, IndexTag } from "../index.js";
import {
ContextIndexingType,
IDE,
IndexingProgressUpdate,
IndexTag,
} from "../index.js";
import type { FromCoreProtocol, ToCoreProtocol } from "../protocol";
import type { IMessenger } from "../protocol/messenger";
import { extractMinimalStackTraceInfo } from "../util/extractMinimalStackTraceInfo.js";
@ -123,28 +128,43 @@ export class CodebaseIndexer {
return [];
}
const indexes: CodebaseIndex[] = [
new ChunkCodebaseIndex(
this.ide.readFile.bind(this.ide),
continueServerClient,
embeddingsModel.maxEmbeddingChunkSize,
), // Chunking must come first
];
const lanceDbIndex = await LanceDbIndex.create(
embeddingsModel,
this.ide.readFile.bind(this.ide),
const indexTypesToBuild = new Set( // use set to remove duplicates
config.contextProviders
.map((provider) => provider.description.indexTypes)
.filter((indexType) => Array.isArray(indexType)) // remove undefined indexTypes
.flat(),
);
if (lanceDbIndex) {
indexes.push(lanceDbIndex);
const indexTypeToIndexerMapping: Record<
ContextIndexingType,
() => Promise<CodebaseIndex | null>
> = {
chunk: async () =>
new ChunkCodebaseIndex(
this.ide.readFile.bind(this.ide),
continueServerClient,
embeddingsModel.maxEmbeddingChunkSize,
),
codeSnippets: async () => new CodeSnippetsCodebaseIndex(this.ide),
fullTextSearch: async () => new FullTextSearchCodebaseIndex(),
embeddings: async () => {
const lanceDbIndex = await LanceDbIndex.create(
embeddingsModel,
this.ide.readFile.bind(this.ide),
);
return lanceDbIndex;
},
};
const indexes: CodebaseIndex[] = [];
// not parallelizing to avoid race conditions in sqlite
for (const indexType of indexTypesToBuild) {
const index = await indexTypeToIndexerMapping[indexType]();
if (index) {
indexes.push(index);
}
}
indexes.push(
new FullTextSearchCodebaseIndex(),
new CodeSnippetsCodebaseIndex(this.ide),
);
return indexes;
}

View file

@ -24,7 +24,7 @@ export type ToWebviewFromIdeOrCoreProtocol = {
"indexing/statusUpdate": [IndexingStatus, void]; // Docs, etc.
refreshSubmenuItems: [
{
providers: "all" | "dependsOnIndexing" | ContextProviderName[];
providers: "all" | "indexTypes" | ContextProviderName[];
},
void,
];

View file

@ -115,7 +115,7 @@ export const SubmenuContextProvidersProvider = ({
const interval = setInterval(refreshOpenFiles, 2000);
refreshOpenFiles(); // Initial call
void refreshOpenFiles(); // Initial call
return () => {
isMounted = false;
@ -227,7 +227,7 @@ export const SubmenuContextProvidersProvider = ({
);
const loadSubmenuItems = useCallback(
async (providers: "dependsOnIndexing" | "all" | ContextProviderName[]) => {
async (providers: "indexTypes" | "all" | ContextProviderName[]) => {
await Promise.allSettled(
submenuContextProviders.map(
async (description: ContextProviderDescription) => {
@ -236,12 +236,13 @@ export const SubmenuContextProvidersProvider = ({
const refreshProvider =
providers === "all"
? true
: providers === "dependsOnIndexing"
? description.dependsOnIndexing
: providers === "indexTypes"
? description.indexTypes &&
description.indexTypes?.length > 0
: providers.includes(description.title);
if (!refreshProvider) {
if (providers === "dependsOnIndexing") {
if (providers === "indexTypes") {
console.debug(
`Skipping ${description.title} provider due to disabled indexing`,
);
@ -351,7 +352,7 @@ export const SubmenuContextProvidersProvider = ({
useWebviewListener(
"refreshSubmenuItems",
async (data) => {
loadSubmenuItems(data.providers);
void loadSubmenuItems(data.providers);
},
[loadSubmenuItems],
);
@ -360,7 +361,7 @@ export const SubmenuContextProvidersProvider = ({
"indexProgress",
async (data) => {
if (data.status === "done") {
loadSubmenuItems("dependsOnIndexing");
void loadSubmenuItems("indexTypes");
}
},
[loadSubmenuItems],
@ -379,7 +380,7 @@ export const SubmenuContextProvidersProvider = ({
)
.map((provider) => provider.title);
if (newTitles.length > 0) {
loadSubmenuItems(newTitles);
void loadSubmenuItems(newTitles);
}
lastProviders.current = submenuContextProviders;
}, [loadSubmenuItems, submenuContextProviders]);