Skip to content

Latest commit

 

History

History
80 lines (44 loc) · 5.93 KB

settings.md

File metadata and controls

80 lines (44 loc) · 5.93 KB

Extension Settings

The Visual Studio Code Swift extension comes with a number of settings you can use to control how it works. This document details what each of these settings does.

  • Path

This is the folder that the swift executable can be found in. If this is not set then the extension will look for executables in the $PATH. The extension will also use this setting when looking for other executables it requires like sourcekit-lsp and lldb.

  • Build Arguments

This is a list of additional arguments passed to the swift build calls the extension makes. Argument keys and values should be provided as separate entries in the array e.g. ['-Xswiftc', '-warn-concurrency']. This setting is only applied to the default build tasks generated by the extension. If you have created custom versions of these tasks in tasks.json the setting will not be applied. Instead you will need to edit the arguments list in the tasks.json file.

  • Auto Generate Launch Configurations

When a SwiftPM project is loaded into Visual Studio Code the Swift extension will automatically generate debug and release launch configurations for CodeLLDB for any executable in the package. This setting allows you to disable this if you would prefer to setup your own launch configurations.

  • Problem Match Compile Errors

When this is enabled any errors or warnings from a swift build will be listed in the problems view. There is a chance these compile "problems" will double up with "problems" coming from SourceKit-LSP but the list of issues will be more comprehensive. The compile "problems" will only disappear after a swift build indicates they are resolved.

  • Exclude Paths From Package Dependencies

This is a list of paths to exclude from the Package Dependency View.

  • Background Compilation

This is an experimental setting which runs swift build whenever a file is saved. There are possibilites the background compilation will clash with any compilation you trigger yourselves so this is disabled by default.

  • Build path

The path to a directory that will be used for build artifacts. This path will be added to all swift package manager commands that are executed by vscode-swift extension via --build-path option. When no value provided - nothing gets passed to swift package manager and it will use its default value of .build folder in workspace. You can use absolute path for directory or the relative path, which will use the workspace path as a base. Unfortunately, VSCode does not correctly understand and pass the tilde symbol (~) which represents user home folder under *nix systems. Thus, it should be avoided.

Sourcekit-LSP

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.

  • Server Path

The path of the sourcekit-lsp executable. As mentioned above the default is to look in the folder where the swift executable is found.

  • Server Arguments

This is a list of arguments that will be passed to the SourceKit-LSP. Argument keys and values should be provided as separate entries in the array e.g. ['--log-level', 'debug'].

  • Inlay Hints

This controls the display of Inlay Hints. Inlay Hints are variable annotations indicating their inferred type. They are only available if you are using Swift 5.6 or later.

  • Trace: Server

Trace the communication between Visual Studio Code and the SourceKit-LSP server. The output from this is sent to an Output Window called "Sourcekit Language Server"

Advanced

  • Swift Environment Variables

This is a list of environment variables to set when running swift (build, resolve etc).

  • Runtime Path

Where to find Swift runtime libraries. This is mainly of use when these libraries cannot be discovered via the RPATH. On Windows the runtime path is added to the Path environment variable. This is of less use on macOS and Linux but will be added to DYLD_LIBRARY_PATH and LD_LIBRARY_PATH environment variables respectively on each platform.

  • Destination

The build destination for SwiftPM projects. If the value is a string, the plugin will load the destination.json file at the given path. If the value is an object, the plugin will map the value as follows and generate the destination.json automatically.

Configuration key Description destination.json key Default value
target The target triple of build destination. target null
sdk The path of the SDK to build against. sdk null
binDir The path of the folder containing tool binaries. toolchain-bin-dir The usr/bin subdirectory of the Swift toolchain.
extraSwiftCFlags Additional arguments to pass to the Swift compiler. extra-swiftc-flags []
extraCCFlags Additional arguments to pass to the C compiler. extra-cc-flags []
extraCPPFlags Additional arguments to pass to the C++ compiler. extra-cpp-flags []

Hot reload is available for either way of specifying build destination.

  • Diagnostics

The Swift extension includes a Swift Output channel that events are logged in. You can access this by selecting menu item View -> Output and then selecting Swift in the drop down menu. Events like adding new folders, LSP server starting, errors and package resolves/updates are recorded in here. This is all useful information when trying to debug an issue with the extension. Enabling the diagnostics setting will extend this information to include considerably more information. If you want to report a bug with the extension it would be good practice to enable this setting, restart Visual Studio Code and once you have replicated your bug include the contents of the Swift Output channel in the bug report.