@@ -229,16 +229,16 @@ package actor SourceKitLSPServer {
229229 // was added to it and thus currently doesn't know that it can handle that file. In that case, we shouldn't open
230230 // a new workspace for the same root. Instead, the existing workspace's build system needs to be reloaded.
231231 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 {
233233 continue
234234 }
235- guard !projectRoots. contains ( buildSystemKind . projectRoot) else {
235+ guard !projectRoots. contains ( buildSystemSpec . projectRoot) else {
236236 continue
237237 }
238238 guard
239239 let workspace = await orLog (
240240 " Creating workspace " ,
241- { try await createWorkspace ( workspaceFolder: uri, buildSystemKind : buildSystemKind ) }
241+ { try await createWorkspace ( workspaceFolder: uri, buildSystemSpec : buildSystemSpec ) }
242242 )
243243 else {
244244 continue
@@ -811,7 +811,7 @@ extension SourceKitLSPServer {
811811 /// If the build system that was determined for the workspace does not satisfy `condition`, `nil` is returned.
812812 private func createWorkspace(
813813 workspaceFolder: DocumentURI ,
814- buildSystemKind : BuildSystemKind ?
814+ buildSystemSpec : BuildSystemSpec ?
815815 ) async throws -> Workspace {
816816 guard let capabilityRegistry = capabilityRegistry else {
817817 struct NoCapabilityRegistryError : Error { }
@@ -835,7 +835,7 @@ extension SourceKitLSPServer {
835835 documentManager: self . documentManager,
836836 rootUri: workspaceFolder,
837837 capabilityRegistry: capabilityRegistry,
838- buildSystemKind : buildSystemKind ,
838+ buildSystemSpec : buildSystemSpec ,
839839 toolchainRegistry: self . toolchainRegistry,
840840 options: options,
841841 testHooks: testHooks,
@@ -858,6 +858,15 @@ extension SourceKitLSPServer {
858858 return workspace
859859 }
860860
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+
861870 func initialize( _ req: InitializeRequest ) async throws -> InitializeResult {
862871 logger. logFullObjectInMultipleLogMessages ( header: " Initialize request " , AnyRequestType ( request: req) )
863872 // If the client can handle `PeekDocumentsRequest`, they can enable the
@@ -918,34 +927,25 @@ extension SourceKitLSPServer {
918927 if let workspaceFolders = req. workspaceFolders {
919928 self . workspacesAndIsImplicit += await workspaceFolders. asyncCompactMap { workspaceFolder in
920929 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
924933 )
925- return ( workspace: workspace, isImplicit: false )
926934 }
927935 }
928936 } 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 )
933940 )
934941 }
935- if let workspace {
936- self . workspacesAndIsImplicit. append ( ( workspace: workspace, isImplicit: false ) )
937- }
938942 } else if let path = req. rootPath {
939943 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 )
944947 )
945948 }
946- if let workspace {
947- self . workspacesAndIsImplicit. append ( ( workspace: workspace, isImplicit: false ) )
948- }
949949 }
950950
951951 if self . workspaces. isEmpty {
@@ -957,7 +957,7 @@ extension SourceKitLSPServer {
957957 documentManager: self . documentManager,
958958 rootUri: req. rootURI,
959959 capabilityRegistry: self . capabilityRegistry!,
960- buildSystemKind : nil ,
960+ buildSystemSpec : nil ,
961961 toolchainRegistry: self . toolchainRegistry,
962962 options: options,
963963 testHooks: testHooks,
@@ -1343,10 +1343,7 @@ extension SourceKitLSPServer {
13431343 if let added = notification. event. added {
13441344 let newWorkspaces = await added. asyncCompactMap { workspaceFolder in
13451345 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)
13501347 }
13511348 }
13521349 self . workspacesAndIsImplicit += newWorkspaces. map { ( workspace: $0, isImplicit: false ) }
0 commit comments