Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ If you'd like to return to using the released version of the extension you can u

Occasionally, pre-release builds will be published to the VS Code Marketplace. You can switch to the pre-release version by clicking on the `Switch to Pre-Release Version` button in the Extensions View:

![](userdocs/userdocs.docc/install-pre-release.png)
![A snapshot of VS Code that has Extensions highlighted, showing the Swift extension. In the detail panel of the extension view, a red box highlights the button "Switch to Pre-Release Version".](userdocs/userdocs.docc/Resources/install-pre-release.png)

Switching back to the release version can be done by clicking on the `Switch to Release Version` button.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This extension adds language support for Swift to Visual Studio Code, providing

# Documentation

The official documentation for this extension is available at [vscode-swift](https://docs.swift.org/vscode/documentation/userdocs)
The official documentation for this extension is [available on swift.org](https://docs.swift.org/vscode/documentation/userdocs).

This extension uses [SourceKit LSP](https://github.com/apple/sourcekit-lsp) for the [language server](https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/), which powers code completion. It also has a dependency on the [LLDB DAP](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap) extension to enable debugging.

Expand Down
11 changes: 11 additions & 0 deletions userdocs/userdocs.docc/Articles/Advanced/install-pre-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Installing Pre-Release Builds

Try out the latest updates by switching to the pre-release version.

The Swift extension provides pre-release builds that you can use to test out unreleased features or get bug fixes before the project publishes an official release. Pre-release build numbers are one minor version ahead of the most recent release.

The "Switch to Pre-Release Version" button in the VS Code extensions view is used to install the latest pre-release builds:

![A snapshot of VS Code that has Extensions highlighted, showing the Swift extension. In the detail panel of the extension view, a red box highlights the button "Switch to Pre-Release Version".](install-pre-release.png)

When you select to use a pre-release version, the button changes to "Switch to Release Version", which lets you go back to the official release.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Visual Studio Code Dev Containers

Dev containers can be used as an easy way to develop when building for other platforms.
Create reusable development environments using containers.

[VS Code Dev Containers](https://code.visualstudio.com/docs/remote/containers) allows you to run your code and environment in a container. This is especially useful for Swift when developing on macOS and deploying to Linux. You can ensure there are no compatibility issues in Foundation when running your code. The extension also works with [GitHub Codespaces](https://github.com/features/codespaces) to allow you to write your code on the web.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Automatic Task Creation

Add tasks for common operations with your Package.

For workspaces that contain a `Package.swift` file, the Swift extension adds the following tasks:

- **Build All**: Build all targets in the Package.
- **Build Debug <Executable>**: Each executable in a Package.swift get a task for building a debug build.
- **Build Release <Executable>**: Each executable in a Package.swift get a task for building a release build.

> 💡 Tip: Tasks use workflows common to all VS Code extensions. For more information see [the VS Code documentation for tasks](https://code.visualstudio.com/docs/editor/tasks).

These tasks are available via the commands **Terminal ▸ Run Task...** and **Terminal ▸ Run Build Task...** in the command palette.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Debugging

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's subtle, but you might want to include an Availability marker on this page to indicate this works with Swift 6.0+:

Suggested change
@Metadata {
@Available("Swift", introduced: "6.0")
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this makes sense to set for debugging. You are able to debug with older toolchains: we just switched to lldb-dap instead of CodeLLDB in 6.0 and later.

vscode-swift allows you to debug your Swift packages.

> Tip: Debugging works best when using a version of the Swift toolchain 6.0 or higher
Debug your Swift executables using LLDB.

When you open a Swift package (a directory containing a `Package.swift` file), the extension automatically generates build tasks and launch configurations for each executable within the package. Additionally, if the package includes tests, the extension creates a configuration specifically designed to run those tests. These configurations all leverage the CodeLLDB extension as the debugger of choice.

Use the **Run > Start Debugging** menu item to run an executable and start debugging. If you have multiple launch configurations you can choose which launch configuration to use in the debugger view.
> 💡 Tip: Debugging workflows are common to all VS Code extensions. See the [VS Code documentation about testing](https://code.visualstudio.com/docs/debugtest/testing) for a more in-depth overview.
>
> Debugging works best when using a version of the Swift toolchain 6.0 or higher.

Debugging uses workflows common to all VSCode extensions. For more information see https://code.visualstudio.com/docs/editor/debugging
Use the **Run > Start Debugging** menu item to run an executable and start debugging. If you have multiple launch configurations you can choose which launch configuration to use in the debugger view.
19 changes: 19 additions & 0 deletions userdocs/userdocs.docc/Articles/Features/docc-live-preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Documentation Live Preview

@Metadata {
@Available("Swift", introduced: "6.2")
}

Show a live preview of your Swift documentation while editing.


The Swift toolchain provides DocC, which compiles documentation for your Swift package. You can distribute compiled documentation to developers, or host the content. It's what this project used to make its documentation! You can learn more about DocC by reading [the documentation on the Swift organization's website](https://www.swift.org/documentation/docc/).

View a side-by-side live preview of your documentation as you edit it with the Swift extension for VS Code.
Access this feature using the Preview Swift Documentation button at the top right of an editor, or be invoking `Swift: Preview Documentation` in the command palette.
This opens up a new editor pane with your rendered documentation:

![An animation showing how to launch documentation live preview.](docc-live-preview.gif)

> Note: This feature is only available when using a Swift toolchain 6.2 or higher running on macOS or Linux.

13 changes: 13 additions & 0 deletions userdocs/userdocs.docc/Articles/Features/language-features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Language Features

Navigate and write your Swift code more easily with Language features.

The Swift extension provides language features such as code completion and jump to definition via [SourceKit-LSP](https://github.com/apple/sourcekit-lsp).

> ⚠️ Important: With Swift toolchains prior to 6.1 you will need to build your project at least once for SourceKit-LSP to function correcly. Whenever you add a new dependency to your project, make sure to rebuild it so that SourceKit-LSP can update its information.

SourceKit-LSP provides background indexing in Swift toolchain 6.1 which will automatically index your project on startup. All indexing results are cached in the `.build/index-build` folder within your workspace.

Language features are common to all VS Code extensions. See the [VS Code documentation about navigating code](https://code.visualstudio.com/docs/editing/editingevolved) for a more in-depth overview.

SourceKit-LSP can be configured via extension settings. See <doc:settings> for more information.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Project View
# Swift Project View

vscode-swift provides project view
Use this view to navigate your Swift project.

If your workspace contains a package, this extension will add a **Swift Project** view to the Explorer:

![](package-dependencies.png)
![A snapshot of the Package Dependencies view showing dependencies for the async-http-client Swift project.](package-dependencies.png)

Additionally, the extension will monitor `Package.swift` and `Package.resolved` for changes, resolve any changes to the dependencies, and update the view as needed.
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
# Test Coverage
# Running and Debugging Tests

vscode-swift provides mechanisms to see coverage of your tests.
View test results in the test explorer.


All VS Code extensions provide a [testing capabilities and views(https://code.visualstudio.com/docs/debugtest/testing).
View, run, and debug tests that your package containers in the Test Explorer.

![A screenshot of the test explorer pane in Visual Studio Code that shows a selection of 5 tests run and passed.](test-explorer.png)

Once your project is built, the Test Explorer will list all your tests. These tests are grouped by package, then test target, and finally, by XCTestCase class. From the Test Explorer, you can initiate a test run, debug a test run, and if you have already opened a file, you can quickly jump to the source code for a test.

## Run Tests with Coverage

Test coverage is a measurement of how much of your code is tested by your tests. It defines how many lines of code were actually run when you ran your tests and how many were not. When a line of code is not run by your tests it will not have been tested and perhaps you need to extend your tests.

The Swift extension integrates with VS Code's Code Coverage APIs to record what code has been hit or missed by your tests.

![](coverage-run.png)
![A snapshot of the Test Explorer with the mouse hovering over the "Run Tests With Coverage" button.](coverage-run.png)

Once you've performed a code coverage run a coverage report will be displayed in a section of the primary side bar. This report lists all the source files in your project and what percentage of lines were hit by tests. You can click on each file to open that file in the code editor. If you close the report you can always get it back by running the command `Test: Open Coverage`.

![](coverage-report.png)
![A snapshot of the Test Coverage view showing percentage of code covered for each source file.](coverage-report.png)

After generating code coverage lines numbers in covered files will be coloured red or green depending on if they ran during the test run. Hovering over the line numbers shows how many times each line was run. Hitting the "Toggle Inline Coverage" link that appears when hovering over the line numbers will keep this information visible.

![](coverage-render.png)
![A snapshot of a text editor with Swift code highlighted in green to show that it has been executed in the test.](coverage-render.png)
59 changes: 59 additions & 0 deletions userdocs/userdocs.docc/Articles/Reference/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Commands

Useful VS Code commands added by the Swift extension.


The Swift extension adds the following commands, each prefixed with `"Swift: "` in the command palette.

#### Configuration

- **`Create New Project...`** - Create a new Swift project using a template. This opens a dialog to guide you through creating a new project structure.
- **`Create New Swift File...`** - Create a new `.swift` file in the current workspace.
- **`Select Toolchain...`** - Select the locally installed Swift toolchain (including Xcode toolchains on macOS) that you want to use Swift tools from.

The following command is only available on macOS:

- **`Select Target Platform...`** - An experimental command available in Swift 6.1 that offers code completion for iOS, tvOS, watchOS, and visionOS projects.

#### Building and Debugging

- **`Run Build`** - Run `swift build` for the package associated with the open file.
- **`Debug Build`** - Run `swift build` with debugging enabled for the package associated with the open file, launching the binary and attaching the debugger.
- **`Attach to Process...`** - Attach the debugger to an already running process for debugging.
- **`Clean Build Folder`** - Clean the `.build` folder for the package associated with the open file, removing all previously built products.

#### Dependency Management

- **`Resolve Package Dependencies`** - Run `swift package resolve` on packages associated with the open file.
- **`Update Package Dependencies`** - Run `swift package update` on packages associated with the open file.
- **`Reset Package Dependencies`** - Run `swift package reset` on packages associated with the open file.
- **`Add to Workspace`** - Add the current package to the active workspace in VS Code.
- **`Clean Build`** - Run `swift package clean` on packages associated with the open file.
- **`Open Package.swift`** - Open `Package.swift` for the package associated with the open file.
- **`Use Local Version`** - Switch the package dependency to use a local version of the package instead of the remote repository version.
- **`Edit Locally`** - Make the package dependency editable locally, allowing changes to the dependency to be reflected immediately.
- **`Revert To Original Version`** - Revert the package dependency to its original, unedited state after local changes have been made.
- **`View Repository`** - Open the external repository of the selected Swift package in a browser.

#### Testing

- **`Test: Run All Tests`** - Run all the tests across all test targets in the open project.
- **`Test: Rerun Last Run`** - Repeat the last test run.
- **`Test: Open Coverage`** - Open the last generated coverage report, if one exists.
- **`Test: Run All Tests in Parallel`** - Run all tests in parallel. This action only affects XCTests. Swift-testing tests are parallel by default, and their parallelism [is controlled in code](https://developer.apple.com/documentation/testing/parallelization).

#### Snippets and Scripts

- **`Insert Function Comment`** - Insert a standard comment block for documenting a Swift function in the current file.
- **`Run Swift Script`** - Run the currently open file, as a Swift script. The file must not be part of a build target. If the file has not been saved it will save it to a temporary file so it can be run.
- **`Run Swift Snippet`** - If the currently open file is a Swift snippet then run it.
- **`Debug Swift Snippet`** - If the currently open file is a Swift snippet then debug it.

#### Diagnostics

- **`Capture Diagnostic Bundle`** - Capture a diagnostic bundle from VS Code, containing logs and information to aid in troubleshooting Swift-related issues.
- **`Clear Diagnostics Collection`** - Clear all collected diagnostics in the current workspace to start fresh.
- **`Restart LSP Server`** - Restart the Swift Language Server Protocol (LSP) server for the current workspace.
- **`Re-Index Project`** - Force a re-index of the project to refresh code completion and symbol navigation support.

> 💡 Tip: Commands can be accessed from the VS Code command palette which is common to all VS Code extensions. See the [VS Code documentation about the command palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) for a more in-depth overview.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Extension Settings

vscode-swift provides various settings to configure its behaviour.
Configure the behavior of the Swift extension.

The Visual Studio Code Swift extension comes with a number of settings you can use to control how it works. Detailed descriptions of each setting is provided in the extension settings page.
> 💡 Tip: The Settings Editor is common to all VS Code extensions. See the [documentation about personalizing VS Code](https://code.visualstudio.com/docs/getstarted/personalize-vscode) for a more in-depth overview.

The Swift extension comes with a number of settings you can use to control how it works. Detailed descriptions of each setting are provided in the extension settings page.

This document outlines useful configuration options not covered by the settings descriptions in the extension settings page.

Expand Down Expand Up @@ -53,7 +55,7 @@ If you'd like to provide specific arguments to your plugin command invocation yo
}
```

Alternatively you can specfiy which specific command the arguments should apply to using `PluginName:command`. A key of `PluginName` will use the arguments for all commands in the plugin. If you'd like the same arguments to be used for all plugins use `*` as the plugin name.
Alternatively you can specify which specific command the arguments should apply to using `PluginName:command`. A key of `PluginName` will use the arguments for all commands in the plugin. If you'd like the same arguments to be used for all plugins use `*` as the plugin name.

```json
{
Expand All @@ -65,13 +67,15 @@ Alternatively you can specfiy which specific command the arguments should apply

## SourceKit-LSP

[SourceKit-LSP](https://github.com/apple/sourcekit-lsp) is the language server used by the the Swift extension to provide symbol completion, jump to definition etc. It is developed by Apple to provide Swift and C language support for any editor that supports the Language Server Protocol.
[SourceKit-LSP](https://github.com/apple/sourcekit-lsp) is the language server used by the Swift extension to provide symbol completion, jump to definition, etc. It is developed by Apple to provide Swift and C language support for any editor that supports the Language Server Protocol.

### Background Indexing

If you're using a nightly (`main`) or recent `6.0` toolchain you can enable support for background indexing in Sourcekit-LSP. This removes the need to do a build before getting code completion and diagnostics.
Background Indexing was added as an experimental feature in Swift toolchain version 6.0 and then enabled by default in 6.1. This feature removes the need to do a build before getting code completion and diagnostics.

On startup, SourceKit-LSP will read your project information from your `Package.swift` and begin indexing your project automatically. All indexing results are cached in the `.build/index-build` folder within your workspace.

To enable support, set the [`swift.sourcekit-lsp.backgroundIndexing`](vscode://settings/swift.sourcekit-lsp.backgroundIndexing) setting to `true`.
You can enable or disable this feature with the [`swift.sourcekit-lsp.backgroundIndexing`](vscode://settings/swift.sourcekit-lsp.backgroundIndexing) setting.

### Support for 'Expand Macro'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Installation

vscode-code Swift is installed through the extension marketplace.
Install the Swift extension via the VS Code Marketplace.

The Swift extension is supported on macOS, Linux, and Windows.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Supported Toolchains

vscode-swift supports several versions of the Swift toolchain.
Find out which versions of Swift the extension supports.

vscode-swift supports the following Swift toolchains:
The Swift extension supports the following Swift toolchains:
* 5.9
* 5.10
* 6.0
* 6.1
* 6.2

The extension also strives to work with the latest nightly toolchains built from the main branch.

Certain features of vscode-swift will only work with newer versions of the toolchains. We recommend using the latest version of the Swift toolchain to get the most benefit of the extension. The following features only work with certain toolchains as listed:
Certain features of the Swift extension will only work with newer versions of the toolchains. We recommend using the latest version of the Swift toolchain to get the most benefit out of the extension. The following features only work with certain toolchains as listed:

Feature | Minimum Toolchain Required
------------------------ | -------------------------------------
lldb-dap debugging | 6.0
Feature | Minimum Toolchain Required
-------------------------- | -------------------------------------
Debugging with `lldb-dap` | 6.0
<doc:docc-live-preview> | 6.2

## Swiftly Support

Expand All @@ -24,7 +26,7 @@ You can choose a swiftly managed toolchain to use from the `> Swift: Select Tool

If you do `swiftly use` on the command line you must restart VS Code or do `> Developer: Reload Window` in order for the VS Code Swift extension to start using the new toolchain.

### `.swift-version` Support
### .swift-version Support

Swiftly can use a special `.swift-version` file in the root of your package so that you can share your toolchain preference with the rest of your team. The VS Code Swift extension respects this file if it exists and will use the toolchain specified within it to build and test your package.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading