| 1 | import { |
| 2 | ContextItem, |
| 3 | ContextProviderDescription, |
| 4 | ContextProviderExtras, |
| 5 | } from "../../index.js"; |
| 6 | import { formatGrepSearchResults } from "../../util/grepSearch.js"; |
| 7 | import { BaseContextProvider } from "../index.js"; |
| 8 | |
| 9 | class SearchContextProvider extends BaseContextProvider { |
| 10 | static description: ContextProviderDescription = { |
| 11 | title: "search", |
| 12 | displayTitle: "Search", |
| 13 | description: "Use ripgrep to exact search the workspace", |
| 14 | type: "query", |
| 15 | renderInlineAs: "", |
| 16 | }; |
| 17 | |
| 18 | async getContextItems( |
| 19 | query: string, |
| 20 | extras: ContextProviderExtras, |
| 21 | ): Promise<ContextItem[]> { |
| 22 | const results = await extras.ide.getSearchResults(query); |
| 23 | const formatted = formatGrepSearchResults(results); |
| 24 | return [ |
| 25 | { |
| 26 | description: "Search results", |
| 27 | content: `Results of searching codebase for "${query}":\n\n${formatted}`, |
| 28 | name: "Search results", |
| 29 | }, |
| 30 | ]; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | export default SearchContextProvider; |