swift.md

 1---
 2title: Swift
 3description: "Configure Swift language support in Zed, including language servers, formatting, and debugging."
 4---
 5
 6# Swift
 7
 8Swift language support in Zed is provided by the community-maintained [Swift extension](https://github.com/zed-extensions/swift).
 9Report issues to: [https://github.com/zed-extensions/swift/issues](https://github.com/zed-extensions/swift/issues)
10
11- Tree-sitter: [alex-pinkus/tree-sitter-swift](https://github.com/alex-pinkus/tree-sitter-swift)
12- Language Server: [swiftlang/sourcekit-lsp](https://github.com/swiftlang/sourcekit-lsp)
13- Debug Adapter: [`lldb-dap`](https://github.com/swiftlang/llvm-project/blob/next/lldb/tools/lldb-dap/README.md)
14
15## Language Server Configuration
16
17You can modify the behavior of SourceKit LSP by creating a `.sourcekit-lsp/config.json` under your home directory or in your project root. See [SourceKit-LSP configuration file](https://github.com/swiftlang/sourcekit-lsp/blob/main/Documentation/Configuration%20File.md) for complete documentation.
18
19## Debugging
20
21The Swift extension provides a debug adapter for debugging Swift code.
22Zed's name for the adapter (in the UI and `debug.json`) is `Swift`, and under the hood it uses [`lldb-dap`](https://github.com/swiftlang/llvm-project/blob/next/lldb/tools/lldb-dap/README.md), as provided by the Swift toolchain.
23The extension tries to find an `lldb-dap` binary using `swiftly`, using `xcrun`, and by searching `$PATH`, in that order of preference.
24The extension doesn't attempt to download `lldb-dap` if it's not found.
25
26- [lldb-dap configuration documentation](https://github.com/llvm/llvm-project/blob/main/lldb/tools/lldb-dap/README.md#configuration-settings-reference)
27
28### Examples
29
30#### Build and debug a Swift binary
31
32```json [debug]
33[
34  {
35    "label": "Debug Swift",
36    "build": {
37      "command": "swift",
38      "args": ["build"]
39    },
40    "program": "$ZED_WORKTREE_ROOT/swift-app/.build/arm64-apple-macosx/debug/swift-app",
41    "request": "launch",
42    "adapter": "Swift"
43  }
44]
45```