Skip to content

Commit 5ca9e8d

Browse files
committed
If a Workspace's project path is the prefix of a new Filespace's file path, reuse the workspace
1 parent d2a1578 commit 5ca9e8d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Core/Sources/Service/Workspace.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,20 @@ final class Workspace {
162162

163163
let projectURL = try await Environment.fetchCurrentProjectRootURL(fileURL)
164164
let workspaceURL = projectURL ?? fileURL
165-
let workspace = workspaces[workspaceURL] ?? Workspace(projectRootURL: workspaceURL)
165+
166+
let workspace = {
167+
if let existed = workspaces[workspaceURL] {
168+
return existed
169+
}
170+
// Reuse existed workspace if possible
171+
for (_, workspace) in workspaces {
172+
if fileURL.path.hasPrefix(workspace.projectRootURL.path) {
173+
return workspace
174+
}
175+
}
176+
return Workspace(projectRootURL: workspaceURL)
177+
}()
178+
166179
let filespace = workspace.createFilespaceIfNeeded(fileURL: fileURL)
167180
workspaces[workspaceURL] = workspace
168181
workspace.refreshUpdateTime()

0 commit comments

Comments
 (0)