@@ -229,16 +229,16 @@ package actor SourceKitLSPServer {
229
229
// was added to it and thus currently doesn't know that it can handle that file. In that case, we shouldn't open
230
230
// a new workspace for the same root. Instead, the existing workspace's build system needs to be reloaded.
231
231
let uri = DocumentURI ( url)
232
- guard let buildSystemKind = determineBuildSystem ( forWorkspaceFolder: uri, options: self . options) else {
232
+ guard let buildSystemSpec = determineBuildSystem ( forWorkspaceFolder: uri, options: self . options) else {
233
233
continue
234
234
}
235
- guard !projectRoots. contains ( buildSystemKind . projectRoot) else {
235
+ guard !projectRoots. contains ( buildSystemSpec . projectRoot) else {
236
236
continue
237
237
}
238
238
guard
239
239
let workspace = await orLog (
240
240
" Creating workspace " ,
241
- { try await createWorkspace ( workspaceFolder: uri, buildSystemKind : buildSystemKind ) }
241
+ { try await createWorkspace ( workspaceFolder: uri, buildSystemSpec : buildSystemSpec ) }
242
242
)
243
243
else {
244
244
continue
@@ -811,7 +811,7 @@ extension SourceKitLSPServer {
811
811
/// If the build system that was determined for the workspace does not satisfy `condition`, `nil` is returned.
812
812
private func createWorkspace(
813
813
workspaceFolder: DocumentURI ,
814
- buildSystemKind : BuildSystemKind ?
814
+ buildSystemSpec : BuildSystemSpec ?
815
815
) async throws -> Workspace {
816
816
guard let capabilityRegistry = capabilityRegistry else {
817
817
struct NoCapabilityRegistryError : Error { }
@@ -835,7 +835,7 @@ extension SourceKitLSPServer {
835
835
documentManager: self . documentManager,
836
836
rootUri: workspaceFolder,
837
837
capabilityRegistry: capabilityRegistry,
838
- buildSystemKind : buildSystemKind ,
838
+ buildSystemSpec : buildSystemSpec ,
839
839
toolchainRegistry: self . toolchainRegistry,
840
840
options: options,
841
841
testHooks: testHooks,
@@ -858,6 +858,15 @@ extension SourceKitLSPServer {
858
858
return workspace
859
859
}
860
860
861
+ /// Determines the build system for the given workspace folder and creates a `Workspace` that uses this inferred build
862
+ /// system.
863
+ private func createWorkspaceWithInferredBuildSystem( workspaceFolder: DocumentURI ) async throws -> Workspace {
864
+ return try await self . createWorkspace (
865
+ workspaceFolder: workspaceFolder,
866
+ buildSystemSpec: determineBuildSystem ( forWorkspaceFolder: workspaceFolder, options: self . options)
867
+ )
868
+ }
869
+
861
870
func initialize( _ req: InitializeRequest ) async throws -> InitializeResult {
862
871
logger. logFullObjectInMultipleLogMessages ( header: " Initialize request " , AnyRequestType ( request: req) )
863
872
// If the client can handle `PeekDocumentsRequest`, they can enable the
@@ -918,34 +927,25 @@ extension SourceKitLSPServer {
918
927
if let workspaceFolders = req. workspaceFolders {
919
928
self . workspacesAndIsImplicit += await workspaceFolders. asyncCompactMap { workspaceFolder in
920
929
await orLog ( " Creating workspace from workspaceFolders " ) {
921
- let workspace = try await self . createWorkspace (
922
- workspaceFolder: workspaceFolder. uri,
923
- buildSystemKind : determineBuildSystem ( forWorkspaceFolder : workspaceFolder . uri , options : self . options )
930
+ return (
931
+ workspace : try await self . createWorkspaceWithInferredBuildSystem ( workspaceFolder: workspaceFolder. uri) ,
932
+ isImplicit : false
924
933
)
925
- return ( workspace: workspace, isImplicit: false )
926
934
}
927
935
}
928
936
} else if let uri = req. rootURI {
929
- let workspace = await orLog ( " Creating workspace from rootURI " ) {
930
- try await self . createWorkspace (
931
- workspaceFolder: uri,
932
- buildSystemKind: determineBuildSystem ( forWorkspaceFolder: uri, options: self . options)
937
+ await orLog ( " Creating workspace from rootURI " ) {
938
+ self . workspacesAndIsImplicit. append (
939
+ ( workspace: try await self . createWorkspaceWithInferredBuildSystem ( workspaceFolder: uri) , isImplicit: false )
933
940
)
934
941
}
935
- if let workspace {
936
- self . workspacesAndIsImplicit. append ( ( workspace: workspace, isImplicit: false ) )
937
- }
938
942
} else if let path = req. rootPath {
939
943
let uri = DocumentURI ( URL ( fileURLWithPath: path) )
940
- let workspace = await orLog ( " Creating workspace from rootPath " ) {
941
- try await self . createWorkspace (
942
- workspaceFolder: uri,
943
- buildSystemKind: determineBuildSystem ( forWorkspaceFolder: uri, options: self . options)
944
+ await orLog ( " Creating workspace from rootPath " ) {
945
+ self . workspacesAndIsImplicit. append (
946
+ ( workspace: try await self . createWorkspaceWithInferredBuildSystem ( workspaceFolder: uri) , isImplicit: false )
944
947
)
945
948
}
946
- if let workspace {
947
- self . workspacesAndIsImplicit. append ( ( workspace: workspace, isImplicit: false ) )
948
- }
949
949
}
950
950
951
951
if self . workspaces. isEmpty {
@@ -957,7 +957,7 @@ extension SourceKitLSPServer {
957
957
documentManager: self . documentManager,
958
958
rootUri: req. rootURI,
959
959
capabilityRegistry: self . capabilityRegistry!,
960
- buildSystemKind : nil ,
960
+ buildSystemSpec : nil ,
961
961
toolchainRegistry: self . toolchainRegistry,
962
962
options: options,
963
963
testHooks: testHooks,
@@ -1343,10 +1343,7 @@ extension SourceKitLSPServer {
1343
1343
if let added = notification. event. added {
1344
1344
let newWorkspaces = await added. asyncCompactMap { workspaceFolder in
1345
1345
await orLog ( " Creating workspace after workspace folder change " ) {
1346
- try await self . createWorkspace (
1347
- workspaceFolder: workspaceFolder. uri,
1348
- buildSystemKind: determineBuildSystem ( forWorkspaceFolder: workspaceFolder. uri, options: self . options)
1349
- )
1346
+ try await self . createWorkspaceWithInferredBuildSystem ( workspaceFolder: workspaceFolder. uri)
1350
1347
}
1351
1348
}
1352
1349
self . workspacesAndIsImplicit += newWorkspaces. map { ( workspace: $0, isImplicit: false ) }
0 commit comments