Skip to content

Commit d4fb901

Browse files
committed
Move refreshUpdateTime calls to Workspace
1 parent 3e7c947 commit d4fb901

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

Tool/Sources/Workspace/Workspace.swift

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,24 +123,18 @@ public final class Workspace {
123123
fileURL: fileURL,
124124
onSave: { [weak self] filespace in
125125
guard let self else { return }
126-
for plugin in self.plugins.values {
127-
plugin.didSaveFilespace(filespace)
128-
}
126+
self.didSaveFilespace(filespace)
129127
},
130128
onClose: { [weak self] url in
131129
guard let self else { return }
132-
for plugin in self.plugins.values {
133-
plugin.didCloseFilespace(url)
134-
}
130+
self.didCloseFilespace(url)
135131
}
136132
)
137133
if filespaces[fileURL] == nil {
138134
filespaces[fileURL] = filespace
139135
}
140136
if existedFilespace == nil {
141-
for plugin in plugins.values {
142-
plugin.didOpenFilespace(filespace)
143-
}
137+
didOpenFilespace(filespace)
144138
} else {
145139
filespace.refreshUpdateTime()
146140
}
@@ -154,10 +148,37 @@ public final class Workspace {
154148

155149
@WorkspaceActor
156150
public func didUpdateFilespace(fileURL: URL, content: String) {
151+
refreshUpdateTime()
157152
guard let filespace = filespaces[fileURL] else { return }
153+
filespace.refreshUpdateTime()
158154
for plugin in plugins.values {
159155
plugin.didUpdateFilespace(filespace, content: content)
160156
}
161157
}
158+
159+
@WorkspaceActor
160+
func didOpenFilespace(_ filespace: Filespace) {
161+
refreshUpdateTime()
162+
openedFileRecoverableStorage.openFile(fileURL: filespace.fileURL)
163+
for plugin in plugins.values {
164+
plugin.didOpenFilespace(filespace)
165+
}
166+
}
167+
168+
@WorkspaceActor
169+
func didCloseFilespace(_ fileURL: URL) {
170+
for plugin in self.plugins.values {
171+
plugin.didCloseFilespace(fileURL)
172+
}
173+
}
174+
175+
@WorkspaceActor
176+
func didSaveFilespace(_ filespace: Filespace) {
177+
refreshUpdateTime()
178+
filespace.refreshUpdateTime()
179+
for plugin in plugins.values {
180+
plugin.didSaveFilespace(filespace)
181+
}
182+
}
162183
}
163184

Tool/Sources/WorkspaceSuggestionService/SuggestionWorkspacePlugin.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ public final class SuggestionServiceWorkspacePlugin: WorkspacePlugin {
9595
}
9696

9797
public func notifyOpenFile(filespace: Filespace) {
98-
workspace?.refreshUpdateTime()
99-
workspace?.openedFileRecoverableStorage.openFile(fileURL: filespace.fileURL)
10098
Task {
10199
guard !(await filespace.isGitIgnored) else { return }
102100
// check if file size is larger than 15MB, if so, return immediately
@@ -114,8 +112,6 @@ public final class SuggestionServiceWorkspacePlugin: WorkspacePlugin {
114112
}
115113

116114
public func notifyUpdateFile(filespace: Filespace, content: String) {
117-
filespace.refreshUpdateTime()
118-
workspace?.refreshUpdateTime()
119115
Task {
120116
guard !(await filespace.isGitIgnored) else { return }
121117
try await suggestionService?.notifyChangeTextDocument(
@@ -126,8 +122,6 @@ public final class SuggestionServiceWorkspacePlugin: WorkspacePlugin {
126122
}
127123

128124
public func notifySaveFile(filespace: Filespace) {
129-
filespace.refreshUpdateTime()
130-
workspace?.refreshUpdateTime()
131125
Task {
132126
guard !(await filespace.isGitIgnored) else { return }
133127
try await suggestionService?.notifySaveTextDocument(fileURL: filespace.fileURL)

0 commit comments

Comments
 (0)