多数功能只对根目录含 Package.swift 的 Swift Package Manager 项目生效,对 .xcodeproj 支持有限;调试依赖单独安装的 LLDB DAP 扩展;需要本机已安装 Swift 工具链
在 VS Code 扩展市场安装 Swift 扩展;调试需另行安装 LLDB DAP 扩展README 未说明
在 VS Code 里写 Swift 的官方扩展,为 SwiftPM 项目提供补全、跳转、调试和测试支持
在 VS Code 里写 Swift 的官方扩展,提供语法高亮、代码补全、调试和包管理集成,省去另开 Xcode 的麻烦。
核心能力
- 基于 SourceKit LSP 提供代码补全与符号跳转
- 支持跳转定义、查看定义、查找引用和符号搜索
- 标注错误并给出修复建议
- 自动生成 LLDB DAP 调试启动配置
- 提供项目面板和测试资源管理器视图
容易踩的坑
- 2.18.0最新正式版2026-11-05 · 2026-11-05 15:31 UTC
Added
- Diagnostics with
remarkseverity are now shown in the Problems pane (#2338) - Toolchain changes will now automatically reload the workspace (#2196)
- Add a button that installs Swiftly and the latest Swift toolchain to the extension's welcome walkthrough (#2078)
- Add syntax highlighing for DocC Tutorial files (#2320)
- Add
swift.logFileLogLevelsetting to control the verbosity of the extension's log file (#2379) - Add
traceoption to theswift.outputChannelLogLevelsetting (#2379)
Changed
swift.sourcekit-lsp.serverPathandswift.sourcekit-lsp.serverArgumentsare nowmachinescoped, so they can only be set in user settings (#2369)
Removed
- The deprecated
swift.diagnosticssetting. Useswift.outputChannelLogLevelinstead.
Fixed
- Loading large projects will no longer show the extension as unresponsive (#1932)
- Parameterized tests with very large numbers of test cases no longer slow the Test Explorer to a crawl (#2364)
- Pressing Ctrl+C in a test run's task terminal no longer hangs the test run and the task queue (#2420)
- Capturing a diagnostics bundle will no longer fail if the extension fails to activate (#2273)
- Make sure the start of swift-testing runs is not missed (#2365)
- Starting a new test run while another is still finishing no longer drops the new run (#2398)
- Code coverage reports no longer include build, test and excluded files when the package path contains regular expression characters such as parentheses (#2410)
- Saving Package.swift no longer clears the package's compiler errors from the Problems view (#2405)
- Unediting a dependency with uncommitted changes now asks whether to force it, and dismissing the prompt keeps the changes (#2404)
- Removing a folder while its tests are being discovered no longer starts a build that keeps running after the folder is gone (#2419)
- Saving Package.swift repeatedly no longer queues duplicate
swift package resolveruns (#2407) - Test Explorer and playground code lenses now update while editing files in packages whose names share a prefix with another package (#2408)
- Diagnostics with
- 2.16.72026-08-18 · 2026-08-18 17:54 UTC
查看更新说明
Added
- Add Clean Build Folder automatically generated task to remove all build artifacts (#2280)
Fixed
- Reveal the task terminal when clicking the Swift build status item instead of showing a popup (#2254)
- Update sourcekit-lsp schema logic for new branch structure (#2270)
- Work around an issue in older lldb-dap binaries where breakpoints would show up as unresolved even when they were hit (#2283)
- Stop assuming that
swift.pathwill point at a directory namedbin(#2288) - Fixed code coverage information only showing for the first test target when buildnig with swift-build (#2296)
- Fixed test run never completing when stopping a debug session (#2329)
- 2.16.62026-06-05 · 2026-06-05 14:40 UTC
- 2.16.52026-05-27 · 2026-05-27 15:44 UTC
查看更新说明
Added
- Add
swift.sourcekit-lsp.includeDeclarationInFindAllReferencessetting to control whether the symbol declaration is included in Find All References results (#2236) - Add support for swift-testing warnings (#2244)
Fixed
- Fix swift-testing timeout when doing a Run All tests w/ multiple test targets when using swift-build (#2207)
- Run toolchain executables via
swiftly run <tool>when the active toolchain is managed by swiftly (#2177) - Run toolchain executables via
xcrun <tool>when the active toolchain is managed by Xcode (#2253) - Fix swift.buildPath being ignored by swift package plugin tasks (#2235)
- Fix nightly toolchains providing a value to
--swift-testing-event-stream-versionthat swift-testing doesn't support (#2247) - Fix error during toolchain selection when swiftly has no active toolchain (#2246)
- Add
- 2.16.42026-04-27 · 2026-04-27 18:35 UTC
查看更新说明
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Swift for Visual Studio Code
This extension adds language support for Swift to Visual Studio Code, providing a seamless experience for developing Swift applications on all supported platforms. It supports features such as:
- Code completion
- Jump to definition, peek definition, find all references and symbol search
- Error annotations and fix suggestions
- Automatic generation of launch configurations for debugging with LLDB DAP
- Automatic task creation
- A Project Panel to quickly run actions and view dependencies
- Test Explorer view
Note
Most features of the Swift for Visual Studio Code extension only work with projects that build with Swift Package Manager. These projects will have aPackage.swiftfile in their root folder. Support for Xcode projects (.xcodeproj) is limited.
Creating New Projects
Building and Running Executables
Debugging Executables
Running Tests
Documentation
The getting started guide and official documentation for this extension are available on swift.org.
This extension uses SourceKit LSP for the language server, which powers code completion. It also has a dependency on the LLDB DAP extension to enable debugging.
To propose new features, you can post on the swift.org forums in the VS Code Swift Extension category. If you run into something that doesn't work the way you'd expect, you can file an issue in the GitHub repository.
Extension API
The Swift extension exports a comprehensive API that can be used by other Visual Studio Code extensions. The API provides access to:
- Swift Toolchains: The active Swift toolchain both globally and on a per-project basis.
- Swift Projects: A list of all known Swift projects in the active workspace.
- SPM Packages: Swift Package Manager targets, products, dependencies, and plugins.
The API includes a version number that follows semantic versioning and is separate from the extension's version number. See the contributing guide for a more detailed explanation on when this version number is incremented.
Using the API
To use the API in your extension you can download the src/SwiftExtensionApi.ts file from this repository to get proper TypeScript type definitions. It is recommended that you download the version from a tagged release as main is not guaranteed to remain stable.
Example usage:
import { getSwiftExtensionApi, SwiftExtensionApi } from './SwiftExtensionApi';
// Get the Swift extension API
const api: SwiftExtensionApi = await getSwiftExtensionApi();
// Access workspace context
const workspaceContext = api.workspaceContext;
if (workspaceContext) {
// Get the toolchain version
const toolchain = workspaceContext.globalToolchain;
console.log(`Using Swift ${toolchain.swiftVersion}`);
// Listen for folder changes
workspaceContext.onDidChangeFolders((event) => {
console.log(`Folder operation: ${event.operation}`);
});
// Access the in focus folder and its Swift package
const currentFolder = workspaceContext.currentFolder;
if (currentFolder) {
const swiftPackage = currentFolder.swiftPackage;
const targets = await swiftPackage.targets;
console.log(`Found ${targets.length} targets`);
}
}
Contributing
The Swift for Visual Studio Code extension is based on an extension originally created by the Swift Server Working Group. It is now maintained as part of the swiftlang organization, and the original extension is deprecated. Contributions, including code, tests, and documentation, are welcome. For more details, refer to CONTRIBUTING.md.
To provide clarity on the expectations for our members, Swift has adopted the code of conduct outlined in the Contributor Covenant. This widely recognized document effectively encapsulates our values. For more information, please refer to the Code of Conduct.