Skip to content

Commit 4b262f8

Browse files
committed
Fixed SwiftLint errors and made a few adjustments
1 parent 87ebaa7 commit 4b262f8

8 files changed

Lines changed: 37 additions & 26 deletions

File tree

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3256,7 +3256,7 @@
32563256
attributes = {
32573257
BuildIndependentTargetsInParallel = 1;
32583258
LastSwiftUpdateCheck = 1330;
3259-
LastUpgradeCheck = 1540;
3259+
LastUpgradeCheck = 1620;
32603260
TargetAttributes = {
32613261
2BE487EB28245162003F3F64 = {
32623262
CreatedOnToolsVersion = 13.3.1;

CodeEdit/Features/Activities/ActivityManager.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Combine
1010
import SwiftUI
1111

1212
/// Manages activities for a workspace
13+
@MainActor
1314
final class ActivityManager: ObservableObject {
1415
/// Currently displayed activities
1516
@Published private(set) var activities: [CEActivity] = []
@@ -59,13 +60,13 @@ final class ActivityManager: ObservableObject {
5960
func update(
6061
id: String,
6162
title: String? = nil,
62-
message: String? = nil,
63+
message: String? = nil,
6364
percentage: Double? = nil,
6465
isLoading: Bool? = nil
6566
) {
6667
if let index = activities.firstIndex(where: { $0.id == id }) {
6768
var activity = activities[index]
68-
69+
6970
if let title = title {
7071
activity.title = title
7172
}
@@ -96,8 +97,9 @@ final class ActivityManager: ObservableObject {
9697
/// - id: ID of activity to delete
9798
/// - delay: Time to wait before deleting
9899
func delete(id: String, delay: TimeInterval) {
99-
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
100-
self?.delete(id: id)
100+
Task { @MainActor in
101+
try? await Task.sleep(for: .seconds(delay))
102+
delete(id: id)
101103
}
102104
}
103105
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
//
2+
// CEActivity.swift
3+
// CodeEdit
4+
//
5+
// Created by Austin Condiff on 2/20/25.
6+
//
7+
18
struct CEActivity: Equatable {
29
var id: String
310
var title: String
411
var message: String?
512
var percentage: Double?
613
var isLoading: Bool = false
7-
}
14+
}

CodeEdit/Features/Documents/Controllers/CodeEditSplitViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class CodeEditSplitViewController: NSSplitViewController {
4141

4242
override func viewDidLoad() {
4343
super.viewDidLoad()
44-
guard let windowRef else {
44+
guard windowRef != nil else {
4545
// swiftlint:disable:next line_length
4646
assertionFailure("No WindowRef found, not initialized properly or the window was dereferenced and the controller was not.")
4747
return

CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+Index.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@ import Foundation
1010
extension WorkspaceDocument.SearchState {
1111
/// Adds the contents of the current workspace URL to the search index.
1212
/// That means that the contents of the workspace will be indexed and searchable.
13-
func addProjectToIndex() {
13+
func addProjectToIndex() async {
1414
guard let indexer = indexer else { return }
1515
guard let url = workspace.fileURL else { return }
1616

1717
indexStatus = .indexing(progress: 0.0)
18-
18+
1919
// Create activity using new API
20-
let activity = workspace.activityManager.post(
21-
title: "Indexing | Processing files",
22-
message: "Creating an index to enable fast and accurate searches within your codebase.",
23-
isLoading: true
24-
)
20+
let activity = await MainActor.run {
21+
workspace.activityManager.post(
22+
title: "Indexing | Processing files",
23+
message: "Creating an index to enable fast and accurate searches within your codebase.",
24+
isLoading: true
25+
)
26+
}
2527

2628
Task.detached {
2729
let filePaths = self.getFileURLs(at: url)
@@ -39,8 +41,7 @@ extension WorkspaceDocument.SearchState {
3941
await MainActor.run {
4042
self.indexStatus = .indexing(progress: progress)
4143
}
42-
// Update activity using new API
43-
self.workspace.activityManager.update(
44+
await self.workspace.activityManager.update(
4445
id: activity.id,
4546
percentage: progress
4647
)
@@ -51,15 +52,14 @@ extension WorkspaceDocument.SearchState {
5152
await MainActor.run {
5253
self.indexStatus = .done
5354
}
54-
55-
// Update and delete activity using new API
56-
self.workspace.activityManager.update(
55+
56+
await self.workspace.activityManager.update(
5757
id: activity.id,
5858
title: "Finished indexing",
5959
isLoading: false
6060
)
61-
62-
self.workspace.activityManager.delete(
61+
62+
await self.workspace.activityManager.delete(
6363
id: activity.id,
6464
delay: 4.0
6565
)

CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+SearchState.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ extension WorkspaceDocument {
4747
init(_ workspace: WorkspaceDocument) {
4848
self.workspace = workspace
4949
self.indexer = SearchIndexer.Memory.create()
50-
addProjectToIndex()
50+
Task {
51+
await addProjectToIndex()
52+
}
5153
}
5254

5355
/// Represents the compare options to be used for find and replace.

CodeEdit/Features/InspectorArea/InternalDevelopmentInspector/InternalDevelopmentInspectorView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftUI
99

1010
struct InternalDevelopmentInspectorView: View {
1111
@EnvironmentObject var activityManager: ActivityManager
12-
12+
1313
var body: some View {
1414
Form {
1515
InternalDevelopmentActivitiesView()

CodeEditTests/Features/Activities/ActivityManagerTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class ActivityManagerTests: XCTestCase {
4141

4242
func testUpdateTask() {
4343
let activity = activityManager.post(title: "Task Title")
44-
44+
4545
activityManager.update(
4646
id: activity.id,
4747
title: "Updated Task Title"
@@ -53,7 +53,7 @@ final class ActivityManagerTests: XCTestCase {
5353
func testDeleteTask() {
5454
let activity = activityManager.post(title: "Task Title")
5555
activityManager.delete(id: activity.id)
56-
56+
5757
XCTAssertTrue(activityManager.activities.isEmpty)
5858
}
5959

@@ -62,7 +62,7 @@ final class ActivityManagerTests: XCTestCase {
6262
activityManager.delete(id: activity.id, delay: 0.2)
6363

6464
XCTAssertFalse(activityManager.activities.isEmpty)
65-
65+
6666
let expectation = XCTestExpectation()
6767
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
6868
XCTAssertTrue(self.activityManager.activities.isEmpty)

0 commit comments

Comments
 (0)