| 1 | import { BaseContextProvider } from ".."; |
| 2 | import { |
| 3 | ContextItem, |
| 4 | ContextProviderDescription, |
| 5 | ContextProviderExtras, |
| 6 | ContextSubmenuItem, |
| 7 | LoadSubmenuItemsArgs, |
| 8 | } from "../../"; |
| 9 | import { walkDirs } from "../../indexing/walkDir"; |
| 10 | import generateRepoMap from "../../util/generateRepoMap"; |
| 11 | import { |
| 12 | getShortestUniqueRelativeUriPaths, |
| 13 | getUriPathBasename, |
| 14 | } from "../../util/uri"; |
| 15 | |
| 16 | const ENTIRE_PROJECT_ITEM: ContextSubmenuItem = { |
| 17 | id: "entire-codebase", |
| 18 | title: "Entire codebase", |
| 19 | description: "Search the entire codebase", |
| 20 | }; |
| 21 | |
| 22 | class RepoMapContextProvider extends BaseContextProvider { |
| 23 | static description: ContextProviderDescription = { |
| 24 | title: "repo-map", |
| 25 | displayTitle: "Repository Map", |
| 26 | description: "Select a folder", |
| 27 | type: "submenu", |
| 28 | }; |
| 29 | |
| 30 | async getContextItems( |
| 31 | query: string, |
| 32 | extras: ContextProviderExtras, |
| 33 | ): Promise<ContextItem[]> { |
| 34 | return [ |
| 35 | { |
| 36 | name: "Repository Map", |
| 37 | description: "Overview of the repository structure", |
| 38 | content: await generateRepoMap(extras.llm, extras.ide, { |
| 39 | dirUris: query === ENTIRE_PROJECT_ITEM.id ? undefined : [query], |
| 40 | outputRelativeUriPaths: true, |
| 41 | // Doesn't ALWAYS depend on indexing, so not setting dependsOnIndexing = true, just checking for it |
| 42 | includeSignatures: extras.config.disableIndexing |
| 43 | ? false |
| 44 | : (this.options?.includeSignatures ?? true), |
| 45 | }), |
| 46 | }, |
| 47 | ]; |
| 48 | } |
| 49 | |
| 50 | async loadSubmenuItems( |
| 51 | args: LoadSubmenuItemsArgs, |
| 52 | ): Promise<ContextSubmenuItem[]> { |
| 53 | const workspaceDirs = await args.ide.getWorkspaceDirs(); |
| 54 | const folders = await walkDirs( |
| 55 | args.ide, |
| 56 | { |
| 57 | include: "dirs", |
| 58 | source: "load submenu items - repo map", |
| 59 | }, |
| 60 | workspaceDirs, |
| 61 | ); |
| 62 | const withUniquePaths = getShortestUniqueRelativeUriPaths( |
| 63 | folders, |
| 64 | workspaceDirs, |
| 65 | ); |
| 66 | |
| 67 | return [ |
| 68 | ENTIRE_PROJECT_ITEM, |
| 69 | ...withUniquePaths.map((folder) => ({ |
| 70 | id: folder.uri, |
| 71 | title: getUriPathBasename(folder.uri), |
| 72 | description: folder.uniquePath, |
| 73 | })), |
| 74 | ]; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | export default RepoMapContextProvider; |