Skip to content

Refactored Activities for clarity and a consistent API #1993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2f63de4
Added global notifications system
austincondiff Feb 11, 2025
898a87c
Refactored FeatureIcon and notifications to support custom images
austincondiff Feb 11, 2025
418e540
Fixed SwiftLint errors
austincondiff Feb 11, 2025
14fc34f
Fixed SwiftLint errors
austincondiff Feb 12, 2025
2e73c75
Deleted unused file
austincondiff Feb 12, 2025
a0e7357
Added sticky notifications. Allowed multiple notifications to overlay…
austincondiff Feb 12, 2025
5ba7a66
Streamlined UI getting rid of the notifications popover in favor of t…
austincondiff Feb 13, 2025
e7216ca
Added a close button click state, allows clicking under scroll view.
austincondiff Feb 14, 2025
4bc9151
Remove test notification
austincondiff Feb 15, 2025
d636277
Improve notification handling and workspace panel behavior
austincondiff Feb 18, 2025
9df84a1
Fixed SwiftLint and PR issues
austincondiff Feb 18, 2025
951e899
Fixed animation glitch when taking action on a notification while not…
austincondiff Feb 19, 2025
4518e4c
Changed variable name isManuallyShown to isPresented, and notificatio…
austincondiff Feb 19, 2025
46adb4c
Refactored CENotification to use delegated inits.
austincondiff Feb 19, 2025
8abb2b5
Moved CloseButtonStyle into CodeEditUI and renamed it OverlayButtonStyle
austincondiff Feb 20, 2025
6bdde36
Using cancelables so workspace cleanup is more concise
austincondiff Feb 20, 2025
42f802e
Refactored Activities (previously TaskNotifications) to have a clear …
austincondiff Feb 20, 2025
596847c
Renamed a few files for consistency
austincondiff Feb 20, 2025
87ebaa7
Added Activities section to the Internal Developer Inspector for test…
austincondiff Feb 20, 2025
4b262f8
Fixed SwiftLint errors and made a few adjustments
austincondiff Feb 21, 2025
97d7f07
Added update and delete functions to notification manager.
austincondiff Feb 21, 2025
694d868
Fixed some tests
austincondiff Feb 21, 2025
e602eab
Put back window observer
austincondiff Feb 22, 2025
09e52d7
Clip the inspector so when scrolled, contents can't be seen under too…
austincondiff Feb 26, 2025
43ca864
Performance improvements
austincondiff Feb 27, 2025
ca6a3fc
Made fixes suggested in PR.
austincondiff Mar 4, 2025
c4f7479
Rebased from latest main
austincondiff Mar 4, 2025
6f2e611
Removed files inadvertedly added durring rebase
austincondiff Mar 4, 2025
17b940f
Rebased from main
austincondiff Mar 5, 2025
46c94d1
SwiftLint fix
austincondiff Mar 5, 2025
299ad40
Cleanup
austincondiff Mar 5, 2025
ce4f72c
Cleanup
austincondiff Mar 5, 2025
c858f66
Merge branch 'main' into activities-refactor
austincondiff May 12, 2025
403f480
Update CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocumen…
austincondiff May 12, 2025
6b02dfb
fix: Finish the continuation and await the consumtion of the stream
tom-ludwig May 14, 2025
61278fe
lint: fix linter warning
tom-ludwig May 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Made fixes suggested in PR.
  • Loading branch information
austincondiff committed Mar 5, 2025
commit ca6a3fcb8b76aa19ea27846f264f475d87939db7
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ extension WorkspaceDocument.SearchState {
isLoading: true
)
}

let (progressStream, continuation) = AsyncStream<Double>.makeStream()
// Dispatch this now, we want to continue after starting to monitor
Task { await self.monitorProgressStream(progressStream, activityId: activity.id) }

Task.detached {
let filePaths = self.getFileURLs(at: url)
Expand All @@ -33,16 +37,6 @@ extension WorkspaceDocument.SearchState {
// Batch our progress updates
var pendingProgress: Double?

func updateProgress(_ progress: Double) async {
await MainActor.run {
self.indexStatus = .indexing(progress: progress)
self.workspace.activityManager.update(
id: activity.id,
percentage: progress
)
}
}

for await (file, index) in AsyncFileIterator(fileURLs: filePaths) {
_ = await asyncController.addText(files: [file], flushWhenComplete: false)
let progress = Double(index) / Double(filePaths.count)
Expand All @@ -54,7 +48,7 @@ extension WorkspaceDocument.SearchState {

// Only update UI every 100ms
if index == filePaths.count - 1 || pendingProgress != nil {
await updateProgress(progress)
continuation.yield(progress)
pendingProgress = nil
}
}
Expand All @@ -77,6 +71,25 @@ extension WorkspaceDocument.SearchState {
}
}

/// Monitors a progress stream from ``addProjectToIndex()`` and updates ``indexStatus`` and the workspace's activity
/// manager accordingly.
///
/// Without this, updates can come too fast for `Combine` to handle and can cause crashes.
///
/// - Parameters:
/// - stream: The stream to monitor for progress updates, in %.
/// - activityId: The activity ID that's being monitored
@MainActor
private func monitorProgressStream(_ stream: AsyncStream<Double>, activityId: String) async {
for await progressUpdate in stream.debounce(for: .milliseconds(10)) {
self.indexStatus = .indexing(progress: progressUpdate)
self.workspace.activityManager.update(
id: activityId,
percentage: progressUpdate
)
}
}

/// Retrieves an array of file URLs within the specified directory URL.
///
/// - Parameter url: The URL of the directory to search for files.
Expand Down