Skip to content

feat: run dependent indexer based on context provider #6323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/context/providers/CodeContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CodeContextProvider extends BaseContextProvider {
displayTitle: "Code",
description: "Type to search",
type: "submenu",
dependsOnIndexing: true,
dependsOnIndexing: ["chunk", "codeSnippets"],
};

async getContextItems(
Expand Down
1 change: 1 addition & 0 deletions core/context/providers/CodebaseContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CodebaseContextProvider extends BaseContextProvider {
description: "Automatically find relevant files",
type: "normal",
renderInlineAs: "",
dependsOnIndexing: ["embeddings", "fullTextSearch", "chunk"],
};

async getContextItems(
Expand Down
2 changes: 1 addition & 1 deletion core/context/providers/FolderContextProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FolderContextProvider extends BaseContextProvider {
displayTitle: "Folder",
description: "Type to search",
type: "submenu",
dependsOnIndexing: true,
dependsOnIndexing: ["embeddings", "fullTextSearch", "chunk"],
};

async getContextItems(
Expand Down
7 changes: 6 additions & 1 deletion core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,19 @@ export interface ModelInstaller {
}

export type ContextProviderType = "normal" | "query" | "submenu";
export type ContextIndexingType =
| "chunk"
| "embeddings"
| "fullTextSearch"
| "codeSnippets";

export interface ContextProviderDescription {
title: ContextProviderName;
displayTitle: string;
description: string;
renderInlineAs?: string;
type: ContextProviderType;
dependsOnIndexing?: boolean;
dependsOnIndexing?: ContextIndexingType[];
}

export type FetchFunction = (url: string | URL, init?: any) => Promise<any>;
Expand Down
60 changes: 41 additions & 19 deletions core/indexing/CodebaseIndexer.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -123,27 +128,44 @@ 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.dependsOnIndexing)
.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;
},
};

indexes.push(
new FullTextSearchCodebaseIndex(),
new CodeSnippetsCodebaseIndex(this.ide),
);
const indexes: CodebaseIndex[] = [];
// not parallelizing to avoid race conditions in sqlite
for (const indexType of indexTypesToBuild) {
if (indexType && indexType in indexTypeToIndexerMapping) {
const index = await indexTypeToIndexerMapping[indexType]();
if (index) {
indexes.push(index);
}
}
}

return indexes;
}
Expand Down
11 changes: 6 additions & 5 deletions gui/src/context/SubmenuContextProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const SubmenuContextProvidersProvider = ({

const interval = setInterval(refreshOpenFiles, 2000);

refreshOpenFiles(); // Initial call
void refreshOpenFiles(); // Initial call

return () => {
isMounted = false;
Expand Down Expand Up @@ -237,7 +237,8 @@ export const SubmenuContextProvidersProvider = ({
providers === "all"
? true
: providers === "dependsOnIndexing"
? description.dependsOnIndexing
? description.dependsOnIndexing &&
description.dependsOnIndexing?.length > 0
: providers.includes(description.title);

if (!refreshProvider) {
Expand Down Expand Up @@ -351,7 +352,7 @@ export const SubmenuContextProvidersProvider = ({
useWebviewListener(
"refreshSubmenuItems",
async (data) => {
loadSubmenuItems(data.providers);
void loadSubmenuItems(data.providers);
},
[loadSubmenuItems],
);
Expand All @@ -360,7 +361,7 @@ export const SubmenuContextProvidersProvider = ({
"indexProgress",
async (data) => {
if (data.status === "done") {
loadSubmenuItems("dependsOnIndexing");
void loadSubmenuItems("dependsOnIndexing");
}
},
[loadSubmenuItems],
Expand All @@ -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]);
Expand Down