(
tag: IndexTag,
results: RefreshIndexResults,
markComplete: MarkCompleteCallback,
repoName: string | undefined,
)
| 209 | } |
| 210 | |
| 211 | async *update( |
| 212 | tag: IndexTag, |
| 213 | results: RefreshIndexResults, |
| 214 | markComplete: MarkCompleteCallback, |
| 215 | repoName: string | undefined, |
| 216 | ): AsyncGenerator<IndexingProgressUpdate, any, unknown> { |
| 217 | const db = await SqliteDb.get(); |
| 218 | await CodeSnippetsCodebaseIndex._createTables(db); |
| 219 | const tagString = tagToString(tag); |
| 220 | |
| 221 | // Compute |
| 222 | for (let i = 0; i < results.compute.length; i++) { |
| 223 | const compute = results.compute[i]; |
| 224 | let snippets: SnippetChunk[] = []; |
| 225 | try { |
| 226 | snippets = await this.getSnippetsInFile( |
| 227 | compute.path, |
| 228 | await this.ide.readFile(compute.path), |
| 229 | ); |
| 230 | } catch (e) { |
| 231 | // If can't parse, assume malformatted code |
| 232 | } |
| 233 | |
| 234 | // Add snippets to sqlite |
| 235 | for (const snippet of snippets) { |
| 236 | const { lastID } = await db.run( |
| 237 | "REPLACE INTO code_snippets (path, cacheKey, content, title, signature, startLine, endLine) VALUES (?, ?, ?, ?, ?, ?, ?)", |
| 238 | [ |
| 239 | compute.path, |
| 240 | compute.cacheKey, |
| 241 | snippet.content, |
| 242 | snippet.title, |
| 243 | snippet.signature, |
| 244 | snippet.startLine, |
| 245 | snippet.endLine, |
| 246 | ], |
| 247 | ); |
| 248 | |
| 249 | await db.run( |
| 250 | "REPLACE INTO code_snippets_tags (snippetId, tag) VALUES (?, ?)", |
| 251 | [lastID, tagString], |
| 252 | ); |
| 253 | } |
| 254 | |
| 255 | yield { |
| 256 | desc: `Indexing ${getUriPathBasename(compute.path)}`, |
| 257 | progress: i / results.compute.length, |
| 258 | status: "indexing", |
| 259 | }; |
| 260 | await markComplete([compute], IndexResultType.Compute); |
| 261 | } |
| 262 | |
| 263 | // Delete |
| 264 | for (let i = 0; i < results.del.length; i++) { |
| 265 | const del = results.del[i]; |
| 266 | |
| 267 | const snippets = await db.all( |
| 268 | "SELECT id FROM code_snippets WHERE path = ? AND cacheKey = ?", |
nothing calls this directly
no test coverage detected