(rootDir: string)
| 132 | } |
| 133 | |
| 134 | async function buildIndex(rootDir: string): Promise<SearchIndex> { |
| 135 | if (cachedIndex && cachedRootDir === rootDir && Date.now() - lastIndexTime < INDEX_TTL_MS) { |
| 136 | return cachedIndex; |
| 137 | } |
| 138 | |
| 139 | const entries = await walkDirectory({ rootDir, depthLimit: 0 }); |
| 140 | const files = entries.filter((e) => !e.isDirectory); |
| 141 | |
| 142 | const docs: SearchDocument[] = []; |
| 143 | for (const file of files) { |
| 144 | const doc = await buildSearchDocumentForFile(rootDir, file.relativePath); |
| 145 | if (doc) docs.push(doc); |
| 146 | } |
| 147 | |
| 148 | const index = new SearchIndex(); |
| 149 | await index.index(docs, rootDir); |
| 150 | cachedIndex = index; |
| 151 | cachedRootDir = rootDir; |
| 152 | lastIndexTime = Date.now(); |
| 153 | |
| 154 | return index; |
| 155 | } |
| 156 | |
| 157 | export async function semanticCodeSearch(options: SemanticSearchOptions): Promise<string> { |
| 158 | const index = await buildIndex(options.rootDir); |
no test coverage detected