Changesets · Branches · Tags · Compare
| Changeset | 7cc464ab07518cbe15aa087e8574f9795085c4bb143400a12390e0f9130aeff0 |
|---|---|
| Author | Ting-Wai To <tingwai.to@gmail.com> · 2025-07-01 13:33 -07:00 |
| Committer | Ting-Wai To <tingwai.to@gmail.com> · 2025-07-02 10:13 -07:00 |
| Parents | 54bc82ab2ee9 |
7 files changed
modified core/index.d.ts +1 −0
| @@ -57,6 +57,7 @@ | ||
| 57 | 57 | | "disabled" |
| 58 | 58 | | "cancelled"; |
| 59 | 59 | debugInfo?: string; |
| 60 | + warnings?: string[]; | |
| 60 | 61 | } |
| 61 | 62 | |
| 62 | 63 | // This is more or less a V2 of IndexingProgressUpdate for docs etc. |
modified core/indexing/CodeSnippetsIndex.ts +2 −2
| @@ -35,7 +35,8 @@ | ||
| 35 | 35 | |
| 36 | 36 | export class CodeSnippetsCodebaseIndex implements CodebaseIndex { |
| 37 | 37 | relativeExpectedTime: number = 1; |
| 38 | - artifactId = "codeSnippets"; | |
| 38 | + static artifactId = "codeSnippets"; | |
| 39 | + artifactId: string = CodeSnippetsCodebaseIndex.artifactId; | |
| 39 | 40 | |
| 40 | 41 | constructor(private readonly ide: IDE) {} |
| 41 | 42 | |
| @@ -220,7 +221,6 @@ | ||
| 220 | 221 | // Compute |
| 221 | 222 | for (let i = 0; i < results.compute.length; i++) { |
| 222 | 223 | const compute = results.compute[i]; |
| 223 | - | |
| 224 | 224 | let snippets: SnippetChunk[] = []; |
| 225 | 225 | try { |
| 226 | 226 | snippets = await this.getSnippetsInFile( |
modified core/indexing/CodebaseIndexer.ts +140 −64
| @@ -48,6 +48,16 @@ | ||
| 48 | 48 | private codebaseIndexingState: IndexingProgressUpdate; |
| 49 | 49 | private readonly pauseToken: PauseToken; |
| 50 | 50 | |
| 51 | + private getUserFriendlyIndexName(artifactId: string): string { | |
| 52 | + if (artifactId === FullTextSearchCodebaseIndex.artifactId) | |
| 53 | + return "Full text search"; | |
| 54 | + if (artifactId === CodeSnippetsCodebaseIndex.artifactId) | |
| 55 | + return "Code snippets"; | |
| 56 | + if (artifactId === ChunkCodebaseIndex.artifactId) return "Chunking"; | |
| 57 | + if (artifactId.startsWith("vectordb")) return "Embedding"; | |
| 58 | + return artifactId; // fallback to original | |
| 59 | + } | |
| 60 | + | |
| 51 | 61 | // Note that we exclude certain Sqlite errors that we do not want to clear the indexes on, |
| 52 | 62 | // e.g. a `SQLITE_BUSY` error. |
| 53 | 63 | errorsRegexesToClearIndexesOn = [ |
| @@ -314,6 +324,7 @@ | ||
| 314 | 324 | status: "loading", |
| 315 | 325 | }; |
| 316 | 326 | const beginTime = Date.now(); |
| 327 | + let collectedWarnings: string[] = []; | |
| 317 | 328 | |
| 318 | 329 | for (const directory of dirs) { |
| 319 | 330 | const dirBasename = getUriPathBasename(directory); |
| @@ -344,45 +355,52 @@ | ||
| 344 | 355 | const repoName = await this.ide.getRepoName(directory); |
| 345 | 356 | let nextLogThreshold = 0; |
| 346 | 357 | |
| 347 | - try { | |
| 348 | - for await (const updateDesc of this.indexFiles( | |
| 349 | - directory, | |
| 350 | - directoryFiles, | |
| 351 | - branch, | |
| 352 | - repoName, | |
| 353 | - )) { | |
| 354 | - // Handle pausing in this loop because it's the only one really taking time | |
| 355 | - if (abortSignal.aborted) { | |
| 356 | - yield { | |
| 357 | - progress: 0, | |
| 358 | - desc: "Indexing cancelled", | |
| 359 | - status: "cancelled", | |
| 360 | - }; | |
| 361 | - return; | |
| 362 | - } | |
| 363 | - if (this.pauseToken.paused) { | |
| 364 | - yield* this.yieldUpdateAndPause(); | |
| 365 | - } | |
| 366 | - yield updateDesc; | |
| 367 | - if (updateDesc.progress >= nextLogThreshold) { | |
| 368 | - // log progress every 2.5% | |
| 369 | - nextLogThreshold += 0.025; | |
| 370 | - this.logProgress( | |
| 371 | - beginTime, | |
| 372 | - Math.floor(directoryFiles.length * updateDesc.progress), | |
| 373 | - updateDesc.progress, | |
| 374 | - ); | |
| 375 | - } | |
| 358 | + for await (const updateDesc of this.indexFiles( | |
| 359 | + directory, | |
| 360 | + directoryFiles, | |
| 361 | + branch, | |
| 362 | + repoName, | |
| 363 | + )) { | |
| 364 | + // Handle pausing in this loop because it's the only one really taking time | |
| 365 | + if (abortSignal.aborted) { | |
| 366 | + yield { | |
| 367 | + progress: 0, | |
| 368 | + desc: "Indexing cancelled", | |
| 369 | + status: "cancelled", | |
| 370 | + }; | |
| 371 | + return; | |
| 372 | + } | |
| 373 | + if (this.pauseToken.paused) { | |
| 374 | + yield* this.yieldUpdateAndPause(); | |
| 375 | + } | |
| 376 | + | |
| 377 | + // Collect warnings from indexFiles | |
| 378 | + if (updateDesc.warnings && updateDesc.warnings.length > 0) { | |
| 379 | + collectedWarnings = [...updateDesc.warnings]; | |
| 380 | + } | |
| 381 | + | |
| 382 | + yield updateDesc; | |
| 383 | + if (updateDesc.progress >= nextLogThreshold) { | |
| 384 | + // log progress every 2.5% | |
| 385 | + nextLogThreshold += 0.025; | |
| 386 | + this.logProgress( | |
| 387 | + beginTime, | |
| 388 | + Math.floor(directoryFiles.length * updateDesc.progress), | |
| 389 | + updateDesc.progress, | |
| 390 | + ); | |
| 376 | 391 | } |
| 377 | - } catch (err) { | |
| 378 | - yield this.handleErrorAndGetProgressUpdate(err); | |
| 379 | - return; | |
| 380 | 392 | } |
| 381 | 393 | } |
| 394 | + | |
| 395 | + // Final completion message with preserved warnings | |
| 382 | 396 | yield { |
| 383 | 397 | progress: 1, |
| 384 | - desc: "Indexing Complete", | |
| 398 | + desc: | |
| 399 | + collectedWarnings.length > 0 | |
| 400 | + ? `Indexing completed with ${collectedWarnings.length} warning(s)` | |
| 401 | + : "Indexing Complete", | |
| 385 | 402 | status: "done", |
| 403 | + warnings: collectedWarnings.length > 0 ? collectedWarnings : undefined, | |
| 386 | 404 | }; |
| 387 | 405 | this.logProgress(beginTime, 0, 1); |
| 388 | 406 | } |
| @@ -490,6 +508,8 @@ | ||
| 490 | 508 | const indexesToBuild = await this.getIndexesToBuild(); |
| 491 | 509 | let completedIndexCount = 0; |
| 492 | 510 | let progress = 0; |
| 511 | + const warnings: string[] = []; | |
| 512 | + | |
| 493 | 513 | for (const codebaseIndex of indexesToBuild) { |
| 494 | 514 | const tag: IndexTag = { |
| 495 | 515 | directory, |
| @@ -500,45 +520,101 @@ | ||
| 500 | 520 | progress: progress, |
| 501 | 521 | desc: `Planning changes for ${codebaseIndex.artifactId} index...`, |
| 502 | 522 | status: "indexing", |
| 523 | + warnings: warnings.length > 0 ? [...warnings] : undefined, | |
| 503 | 524 | }; |
| 504 | - const [results, lastUpdated, markComplete] = | |
| 505 | - await getComputeDeleteAddRemove( | |
| 506 | - tag, | |
| 507 | - { ...stats }, | |
| 508 | - (filepath) => this.ide.readFile(filepath), | |
| 509 | - repoName, | |
| 510 | - ); | |
| 511 | - const totalOps = this.totalIndexOps(results); | |
| 512 | - let completedOps = 0; | |
| 513 | 525 | |
| 514 | - // Don't update if nothing to update. Some of the indices might do unnecessary setup work | |
| 515 | - if (totalOps > 0) { | |
| 516 | - for (const subResult of this.batchRefreshIndexResults(results)) { | |
| 517 | - for await (const { desc } of codebaseIndex.update( | |
| 526 | + try { | |
| 527 | + const [results, lastUpdated, markComplete] = | |
| 528 | + await getComputeDeleteAddRemove( | |
| 518 | 529 | tag, |
| 519 | - subResult, | |
| 520 | - markComplete, | |
| 530 | + { ...stats }, | |
| 531 | + (filepath) => this.ide.readFile(filepath), | |
| 521 | 532 | repoName, |
| 522 | - )) { | |
| 523 | - yield { | |
| 524 | - progress, | |
| 525 | - desc, | |
| 526 | - status: "indexing", | |
| 527 | - }; | |
| 533 | + ); | |
| 534 | + const totalOps = this.totalIndexOps(results); | |
| 535 | + let completedOps = 0; | |
| 536 | + | |
| 537 | + // Don't update if nothing to update. Some of the indices might do unnecessary setup work | |
| 538 | + if (totalOps > 0) { | |
| 539 | + for (const subResult of this.batchRefreshIndexResults(results)) { | |
| 540 | + try { | |
| 541 | + for await (const { desc } of codebaseIndex.update( | |
| 542 | + tag, | |
| 543 | + subResult, | |
| 544 | + markComplete, | |
| 545 | + repoName, | |
| 546 | + )) { | |
| 547 | + yield { | |
| 548 | + progress, | |
| 549 | + desc, | |
| 550 | + status: "indexing", | |
| 551 | + warnings: warnings.length > 0 ? [...warnings] : undefined, | |
| 552 | + }; | |
| 553 | + } | |
| 554 | + completedOps += | |
| 555 | + subResult.compute.length + | |
| 556 | + subResult.del.length + | |
| 557 | + subResult.addTag.length + | |
| 558 | + subResult.removeTag.length; | |
| 559 | + progress = | |
| 560 | + (completedIndexCount + completedOps / totalOps) * | |
| 561 | + (1 / indexesToBuild.length); | |
| 562 | + } catch (err) { | |
| 563 | + // Collect non-fatal errors as warnings and continue | |
| 564 | + const warningMsg = | |
| 565 | + err instanceof Error ? err.message : String(err); | |
| 566 | + const friendlyName = this.getUserFriendlyIndexName( | |
| 567 | + codebaseIndex.artifactId, | |
| 568 | + ); | |
| 569 | + warnings.push(`${friendlyName}: ${warningMsg}`); | |
| 570 | + console.warn(`${friendlyName}: ${warningMsg}`, err); | |
| 571 | + | |
| 572 | + // Complete this batch and continue with next | |
| 573 | + completedOps += | |
| 574 | + subResult.compute.length + | |
| 575 | + subResult.del.length + | |
| 576 | + subResult.addTag.length + | |
| 577 | + subResult.removeTag.length; | |
| 578 | + progress = | |
| 579 | + (completedIndexCount + completedOps / totalOps) * | |
| 580 | + (1 / indexesToBuild.length); | |
| 581 | + } | |
| 528 | 582 | } |
| 529 | - completedOps += | |
| 530 | - subResult.compute.length + | |
| 531 | - subResult.del.length + | |
| 532 | - subResult.addTag.length + | |
| 533 | - subResult.removeTag.length; | |
| 534 | - progress = | |
| 535 | - (completedIndexCount + completedOps / totalOps) * | |
| 536 | - (1 / indexesToBuild.length); | |
| 537 | 583 | } |
| 584 | + | |
| 585 | + await markComplete(lastUpdated, IndexResultType.UpdateLastUpdated); | |
| 586 | + completedIndexCount += 1; | |
| 587 | + } catch (err) { | |
| 588 | + // Handle errors during planning phase | |
| 589 | + const cause = getRootCause(err as Error); | |
| 590 | + if (cause instanceof LLMError) { | |
| 591 | + // LLM errors are critical, re-throw them | |
| 592 | + throw cause; | |
| 593 | + } | |
| 594 | + | |
| 595 | + // Collect planning errors as warnings and continue to next index | |
| 596 | + const errorMsg = err instanceof Error ? err.message : String(err); | |
| 597 | + const friendlyName = this.getUserFriendlyIndexName( | |
| 598 | + codebaseIndex.artifactId, | |
| 599 | + ); | |
| 600 | + warnings.push(`${friendlyName}: ${errorMsg}`); | |
| 601 | + console.warn( | |
| 602 | + `Warning during ${codebaseIndex.artifactId} planning:`, | |
| 603 | + err, | |
| 604 | + ); | |
| 605 | + completedIndexCount += 1; | |
| 606 | + progress = completedIndexCount * (1 / indexesToBuild.length); | |
| 538 | 607 | } |
| 608 | + } | |
| 539 | 609 | |
| 540 | - await markComplete(lastUpdated, IndexResultType.UpdateLastUpdated); | |
| 541 | - completedIndexCount += 1; | |
| 610 | + // Final update with any collected warnings | |
| 611 | + if (warnings.length > 0) { | |
| 612 | + yield { | |
| 613 | + progress: 1, | |
| 614 | + desc: `Indexing completed with ${warnings.length} warning(s)`, | |
| 615 | + status: "done", | |
| 616 | + warnings: [...warnings], | |
| 617 | + }; | |
| 542 | 618 | } |
| 543 | 619 | } |
| 544 | 620 |
modified core/indexing/FullTextSearchCodebaseIndex.ts +1 −2
| @@ -55,7 +55,6 @@ | ||
| 55 | 55 | |
| 56 | 56 | for (let i = 0; i < results.compute.length; i++) { |
| 57 | 57 | const item = results.compute[i]; |
| 58 | - | |
| 59 | 58 | // Insert chunks |
| 60 | 59 | const chunks = await db.all( |
| 61 | 60 | "SELECT * FROM chunks WHERE path = ? AND cacheKey = ?", |
| @@ -68,7 +67,7 @@ | ||
| 68 | 67 | [item.path, chunk.content], |
| 69 | 68 | ); |
| 70 | 69 | await db.run( |
| 71 | - `INSERT INTO fts_metadata (id, path, cacheKey, chunkId) | |
| 70 | + `INSERT INTO fts_metadata (id, path, cacheKey, chunkId) | |
| 72 | 71 | VALUES (?, ?, ?, ?) |
| 73 | 72 | ON CONFLICT(id) DO UPDATE SET |
| 74 | 73 | path = excluded.path, |
modified core/indexing/README.md +3 −3
| @@ -20,10 +20,10 @@ | ||
| 20 | 20 | |
| 21 | 21 | All indexes must be returned by `getIndexesToBuild` in [`CodebaseIndexer.ts`](./CodebaseIndexer.ts) if they are to be used. |
| 22 | 22 | |
| 23 | -`CodeSnippetsCodebaseIndex`: uses tree-sitter queries to get a list of functions, classes, and other top-level code objects in each file | |
| 23 | +`CodeSnippetsIndex`: uses tree-sitter queries to get a list of functions, classes, and other top-level code objects in each file | |
| 24 | 24 | `FullTextSearchCodebaseIndex`: creates a full-text search index using SQLite FTS5 |
| 25 | -`ChunkCodebaseIndex`: chunks files recursively by code structure, for use in other embeddings providers like `LanceDbCodebaseIndex` | |
| 26 | -`LanceDbCodebaseIndex`: calculates embeddings for each chunk and adds them to the LanceDB vector database, with metadata going into SQLite. Note that for each branch, a unique table is created in LanceDB. | |
| 25 | +`ChunkCodebaseIndex`: chunks files recursively by code structure, for use in other embeddings providers like `LanceDbIndex` | |
| 26 | +`LanceDbIndex`: calculates embeddings for each chunk and adds them to the LanceDB vector database, with metadata going into SQLite. Note that for each branch, a unique table is created in LanceDB. | |
| 27 | 27 | |
| 28 | 28 | ## Known problems |
| 29 | 29 |
modified gui/src/pages/config/IndexingProgress/IndexingProgress.tsx +9 −7
| @@ -1,17 +1,18 @@ | ||
| 1 | 1 | import { IndexingProgressUpdate } from "core"; |
| 2 | +import { usePostHog } from "posthog-js/react"; | |
| 2 | 3 | import { useContext, useEffect, useState } from "react"; |
| 3 | 4 | import { useDispatch } from "react-redux"; |
| 5 | + | |
| 6 | +import ConfirmationDialog from "../../../components/dialogs/ConfirmationDialog"; | |
| 4 | 7 | import { IdeMessengerContext } from "../../../context/IdeMessenger"; |
| 5 | -import { isJetBrains } from "../../../util"; | |
| 6 | 8 | import { useWebviewListener } from "../../../hooks/useWebviewListener"; |
| 9 | +import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; | |
| 10 | +import { isJetBrains } from "../../../util"; | |
| 7 | 11 | import IndexingProgressBar from "./IndexingProgressBar"; |
| 12 | +import IndexingProgressErrorText from "./IndexingProgressErrorText"; | |
| 8 | 13 | import IndexingProgressIndicator from "./IndexingProgressIndicator"; |
| 9 | -import IndexingProgressTitleText from "./IndexingProgressTitleText"; | |
| 10 | 14 | import IndexingProgressSubtext from "./IndexingProgressSubtext"; |
| 11 | -import { usePostHog } from "posthog-js/react"; | |
| 12 | -import ConfirmationDialog from "../../../components/dialogs/ConfirmationDialog"; | |
| 13 | -import { setShowDialog, setDialogMessage } from "../../../redux/slices/uiSlice"; | |
| 14 | -import IndexingProgressErrorText from "./IndexingProgressErrorText"; | |
| 15 | +import IndexingProgressTitleText from "./IndexingProgressTitleText"; | |
| 15 | 16 | |
| 16 | 17 | export function getProgressPercentage( |
| 17 | 18 | progress: IndexingProgressUpdate["progress"], |
| @@ -119,7 +120,8 @@ | ||
| 119 | 120 | |
| 120 | 121 | <IndexingProgressSubtext update={update} onClick={onClick} /> |
| 121 | 122 | |
| 122 | - {update.status === "failed" && ( | |
| 123 | + {(update.status === "failed" || | |
| 124 | + (update.warnings && update.warnings.length > 0)) && ( | |
| 123 | 125 | <div className="mt-4"> |
| 124 | 126 | <IndexingProgressErrorText update={update} /> |
| 125 | 127 | </div> |
modified gui/src/pages/config/IndexingProgress/IndexingProgressErrorText.tsx +81 −1
| @@ -1,12 +1,27 @@ | ||
| 1 | -import { XCircleIcon } from "@heroicons/react/24/outline"; | |
| 1 | +import { | |
| 2 | + ArrowTopRightOnSquareIcon, | |
| 3 | + ChevronRightIcon, | |
| 4 | + ClipboardIcon, | |
| 5 | + XCircleIcon, | |
| 6 | +} from "@heroicons/react/24/outline"; | |
| 2 | 7 | import { IndexingProgressUpdate } from "core"; |
| 8 | +import { useContext, useState } from "react"; | |
| 9 | +import { GhostButton } from "../../../components"; | |
| 10 | +import { IdeMessengerContext } from "../../../context/IdeMessenger"; | |
| 3 | 11 | import { useAppSelector } from "../../../redux/hooks"; |
| 4 | 12 | |
| 5 | 13 | export interface IndexingProgressErrorTextProps { |
| 6 | 14 | update: IndexingProgressUpdate; |
| 7 | 15 | } |
| 8 | 16 | |
| 17 | +const copyWarningsToClipboard = (warnings: string[] = []) => { | |
| 18 | + const warningsText = warnings.join("\n"); | |
| 19 | + void navigator.clipboard.writeText(warningsText); | |
| 20 | +}; | |
| 21 | + | |
| 9 | 22 | function IndexingProgressErrorText({ update }: IndexingProgressErrorTextProps) { |
| 23 | + const ideMessenger = useContext(IdeMessengerContext); | |
| 24 | + const [showWarnings, setShowWarnings] = useState(false); | |
| 10 | 25 | const embeddingsProvider = useAppSelector( |
| 11 | 26 | (state) => state.config.config.selectedModelByRole.embed, |
| 12 | 27 | ); |
| @@ -30,6 +45,71 @@ | ||
| 30 | 45 | ); |
| 31 | 46 | } |
| 32 | 47 | |
| 48 | + // Show warnings if they exist (for completed indexing with warnings) | |
| 49 | + if ( | |
| 50 | + update.warnings && | |
| 51 | + update.warnings.length > 0 && | |
| 52 | + update.status !== "failed" | |
| 53 | + ) { | |
| 54 | + return ( | |
| 55 | + <div> | |
| 56 | + <div | |
| 57 | + className="flex cursor-pointer items-center gap-2 italic text-yellow-600" | |
| 58 | + onClick={() => setShowWarnings(!showWarnings)} | |
| 59 | + > | |
| 60 | + <span className="leading-relaxed"> | |
| 61 | + {update.warnings.length} warning | |
| 62 | + {update.warnings.length > 1 ? "s" : ""} during indexing | |
| 63 | + </span> | |
| 64 | + <ChevronRightIcon | |
| 65 | + className={`h-3 w-3 transition-transform duration-300 ${ | |
| 66 | + showWarnings ? "rotate-90" : "" | |
| 67 | + }`} | |
| 68 | + /> | |
| 69 | + </div> | |
| 70 | + | |
| 71 | + <div | |
| 72 | + className={`ml-3 overflow-hidden transition-all duration-300 ease-in-out ${ | |
| 73 | + showWarnings ? "mt-2 max-h-96 opacity-100" : "max-h-0 opacity-0" | |
| 74 | + }`} | |
| 75 | + > | |
| 76 | + {/* Warning messages */} | |
| 77 | + <div className="space-y-1"> | |
| 78 | + {update.warnings.map((warning, index) => ( | |
| 79 | + <div key={index} className="text-xs"> | |
| 80 | + • {warning} | |
| 81 | + </div> | |
| 82 | + ))} | |
| 83 | + </div> | |
| 84 | + | |
| 85 | + {/* Action Buttons */} | |
| 86 | + <div className="flex flex-row items-center justify-end gap-2 pt-4"> | |
| 87 | + {/* Copy all warnings to clipboard */} | |
| 88 | + <GhostButton | |
| 89 | + onClick={() => copyWarningsToClipboard(update.warnings)} | |
| 90 | + className="flex items-center !px-1.5 !py-0.5 text-xs" | |
| 91 | + > | |
| 92 | + <ClipboardIcon className="mr-1 h-3 w-3" /> | |
| 93 | + <span>Copy output</span> | |
| 94 | + </GhostButton> | |
| 95 | + | |
| 96 | + {/* Open dev tools to view logs */} | |
| 97 | + <GhostButton | |
| 98 | + onClick={() => { | |
| 99 | + ideMessenger.post("toggleDevTools", undefined); | |
| 100 | + }} | |
| 101 | + className="flex items-center !px-1.5 !py-0.5 text-xs" | |
| 102 | + > | |
| 103 | + <ArrowTopRightOnSquareIcon className="mr-1 h-3 w-3" /> | |
| 104 | + <span>View Logs</span> | |
| 105 | + </GhostButton> | |
| 106 | + </div> | |
| 107 | + </div> | |
| 108 | + </div> | |
| 109 | + ); | |
| 110 | + } | |
| 111 | + | |
| 112 | + // Show error for failed status | |
| 33 | 113 | return ( |
| 34 | 114 | <div className="flex items-center gap-2 italic text-red-600"> |
| 35 | 115 | <XCircleIcon className="h-4 w-4" /> |