Setup
The IDE does not install Swift tools. Install a toolchain, which bringsswift, sourcekit-lsp and lldb-dap:
- macOS: install Xcode, or only the Command Line Tools (
xcode-select --install). Xcode is needed for iOS, macOS app and other Apple platform projects. - Linux and Windows: install a toolchain from swift.org.
sourcekit-lsp is not found, opening a Swift file shows an install hint instead of an Install button. On macOS, /usr/bin/sourcekit-lsp runs the copy from the Xcode chosen with xcode-select (or DEVELOPER_DIR, see Several Xcode versions). To use another binary, set Executable for sourcekit-lsp in Settings › Languages & Frameworks › Language Servers.
Language server
sourcekit-lsp finds the workspace root by looking up from the file for one of these files:Package.swift, buildServer.json, compile_commands.json or .sourcekit-lsp. The outermost folder within the project that has one becomes the root; without any, the project folder is the root.
sourcekit-lsp then reads the build settings for that root:
- SwiftPM: a root with
Package.swiftworks without setup. sourcekit-lsp resolves the package and its dependencies itself. - Build server: a
.bsp/*.jsonfile or abuildServer.jsonin the root points sourcekit-lsp at a Build Server Protocol server. Xcode projects use this (see Xcode projects). compile_commands.json: a compilation database, for example from CMake.
Package dependencies
Right-clickPackage.swift in the Project view or the editor, or use Find Action (⇧⌘A / Ctrl+Shift+A):
- Resolve Swift Packages runs
swift package resolve: it fetches the dependencies and writesPackage.resolved. - Update Swift Packages runs
swift package update: it moves the dependencies to the newest versionsPackage.swiftallows.
Package.swift. sourcekit-lsp watches Package.swift and Package.resolved and reloads the package when either changes, including after git pull, so completion for a new dependency works without restarting the server.
.sourcekit-lsp/config.json holds sourcekit-lsp’s own options; see the sourcekit-lsp configuration reference.
Xcode projects
sourcekit-lsp cannot read.xcodeproj or .xcworkspace files. Without a build server, files in an Xcode project get no build settings, and you see errors such as “No such module”. Generate a buildServer.json in the project root with one of these tools:
-
xcode-build-server:
brew install xcode-build-server, then in the project root:Use-project App.xcodeprojinstead of-workspacefor a project without a workspace. xcode-build-server takes the compile flags from Xcode’s build logs, so build the scheme once in Xcode or withxcodebuildfirst, and build again after adding files or changing build settings. -
sourcekit-xcode-bsp: needs Xcode 26 or newer. Install it with
brew install slime-studio/tap/sourcekit-xcode-bspand runsourcekit-xcode-bsp initin the project root; it finds the.xcworkspaceor.xcodeprojitself and targets the iOS Simulator by default (theplatformfield inbuildServer.json). It is an early release (0.1.x).
buildServer.json (or .bsp/) as the project, or a parent of it with no other root marker between, so that it is the workspace root. After generating the file, reopen the project so that sourcekit-lsp starts with it.
Clean Build Folder (Build › Xcode, Find Action, or right-click the .xcodeproj / .xcworkspace) runs xcodebuild clean for the selected Xcode scheme in the Run tool window, with the same flags a run uses. Delete DerivedData moves this project’s DerivedData folder (the one xcodebuild -showBuildSettings reports, plus the IDE’s own run builds) to the Trash after asking, then restarts sourcekit-lsp. Other projects’ DerivedData is left alone.
New files in Xcode projects
xcodebuild compiles only the files a target lists, and the IDE does not edit project.pbxproj. What happens to a source file you create, rename or delete depends on how the project lists its files:
- Synchronized folders (Xcode 16 and newer): files in a folder shown with a blue folder icon in Xcode’s navigator belong to the folder’s targets as soon as they are on disk. To turn a classic group into one, right-click it in Xcode and choose Convert to Folder. New Xcode 16 projects use synchronized folders.
- Classic groups: a new file must be added to a target in Xcode (File › Add Files to…, or drag it into the group). When a new
.swift,.m,.hor other source file isn’t named inproject.pbxproj, the IDE says so, with Open in Xcode. - XcodeGen (
project.yml) and Tuist (Project.swift): the project is generated from the spec, so after files change the IDE offers to regenerate it (xcodegen generateortuist generate --no-open) in the Run tool window. Regenerate Xcode Project in Find Action (⌘⇧A/Ctrl+Shift+A), or in the context menu ofproject.ymlandProject.swift, runs it any time.
Several Xcode versions
To run sourcekit-lsp from a specific Xcode, setDEVELOPER_DIR in the server’s environment: in Settings › Languages & Frameworks › Language Servers, select sourcekit-lsp and add it under Startup › Environment variables, or in settings.toml:
DEVELOPER_DIR in the run configuration’s environment variables too.
Formatting
Reformat Code (⌥⌘L / Ctrl+Alt+L) uses sourcekit-lsp, which formats with swift-format from the same toolchain. swift-format reads its options from a .swift-format file in the file’s folder or a parent folder.
Run and debug
Single files
A.swift file can be run with Run Context Configuration (⌃⇧R / Ctrl+Shift+F10). The IDE runs swift <file> with the swift on your PATH.
SwiftPM packages
There are no SwiftPM run or test configurations yet. Runswift build, swift run and swift test in the terminal, or create a Shell Script configuration for them (see Run configurations).
Debugging
Debugging uses lldb-dap. On macOS the IDE finds Xcode’s copy throughxcrun -f lldb-dap; elsewhere it comes with the Swift toolchain on PATH. To debug a SwiftPM executable:
1
Build it
Run
swift build. The executable is written to .build/debug/<product>.2
Create a Program configuration
In Run › Edit Configurations…, add a Program configuration with Executable set to
.build/debug/<product> and Debug adapter set to lldb-dap (C, C++, Swift).3
Debug
Start it with Debug (
⌃D / Shift+F9).swift build after editing, as the configuration does not build first. Attach to Process… also attaches to a running Swift program with lldb-dap when CodeLLDB is not installed. See Debugging for breakpoints, stepping and the variables view.
Limitations
- There are no run, test or debug configurations for SwiftPM targets or Xcode schemes, and no test tree for XCTest or Swift Testing.
- Xcode projects need a
buildServer.jsonthat you generate yourself (see Xcode projects). - Expand Macro does nothing: sourcekit-lsp shows the expansion in a new document, which the IDE does not open yet.
- There is no SwiftUI Preview, Interface Builder, asset catalog editor or simulator integration. Use Xcode for those.
- sourcekit-lsp and lldb-dap are not installed by the IDE.