Skip to content

Commit 46bf8aa

Browse files
committed
Fix a racing issue
1 parent 202450c commit 46bf8aa

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

Core/Sources/Service/WorkspaceExtension/Filespace+SuggestionService.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ struct FilespaceSuggestionSnapshotKey: FilespacePropertyKey {
1313
}
1414

1515
extension FilespacePropertyValues {
16+
@WorkspaceActor
1617
var suggestionSourceSnapshot: FilespaceSuggestionSnapshot {
1718
get { self[FilespaceSuggestionSnapshotKey.self] }
1819
set { self[FilespaceSuggestionSnapshotKey.self] = newValue }
1920
}
2021
}
2122

2223
extension Filespace {
24+
@WorkspaceActor
2325
func resetSnapshot() {
2426
// swiftformat:disable redundantSelf
2527
self.suggestionSourceSnapshot = FilespaceSuggestionSnapshotKey.createDefaultValue()

Core/Sources/Service/WorkspaceExtension/SuggestionWorkspacePlugin.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,6 @@ final class SuggestionServiceWorkspacePlugin: WorkspacePlugin {
5757
return true
5858
}
5959

60-
func canAutoTriggerGetSuggestions(
61-
forFileAt fileURL: URL,
62-
lines: [String],
63-
cursorPosition: CursorPosition
64-
) -> Bool {
65-
guard isRealtimeSuggestionEnabled else { return false }
66-
guard let filespace = filespaces[fileURL] else { return true }
67-
if lines.hashValue != filespace.suggestionSourceSnapshot.linesHash { return true }
68-
if cursorPosition != filespace.suggestionSourceSnapshot.cursorPosition { return true }
69-
return false
70-
}
71-
7260
override init(workspace: Workspace) {
7361
super.init(workspace: workspace)
7462

Tool/Sources/Workspace/Filespace.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ public protocol FilespacePropertyKey {
88
}
99

1010
public final class FilespacePropertyValues {
11-
var storage: [ObjectIdentifier: Any] = [:]
11+
private var storage: [ObjectIdentifier: Any] = [:]
1212

13+
@WorkspaceActor
1314
public subscript<K: FilespacePropertyKey>(_ key: K.Type) -> K.Value {
1415
get {
1516
if let value = storage[ObjectIdentifier(key)] as? K.Value {
@@ -65,7 +66,7 @@ public final class Filespace {
6566
}
6667

6768
private(set) var lastSuggestionUpdateTime: Date = Environment.now()
68-
var additionalProperties = FilespacePropertyValues()
69+
private var additionalProperties = FilespacePropertyValues()
6970
let fileSaveWatcher: FileSaveWatcher
7071
let onClose: (URL) -> Void
7172

@@ -87,6 +88,7 @@ public final class Filespace {
8788
}
8889
}
8990

91+
@WorkspaceActor
9092
public subscript<K>(
9193
dynamicMember dynamicMember: WritableKeyPath<FilespacePropertyValues, K>
9294
) -> K {

Tool/Sources/Workspace/Workspace.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ public protocol WorkspacePropertyKey {
1010
}
1111

1212
public class WorkspacePropertyValues {
13-
var storage: [ObjectIdentifier: Any] = [:]
13+
private var storage: [ObjectIdentifier: Any] = [:]
1414

15+
@WorkspaceActor
1516
public subscript<K: WorkspacePropertyKey>(_ key: K.Type) -> K.Value {
1617
get {
1718
if let value = storage[ObjectIdentifier(key)] as? K.Value {
@@ -56,7 +57,7 @@ public final class Workspace {
5657
}
5758
}
5859

59-
var additionalProperties = WorkspacePropertyValues()
60+
private var additionalProperties = WorkspacePropertyValues()
6061
public internal(set) var plugins = [ObjectIdentifier: WorkspacePlugin]()
6162
public let workspaceURL: URL
6263
public let projectRootURL: URL

0 commit comments

Comments
 (0)