@@ -856,6 +856,15 @@ extension SourceKitLSPServer {
856
856
return workspace
857
857
}
858
858
859
+ /// Determines the build system for the given workspace folder and creates a `Workspace` that uses this inferred build
860
+ /// system.
861
+ private func createWorkspaceWithInferredBuildSystem( workspaceFolder: DocumentURI ) async throws -> Workspace {
862
+ return try await self . createWorkspace (
863
+ workspaceFolder: workspaceFolder,
864
+ buildSystemSpec: determineBuildSystem ( forWorkspaceFolder: workspaceFolder, options: self . options)
865
+ )
866
+ }
867
+
859
868
func initialize( _ req: InitializeRequest ) async throws -> InitializeResult {
860
869
logger. logFullObjectInMultipleLogMessages ( header: " Initialize request " , AnyRequestType ( request: req) )
861
870
// If the client can handle `PeekDocumentsRequest`, they can enable the
@@ -916,34 +925,25 @@ extension SourceKitLSPServer {
916
925
if let workspaceFolders = req. workspaceFolders {
917
926
self . workspacesAndIsImplicit += await workspaceFolders. asyncCompactMap { workspaceFolder in
918
927
await orLog ( " Creating workspace from workspaceFolders " ) {
919
- let workspace = try await self . createWorkspace (
920
- workspaceFolder: workspaceFolder. uri,
921
- buildSystemSpec : determineBuildSystem ( forWorkspaceFolder : workspaceFolder . uri , options : self . options )
928
+ return (
929
+ workspace : try await self . createWorkspaceWithInferredBuildSystem ( workspaceFolder: workspaceFolder. uri) ,
930
+ isImplicit : false
922
931
)
923
- return ( workspace: workspace, isImplicit: false )
924
932
}
925
933
}
926
934
} else if let uri = req. rootURI {
927
- let workspace = await orLog ( " Creating workspace from rootURI " ) {
928
- try await self . createWorkspace (
929
- workspaceFolder: uri,
930
- buildSystemSpec: determineBuildSystem ( forWorkspaceFolder: uri, options: self . options)
935
+ await orLog ( " Creating workspace from rootURI " ) {
936
+ self . workspacesAndIsImplicit. append (
937
+ ( workspace: try await self . createWorkspaceWithInferredBuildSystem ( workspaceFolder: uri) , isImplicit: false )
931
938
)
932
939
}
933
- if let workspace {
934
- self . workspacesAndIsImplicit. append ( ( workspace: workspace, isImplicit: false ) )
935
- }
936
940
} else if let path = req. rootPath {
937
941
let uri = DocumentURI ( URL ( fileURLWithPath: path) )
938
- let workspace = await orLog ( " Creating workspace from rootPath " ) {
939
- try await self . createWorkspace (
940
- workspaceFolder: uri,
941
- buildSystemSpec: determineBuildSystem ( forWorkspaceFolder: uri, options: self . options)
942
+ await orLog ( " Creating workspace from rootPath " ) {
943
+ self . workspacesAndIsImplicit. append (
944
+ ( workspace: try await self . createWorkspaceWithInferredBuildSystem ( workspaceFolder: uri) , isImplicit: false )
942
945
)
943
946
}
944
- if let workspace {
945
- self . workspacesAndIsImplicit. append ( ( workspace: workspace, isImplicit: false ) )
946
- }
947
947
}
948
948
949
949
if self . workspaces. isEmpty {
@@ -1340,10 +1340,7 @@ extension SourceKitLSPServer {
1340
1340
if let added = notification. event. added {
1341
1341
let newWorkspaces = await added. asyncCompactMap { workspaceFolder in
1342
1342
await orLog ( " Creating workspace after workspace folder change " ) {
1343
- try await self . createWorkspace (
1344
- workspaceFolder: workspaceFolder. uri,
1345
- buildSystemSpec: determineBuildSystem ( forWorkspaceFolder: workspaceFolder. uri, options: self . options)
1346
- )
1343
+ try await self . createWorkspaceWithInferredBuildSystem ( workspaceFolder: workspaceFolder. uri)
1347
1344
}
1348
1345
}
1349
1346
self . workspacesAndIsImplicit += newWorkspaces. map { ( workspace: $0, isImplicit: false ) }
0 commit comments