Does SourceKit-LSP support multiple workspace folders, or does it just expect to find a Package.swift inside the root folder and use that.
I have two VSCode issues I'd like to resolve at the moment
- Currently when moving between workspaces in VSCode I am having to restart the server to point it at the correct workspace folder.
- I would like to support workspaces where the Swift package is not necessarily in the root folder. It is common for large server projects to be working across multiple languages and the Swift part is a sub-folder. Or there may even be multiple swift packages.
If I can't have multiple workspaces can I tell the server I am working from a new workspace root, instead of forcing it to restart?
sourcekit-lsp does not support workspace folders yet. We are using the URL that’s being passed as
rootPath to find the
Package.swift. Pointing the
rootUri to the directory that contains the
Package.swift file should allow you to open a Swift package in a subfolder though.
Also, looking at the protocol, I assume that the idea is to start a new LSP server when opening a new workspace since the root path is specified in the “Initialize” request which, IIUC, can only be sent once. So I think it is intended to start a new LSP server when opening a new workspace. If you want to have two workspaces open at once, can’t you have two sourcekit-lsp processes running, one for each workspace?
I have workspaces with 15+ packages. Do you think 15 lsp server instances is fine?
Ah, I misunderstood you. I thought you had multiple VSCode windows open and having a separate sourcekit-lsp process for each VSCode window is still what I would expect.
Launching 15 sourcekit-lsp servers is sub-optimal since each will launch its own SourceKitService, consuming 15 x ~300MB = 4.5GB of RAM… Having support for multiple workspaces within one sourcekit-lsp instance would definitely be preferred. Could you file a bug report on bugs.swift.org? I’ll try to get to it as soon as I’ve got time, but can’t make any promises.