Fix deterministic workspace indexing and search#2178
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR refactors workspace search indexing to use structured concurrency with cancellable tasks, and updates tests to use the new async indexing API.
Changes:
- Introduced a cancellable
indexingTaskand new asyncindexProject()API, while keepingaddProjectToIndex()as a non-blocking entry point. - Reworked indexing progress publishing into MainActor-isolated helper methods and added cancellation cleanup.
- Simplified tests by awaiting indexing completion instead of polling with timeouts.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift | Adds indexingTask lifecycle management and cancels indexing on deinit. |
| CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+Index.swift | Refactors indexing into cancellable async flows; adds indexProject() and progress publishers. |
| CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+Find.swift | Switches result reset/search evaluation to structured concurrency and MainActor-safe updates. |
| CodeEditTests/Features/Documents/WorkspaceDocument+SearchState+IndexTests.swift | Updates tests to await indexProject() and assert completion state. |
| CodeEditTests/Features/Documents/WorkspaceDocument+SearchState+FindTests.swift | Updates tests to await indexProject() and assert completion state. |
| CodeEditTests/Features/Documents/WorkspaceDocument+SearchState+FindAndReplaceTests.swift | Updates tests to await indexProject() and removes polling waits. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d859b34 to
9f20f53
Compare
|
@thecoolwinter sorry for the direct ping, but you look like the most active recent maintainer in the repo history. Could you approve the fork PR workflow or route this to the right reviewer when you have a chance? Copilot review comments have been addressed and resolved in Local validation after the update:
The GitHub Actions run is currently |
Description
This PR makes workspace search indexing and search result publication deterministic.
It keeps the existing
addProjectToIndex()startup behavior as fire-and-forget, but moves the actual indexing work into an awaitableindexProject()path. That lets tests and explicit re-indexing callers wait until the index has been flushed instead of pollingindexStatuswith timing loops.The patch also replaces the search path's
DispatchGroupplus nestedTaskcompletion handling with structured concurrency.search(_:)now awaits result evaluation before publishing final search results, so callers do not observe stale or partially populated state.This is intentionally narrower than #1993. It does not replace the task notification system or introduce the broader activity manager refactor. The goal is to land the lifecycle contract fix first so indexing/search behavior is stable before any notification or activity API cleanup continues.
Main changes:
WorkspaceDocument.SearchStateaddProjectToIndex()non-blocking for startupindexProject() asyncfor deterministic indexing and testssearch(_:)await result evaluation beforesetSearchResults()Related Issues
Checklist
Validation
Ran with XcodeBuildMCP on macOS using
-skipPackagePluginValidation.22/22passedCodeEditTests/TaskNotificationHandlerTestsCodeEditTests/WorkspaceDocumentIndexTestsCodeEditTests/FindTestsCodeEditTests/FindAndReplaceTestsCodeEditTests:140passed,0failed,2skippedgit diff --check: cleanNote: the test run still reports an existing trailing-whitespace warning in
CodeEdit/WorkspaceView.swift:90, which is outside this diff.Screenshots
Not applicable. This PR changes workspace indexing/search lifecycle behavior and tests, not UI presentation.