Changesets · Branches · Tags · Compare
| Changeset | 22a64be7284f0dfa2cb245ab97326ee62dd75af89912739e57ab0d567ed839a9 |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-09-09 11:29 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-09-09 11:29 -07:00 |
| Parents | 27a6a4517a3b, 1ac6dff93cbc |
8 files changed
modified core/context/providers/CodeContextProvider.ts +1 −1
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | displayTitle: "Code", |
| 17 | 17 | description: "Type to search", |
| 18 | 18 | type: "submenu", |
| 19 | - dependsOnIndexing: true, | |
| 19 | + dependsOnIndexing: ["chunk", "codeSnippets"], | |
| 20 | 20 | }; |
| 21 | 21 | |
| 22 | 22 | async getContextItems( |
modified core/context/providers/CodebaseContextProvider.ts +1 −1
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | description: "Automatically find relevant files", |
| 14 | 14 | type: "normal", |
| 15 | 15 | renderInlineAs: "", |
| 16 | - dependsOnIndexing: true, | |
| 16 | + dependsOnIndexing: ["embeddings", "fullTextSearch", "chunk"], | |
| 17 | 17 | }; |
| 18 | 18 | |
| 19 | 19 | async getContextItems( |
modified core/context/providers/FolderContextProvider.ts +1 −1
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | displayTitle: "Folder", |
| 20 | 20 | description: "Type to search", |
| 21 | 21 | type: "submenu", |
| 22 | - dependsOnIndexing: true, | |
| 22 | + dependsOnIndexing: ["embeddings", "fullTextSearch", "chunk"], | |
| 23 | 23 | }; |
| 24 | 24 | |
| 25 | 25 | async getContextItems( |
modified core/core.ts +13 −7
| @@ -174,6 +174,13 @@ | ||
| 174 | 174 | } |
| 175 | 175 | }; |
| 176 | 176 | |
| 177 | + this.codeBaseIndexer = new CodebaseIndexer( | |
| 178 | + this.configHandler, | |
| 179 | + this.ide, | |
| 180 | + this.messenger, | |
| 181 | + this.globalContext.get("indexingPaused"), | |
| 182 | + ); | |
| 183 | + | |
| 177 | 184 | this.configHandler.onConfigUpdate((result) => { |
| 178 | 185 | void (async () => { |
| 179 | 186 | const serializedResult = |
| @@ -186,6 +193,12 @@ | ||
| 186 | 193 | selectedOrgId: this.configHandler.currentOrg?.id ?? null, |
| 187 | 194 | }); |
| 188 | 195 | |
| 196 | + if (await this.codeBaseIndexer.wasAnyOneIndexAdded()) { | |
| 197 | + await this.codeBaseIndexer.refreshCodebaseIndex( | |
| 198 | + await this.ide.getWorkspaceDirs(), | |
| 199 | + ); | |
| 200 | + } | |
| 201 | + | |
| 189 | 202 | // update additional submenu context providers registered via VSCode API |
| 190 | 203 | const additionalProviders = |
| 191 | 204 | this.configHandler.getAdditionalSubmenuContextProviders(); |
| @@ -197,13 +210,6 @@ | ||
| 197 | 210 | })(); |
| 198 | 211 | }); |
| 199 | 212 | |
| 200 | - this.codeBaseIndexer = new CodebaseIndexer( | |
| 201 | - this.configHandler, | |
| 202 | - this.ide, | |
| 203 | - this.messenger, | |
| 204 | - this.globalContext.get("indexingPaused"), | |
| 205 | - ); | |
| 206 | - | |
| 207 | 213 | // Dev Data Logger |
| 208 | 214 | const dataLogger = DataLogger.getInstance(); |
| 209 | 215 | dataLogger.core = this; |
modified core/index.d.ts +6 −1
| @@ -173,6 +173,11 @@ | ||
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | export type ContextProviderType = "normal" | "query" | "submenu"; |
| 176 | +export type ContextIndexingType = | |
| 177 | + | "chunk" | |
| 178 | + | "embeddings" | |
| 179 | + | "fullTextSearch" | |
| 180 | + | "codeSnippets"; | |
| 176 | 181 | |
| 177 | 182 | export interface ContextProviderDescription { |
| 178 | 183 | title: ContextProviderName; |
| @@ -180,7 +185,7 @@ | ||
| 180 | 185 | description: string; |
| 181 | 186 | renderInlineAs?: string; |
| 182 | 187 | type: ContextProviderType; |
| 183 | - dependsOnIndexing?: boolean; | |
| 188 | + dependsOnIndexing?: ContextIndexingType[]; | |
| 184 | 189 | } |
| 185 | 190 | |
| 186 | 191 | export type FetchFunction = (url: string | URL, init?: any) => Promise<any>; |
modified core/indexing/CodebaseIndexer.test.ts +150 −0
| @@ -21,6 +21,7 @@ | ||
| 21 | 21 | import { ContinueConfig } from "../index.js"; |
| 22 | 22 | import { localPathToUri } from "../util/pathToUri.js"; |
| 23 | 23 | import { CodebaseIndexer } from "./CodebaseIndexer.js"; |
| 24 | +import { FullTextSearchCodebaseIndex } from "./FullTextSearchCodebaseIndex.js"; | |
| 24 | 25 | import { getComputeDeleteAddRemove } from "./refreshIndex.js"; |
| 25 | 26 | import { TestCodebaseIndex } from "./TestCodebaseIndex.js"; |
| 26 | 27 | import { CodebaseIndex } from "./types.js"; |
| @@ -675,5 +676,154 @@ | ||
| 675 | 676 | ]); |
| 676 | 677 | }); |
| 677 | 678 | }); |
| 679 | + | |
| 680 | + describe("getIndexesToBuild", () => { | |
| 681 | + let indexer: CodebaseIndexer; | |
| 682 | + let mockConfig: any; | |
| 683 | + let mockEmbeddingsModel: any; | |
| 684 | + let mockIdeSettings: any; | |
| 685 | + | |
| 686 | + beforeEach(async () => { | |
| 687 | + indexer = new CodebaseIndexer( | |
| 688 | + testConfigHandler, | |
| 689 | + testIde, | |
| 690 | + mockMessenger as any, | |
| 691 | + false, | |
| 692 | + ); | |
| 693 | + | |
| 694 | + mockEmbeddingsModel = { | |
| 695 | + maxEmbeddingChunkSize: 1000, | |
| 696 | + model: "test-model", | |
| 697 | + provider: "test-provider", | |
| 698 | + }; | |
| 699 | + | |
| 700 | + mockIdeSettings = { | |
| 701 | + remoteConfigServerUrl: "http://test.com", | |
| 702 | + userToken: "test-token", | |
| 703 | + }; | |
| 704 | + | |
| 705 | + mockConfig = { | |
| 706 | + selectedModelByRole: { | |
| 707 | + embed: mockEmbeddingsModel, | |
| 708 | + }, | |
| 709 | + contextProviders: [], | |
| 710 | + }; | |
| 711 | + | |
| 712 | + jest | |
| 713 | + .spyOn(testIde, "getIdeSettings") | |
| 714 | + .mockResolvedValue(mockIdeSettings); | |
| 715 | + }); | |
| 716 | + | |
| 717 | + afterEach(() => { | |
| 718 | + jest.clearAllMocks(); | |
| 719 | + }); | |
| 720 | + | |
| 721 | + test("should create specific indexTypes for the requested context providers", async () => { | |
| 722 | + mockConfig.contextProviders = [ | |
| 723 | + { | |
| 724 | + description: { | |
| 725 | + dependsOnIndexing: ["chunk", "codeSnippets"], | |
| 726 | + }, | |
| 727 | + }, | |
| 728 | + ]; | |
| 729 | + | |
| 730 | + jest.spyOn(testConfigHandler, "loadConfig").mockResolvedValue({ | |
| 731 | + config: mockConfig, | |
| 732 | + errors: [], | |
| 733 | + configLoadInterrupted: false, | |
| 734 | + }); | |
| 735 | + | |
| 736 | + const indexes = (await ( | |
| 737 | + indexer as any | |
| 738 | + ).getIndexesToBuild()) as CodebaseIndex[]; | |
| 739 | + | |
| 740 | + expect(indexes).toHaveLength(2); | |
| 741 | + expect(indexes[0].artifactId).toBe("chunks"); | |
| 742 | + expect(indexes[1].artifactId).toBe("codeSnippets"); | |
| 743 | + }); | |
| 744 | + | |
| 745 | + test("should handle duplicate contexts", async () => { | |
| 746 | + mockConfig.contextProviders = [ | |
| 747 | + { | |
| 748 | + description: { | |
| 749 | + dependsOnIndexing: ["codeSnippets"], | |
| 750 | + }, | |
| 751 | + }, | |
| 752 | + { | |
| 753 | + description: { | |
| 754 | + dependsOnIndexing: ["codeSnippets"], | |
| 755 | + }, | |
| 756 | + }, | |
| 757 | + ]; | |
| 758 | + | |
| 759 | + jest.spyOn(testConfigHandler, "loadConfig").mockResolvedValue({ | |
| 760 | + config: mockConfig, | |
| 761 | + errors: [], | |
| 762 | + configLoadInterrupted: false, | |
| 763 | + }); | |
| 764 | + | |
| 765 | + const indexes = await (indexer as any).getIndexesToBuild(); | |
| 766 | + | |
| 767 | + expect(indexes).toHaveLength(1); | |
| 768 | + expect(indexes[0].artifactId).toBe("codeSnippets"); | |
| 769 | + }); | |
| 770 | + }); | |
| 771 | + }); | |
| 772 | + | |
| 773 | + describe("wasAnyOneIndexAdded", () => { | |
| 774 | + let testIndexer: TestCodebaseIndexer; | |
| 775 | + let mockGetIndexesToBuild: jest.MockedFunction<any>; | |
| 776 | + | |
| 777 | + beforeEach(() => { | |
| 778 | + testIndexer = new TestCodebaseIndexer( | |
| 779 | + testConfigHandler, | |
| 780 | + testIde, | |
| 781 | + mockMessenger as any, | |
| 782 | + false, | |
| 783 | + ); | |
| 784 | + | |
| 785 | + // Mock getIndexesToBuild to control what indexes should be built | |
| 786 | + mockGetIndexesToBuild = jest | |
| 787 | + .spyOn(testIndexer as any, "getIndexesToBuild") | |
| 788 | + .mockResolvedValue([]); | |
| 789 | + | |
| 790 | + jest | |
| 791 | + .spyOn(testIndexer, "refreshCodebaseIndex") | |
| 792 | + .mockImplementation(async () => {}); | |
| 793 | + }); | |
| 794 | + | |
| 795 | + afterEach(() => { | |
| 796 | + jest.clearAllMocks(); | |
| 797 | + }); | |
| 798 | + | |
| 799 | + test("should return true when indexes to build differ from built indexes", async () => { | |
| 800 | + const mockIndex1 = new TestCodebaseIndex(); | |
| 801 | + const mockIndex2 = new FullTextSearchCodebaseIndex(); | |
| 802 | + mockGetIndexesToBuild.mockResolvedValue([mockIndex1]); | |
| 803 | + (testIndexer as any).builtIndexes = [mockIndex2]; | |
| 804 | + | |
| 805 | + const result = await testIndexer.wasAnyOneIndexAdded(); | |
| 806 | + expect(result).toBe(true); | |
| 807 | + }); | |
| 808 | + | |
| 809 | + test("should return true when there are more indexes to build than built indexes", async () => { | |
| 810 | + const mockIndex1 = new TestCodebaseIndex(); | |
| 811 | + const mockIndex2 = new FullTextSearchCodebaseIndex(); | |
| 812 | + mockGetIndexesToBuild.mockResolvedValue([mockIndex1, mockIndex2]); | |
| 813 | + (testIndexer as any).builtIndexes = [mockIndex1]; | |
| 814 | + | |
| 815 | + const result = await testIndexer.wasAnyOneIndexAdded(); | |
| 816 | + expect(result).toBe(true); | |
| 817 | + }); | |
| 818 | + | |
| 819 | + test("should return false when there are fewer indexes to build than built indexes", async () => { | |
| 820 | + const mockIndex1 = new TestCodebaseIndex(); | |
| 821 | + const mockIndex2 = new FullTextSearchCodebaseIndex(); | |
| 822 | + mockGetIndexesToBuild.mockResolvedValue([mockIndex1]); | |
| 823 | + (testIndexer as any).builtIndexes = [mockIndex1, mockIndex2]; | |
| 824 | + | |
| 825 | + const result = await testIndexer.wasAnyOneIndexAdded(); | |
| 826 | + expect(result).toBe(false); | |
| 827 | + }); | |
| 678 | 828 | }); |
| 679 | 829 | }); |
modified core/indexing/CodebaseIndexer.ts +47 −18
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | |
| 3 | 3 | import { ConfigHandler } from "../config/ConfigHandler.js"; |
| 4 | 4 | import { |
| 5 | + ContextIndexingType, | |
| 5 | 6 | ContinueConfig, |
| 6 | 7 | IDE, |
| 7 | 8 | IndexingProgressUpdate, |
| @@ -58,6 +59,7 @@ | ||
| 58 | 59 | private indexingCancellationController: AbortController; |
| 59 | 60 | private codebaseIndexingState: IndexingProgressUpdate; |
| 60 | 61 | private readonly pauseToken: PauseToken; |
| 62 | + private builtIndexes: CodebaseIndex[] = []; | |
| 61 | 63 | |
| 62 | 64 | private getUserFriendlyIndexName(artifactId: string): string { |
| 63 | 65 | if (artifactId === FullTextSearchCodebaseIndex.artifactId) |
| @@ -166,28 +168,46 @@ | ||
| 166 | 168 | return []; |
| 167 | 169 | } |
| 168 | 170 | |
| 169 | - const indexes: CodebaseIndex[] = [ | |
| 170 | - new ChunkCodebaseIndex( | |
| 171 | - this.ide.readFile.bind(this.ide), | |
| 172 | - continueServerClient, | |
| 173 | - embeddingsModel.maxEmbeddingChunkSize, | |
| 174 | - ), // Chunking must come first | |
| 175 | - ]; | |
| 176 | - | |
| 177 | - const lanceDbIndex = await LanceDbIndex.create( | |
| 178 | - embeddingsModel, | |
| 179 | - this.ide.readFile.bind(this.ide), | |
| 171 | + const indexTypesToBuild = new Set( // use set to remove duplicates | |
| 172 | + config.contextProviders | |
| 173 | + .map((provider) => provider.description.dependsOnIndexing) | |
| 174 | + .filter((indexType) => Array.isArray(indexType)) // remove undefined indexTypes | |
| 175 | + .flat(), | |
| 180 | 176 | ); |
| 181 | 177 | |
| 182 | - if (lanceDbIndex) { | |
| 183 | - indexes.push(lanceDbIndex); | |
| 184 | - } | |
| 178 | + const indexTypeToIndexerMapping: Record< | |
| 179 | + ContextIndexingType, | |
| 180 | + () => Promise<CodebaseIndex | null> | |
| 181 | + > = { | |
| 182 | + chunk: async () => | |
| 183 | + new ChunkCodebaseIndex( | |
| 184 | + this.ide.readFile.bind(this.ide), | |
| 185 | + continueServerClient, | |
| 186 | + embeddingsModel.maxEmbeddingChunkSize, | |
| 187 | + ), | |
| 188 | + codeSnippets: async () => new CodeSnippetsCodebaseIndex(this.ide), | |
| 189 | + fullTextSearch: async () => new FullTextSearchCodebaseIndex(), | |
| 190 | + embeddings: async () => { | |
| 191 | + const lanceDbIndex = await LanceDbIndex.create( | |
| 192 | + embeddingsModel, | |
| 193 | + this.ide.readFile.bind(this.ide), | |
| 194 | + ); | |
| 195 | + return lanceDbIndex; | |
| 196 | + }, | |
| 197 | + }; | |
| 185 | 198 | |
| 186 | - indexes.push( | |
| 187 | - new FullTextSearchCodebaseIndex(), | |
| 188 | - new CodeSnippetsCodebaseIndex(this.ide), | |
| 189 | - ); | |
| 199 | + const indexes: CodebaseIndex[] = []; | |
| 200 | + // not parallelizing to avoid race conditions in sqlite | |
| 201 | + for (const indexType of indexTypesToBuild) { | |
| 202 | + if (indexType && indexType in indexTypeToIndexerMapping) { | |
| 203 | + const index = await indexTypeToIndexerMapping[indexType](); | |
| 204 | + if (index) { | |
| 205 | + indexes.push(index); | |
| 206 | + } | |
| 207 | + } | |
| 208 | + } | |
| 190 | 209 | |
| 210 | + this.builtIndexes = indexes; | |
| 191 | 211 | return indexes; |
| 192 | 212 | } |
| 193 | 213 | |
| @@ -694,6 +714,15 @@ | ||
| 694 | 714 | } |
| 695 | 715 | } |
| 696 | 716 | |
| 717 | + public async wasAnyOneIndexAdded() { | |
| 718 | + const indexes = await this.getIndexesToBuild(); | |
| 719 | + return !indexes.every((index) => | |
| 720 | + this.builtIndexes.some( | |
| 721 | + (builtIndex) => builtIndex.artifactId === index.artifactId, | |
| 722 | + ), | |
| 723 | + ); | |
| 724 | + } | |
| 725 | + | |
| 697 | 726 | public async refreshCodebaseIndex(paths: string[]) { |
| 698 | 727 | if (!this.indexingCancellationController.signal.aborted) { |
| 699 | 728 | this.indexingCancellationController.abort(); |
modified gui/src/context/SubmenuContextProviders.tsx +5 −4
| @@ -208,7 +208,7 @@ | ||
| 208 | 208 | |
| 209 | 209 | const interval = setInterval(refreshOpenFiles, 2000); |
| 210 | 210 | |
| 211 | - refreshOpenFiles(); // Initial call | |
| 211 | + void refreshOpenFiles(); // Initial call | |
| 212 | 212 | |
| 213 | 213 | return () => { |
| 214 | 214 | isMounted = false; |
| @@ -475,7 +475,8 @@ | ||
| 475 | 475 | providers === "all" |
| 476 | 476 | ? true |
| 477 | 477 | : providers === "dependsOnIndexing" |
| 478 | - ? description.dependsOnIndexing | |
| 478 | + ? description.dependsOnIndexing && | |
| 479 | + description.dependsOnIndexing?.length > 0 | |
| 479 | 480 | : providers.includes(description.title); |
| 480 | 481 | |
| 481 | 482 | if (!refreshProvider) { |
| @@ -589,7 +590,7 @@ | ||
| 589 | 590 | useWebviewListener( |
| 590 | 591 | "refreshSubmenuItems", |
| 591 | 592 | async (data) => { |
| 592 | - loadSubmenuItems(data.providers); | |
| 593 | + void loadSubmenuItems(data.providers); | |
| 593 | 594 | }, |
| 594 | 595 | [loadSubmenuItems], |
| 595 | 596 | ); |
| @@ -607,7 +608,7 @@ | ||
| 607 | 608 | ) |
| 608 | 609 | .map((provider) => provider.title); |
| 609 | 610 | if (newTitles.length > 0) { |
| 610 | - loadSubmenuItems(newTitles); | |
| 611 | + void loadSubmenuItems(newTitles); | |
| 611 | 612 | } |
| 612 | 613 | lastProviders.current = submenuContextProviders; |
| 613 | 614 | }, [loadSubmenuItems, submenuContextProviders]); |