• Stars
    star
    622
  • Rank 72,195 (Top 2 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created almost 3 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Visual Studio Code Extension for Swift

Swift for Visual Studio Code

This extension adds language support for Swift to Visual Studio Code. It supports:

  • Code completion
  • Jump to definition, peek definition, find all references, symbol search
  • Error annotations and apply suggestions from errors
  • Automatic generation of launch configurations for debugging with CodeLLDB
  • Automatic task creation
  • Package dependency view
  • Test Explorer view

Swift support uses SourceKit LSP for the language server to power code completion and LLDB to enable debugging.

The extension is developed by members of the Swift Community and maintained by the SSWG. The aim is to provide a first-class, feature complete extension to make developing Swift applications on all platforms a seamless experience.

If you experience any issues or want to propose new features please create an issue or post on the #vscode-swift channel on Slack.

Contributing

The Swift for Visual Studio Code extension is a community driven project, developed by the amazing Swift community. Any kind of contribution is appreciated, including code, tests and documentation. For more details see CONTRIBUTING.md.

Installation

For the extension to work, you must have Swift installed on your system. Please see the Getting Started Guide on Swift.org for details on how to install Swift on your system. Install the extension from VSCode Marketplace and open a Swift package! You'll be prompted to install and configure the CodeLLDB extension, which you should do so.

Features

Language features

The extension provides language features such as code completion and jump to definition via the Apple project SourceKit-LSP. For these to work fully it is required that the project has been built at least once. Every time you add a new dependency to your project you should build it so SourceKit-LSP can extract the symbol data for that dependency.

Automatic task creation

For workspaces that contain a Package.swift file, this extension will create the following tasks:

  • Build All: Build all targets in the Package
  • Build Debug : Each executable in a Package.swift get a task for building a debug build
  • Build Release : Each executable in a Package.swift get a task for building a release build

These tasks are available via Terminal โ–ธ Run Task... and Terminal โ–ธ Run Build Task....

Commands

The extension adds commands, available via the command palette.

  • Resolve Package Dependencies: Run swift package resolve on package associated with open file.
  • Update Package Dependencies: Run swift package update on package associated with open file.
  • Reset Package Dependencies: Run swift package reset on package associated with open file.
  • Open Package.swift: Open Package.swift for package associated with open file.
  • Clean Build: Run swift package clean on package associated with open file.
  • Run Swift Script: Run the currently open file, as a Swift script. 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.
  • Run Command Plugin: Display menu of command plugins for currently loaded packages.

The following command is only available on macOS

  • Select Xcode Developer Dir: Select the version of Xcode you want to use swift tools from.
  • Select Target Platform: This is an experimental command used to get code completion for iOS, tvOS projects

Package dependencies

If your workspace contains a package that has dependencies, this extension will add a Package Dependencies view to the Explorer:

Additionally, the extension will monitor Package.swift and Package.resolved for changes, resolve any changes to the dependencies, and update the view as needed.

Debugging

The Swift extension uses the CodeLLDB extension for debugging.

When you open a Swift package (a directory containing a Package.swift) the extension creates build tasks and launch configurations for each executable. If the package contains tests, the extension creates a configuration to run the tests. These all use the CodeLLDB extension as a debugger.

Press F5 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.

CodeLLDB has a version of lldb packaged with it and by default this is the version it uses for debugging. However, this version of lldb does not work with Swift. Fortunately, CodeLLDB allows you to choose an alternate version. The Swift extension will attempt to ascertain which version is required and give you the option to update the CodeLLDB configuration.

Test Explorer

If your package contains tests then they can be viewed, run and debugged in the Test Explorer.

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

Documentation

More Repositories

1

swift-aws-lambda-runtime

Swift implementation of AWS Lambda Runtime
Swift
1,132
star
2

async-http-client

HTTP client library built on SwiftNIO
Swift
917
star
3

http

โš ๏ธ Historical HTTP API - please use https://github.com/swift-server/async-http-client instead
Swift
703
star
4

swift-service-lifecycle

Cleanly startup and shutdown server application, freeing resources in order before exiting.
Swift
395
star
5

work-group

โš ๏ธ Historical workgroup organisation
352
star
6

swiftly

A Swift toolchain installer and manager, written in Swift.
Swift
337
star
7

swift-backtrace

๐Ÿ’ฅ Backtraces for Swift on Linux and Windows
C
295
star
8

guides

Guides for building, debugging and deploying Swift Server applications
258
star
9

sswg

Swift Server Working Group (SSWG)
181
star
10

swift-prometheus

Prometheus client library for Swift
Swift
144
star
11

RediStack

Non-blocking, event-driven Swift client for Redis.
Swift
142
star
12

swift-webauthn

A Swift library for implementing the WebAuthn spec
Swift
127
star
13

swift-openapi-vapor

Vapor Bindings for the OpenAPI Generator
Swift
79
star
14

swift-kafka-client

Swift
77
star
15

swift-devcontainer-template

Visual Studio Code Development Container for Swift
Shell
54
star
16

swift-openapi-async-http-client

AsyncHTTPClient transport for Swift OpenAPI Generator.
Swift
54
star
17

security

โš ๏ธ Historical TLS API - please use SwiftNIO instead
Swift
49
star
18

swift-aws-lambda-events

Swift implementation of AWS Lambda Events
Swift
48
star
19

swift-openapi-hummingbird

Hummingbird transport for OpenAPI generator
Shell
27
star
20

swift-memcache-gsoc

Swift
15
star
21

sswg-collection

Dockerfile
11
star
22

swift-openapi-lambda

An AWS Lambda transport for Swift OpenAPI
Swift
8
star
23

swift-service-cache

caches for swift services
6
star
24

swift-etcd-client-gsoc

Swift
5
star