Aligned with Swift 6, Swift in Visual Studio Code (VS Code) is gaining a number of new features and improvements. Some of these features come with the Swift 6 version of SourceKit-LSP, which provides intelligent editor functionality to all editors that support the Language Server Protocol (LSP), including VS Code. Others are related to new functionality coming with Swift 6, or custom additions to the VS Code extension itself.
Testing
Along with existing support for XCTest, Swift for VS Code now has integration with swift-testing. Both types of tests appear in the VS Code Test Explorer and can be run, debugged, or run with code coverage. The swift-testing integration supports all the equivalent features from XCTest and some swift-testing specific features like custom test names, and test parameters.
In addition SourceKit-LSP now provides custom support for test discovery. Test locations are available as soon as your project has loaded into VS Code.
Code coverage
Recently VS Code introduced a framework for running code coverage tests and rendering the results. We have replaced the custom implementation we used previously with an integration with the new framework. Now coverage results are rendered in a pane included in the TestExplorer view.
Symbol rename
The new rename feature in SourceKit-LSP allows functions, types, variables, etc. to be renamed workspace-wide. It is fully aware of Swift-specific rename patterns like functions with argument labels and also allows cross-language rename of symbols shared with other languages through Swift’s C, C++, and Objective-C interop. Rename integrates into the standard VS Code rename workflow, such as the refactor preview window and can be invoked using Rename Symbol from the command palette or context menu.
Integration with swift-format
SourceKit-LSP integrates with swift-format to apply formatting to your source code. Formatting is available using Format Document from the command palette. It uses a default formatting style which can be customized by placing a .swift-format file in the root of your project.
Debug adapter
Up until this point we have been reliant on the CodeLLDB extension debug adapter to provide debugging support for Swift in VS Code. The Swift 6 toolchain comes with it's own LLDB debug adapter (lldb-dap). The extension has support for choosing between these two debug adapters.
Toolchain selection
You can select the Swift toolchain you are working with using the Swift: Select Toolchain... command. This provides options to select a toolchain directory or select from a platform specific list of toolchains available to you. On macOS you will get a list of toolchains attached to Xcode installs, and installed Swift nightly snapshots. On Linux the list will include a list of toolchains installed using Swiftly.
Background indexing of SwiftPM projects
SourceKit-LSP gained the ability to index SwiftPM projects in the background, which means that you no longer have to build the project to update the index and get cross-module functionality to work. Background indexing is currently available as an experimental feature. This guide describes how to enable it, if you are interested.
Check it out
On macOS you can check out all of the above by either downloading the latest Xcode 16 beta and selecting the Xcode beta toolchain using the new Select Toolchain... command from the command palette in VS Code or you can test inside a devcontainer, setup with the latest Swift 6 nightly docker image. On Linux and Windows you can download the latest Swift 6 nightly.