Support different toolchains per folder #1478
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With the introduction of swiftly's
.swift-version
file the active toolchain can now be per-folder instead of global. If the user has multiple different packages open they may each be using a different toolchain as defined by their.swift-version
file.In order to support this new paradigm the
toolchain
has been moved fromWorkspaceContext
toFolderContext
. Each time a folder (package) is added to the workspace a new toolchain is created, as it might be different from folder to folder.The toolchain created respects the
.swift-version
file. If the toolchain specified in the.swift-version
file is not installed an error message is shown prompting the user to install the version with swiftly.There is still a
globalToolchain
on theWorkspaceContext
which refers to the globally available toolchain. This would be the toolchain used when you runswift
outside of a workspace folder. This is mainly used as a fallback toolchain for when there are no workspace folders.It is generally advisable to use the toolchain provided on the
FolderContext
to ensure you don't end up using mismatched versions.This PR also refactors the
LanguageClientManager
so that one instance of sourcekit-lsp is started per-toolchain, coordinating startup so that the server from a given toolchain starts up when a folder using that toolchain is added to the workspace.While this PR adds support for .swift-version files, there is still quite a bit of work to do to make using swiftly with the VS Code Swift extension a nicer experience including: Installing swiftly directly from the extension, downloading missing toolchains automatically, listing/picking/downloading toolchains via
swiftly list
, a smoother toolchain switching experience that would optionally write the.swift-version
file, and more.