Swift Development with Visual Studio Code

Visual Studio Code (VSCode)
is a cross-platform text and source code editor from Microsoft.
It is one of the most exciting open source projects today,
with regular updates from hundreds of contributors.
VSCode was among the first tools to support
Language Server Protocol (LSP),
which has played a major role in providing a good developer experience,
in a variety of languages ​​and technologies.

With the previously announced
support for lsp for swift
now available in early development,
It's a great time to see how this integration works for yourself.

So this week,
We go through the process of getting started
Swift's new Language Server Protocol support in Visual Studio Code on macOS.
If you have not tried to type Swift outside Xcode,
or is already a VSCode user and brand new in the language,
This article will tell you all you need to know.

Quick support for Language Server Protocol is still in early development
and currently does not offer pre-built packages for
language server ( sourcekit-lsp )
or extension of the Visual Studio code.
For now,
download, build and install these components and their addictions
is a manual process that requires a little knowledge of the command line
(it should take about 1

5 minutes with a reasonably fast internet connection).

When LSP support is made generally available,
It will be much easier to get everything set up.

Step 0: Install Xcode

If you do not already have Xcode installed on your machine,
open the Terminal app and run the following command:

Running this command presents a system prompt.

Click the "Get Xcode" button.
and continue installation on the App Store.

Step 1: Install Visual Studio Code

Download Visual Studio Code
and install it for your system programs folder.
Open the app and
Follow the instructions for launch from the command line.
You must have the command code available from $ PATH
to install the SourceKit LSP extension later.

Go to Swift.org
and download the latest trunk development snapshot
(at the time of writing this was from November 16, 2018).
When it's done downloading,
Run the package to install the Xcode tool.
To enable it,
open xcode,
select the menu item "Xcode> Preferences …" ( ⌘ ),
navigate to components
and select Swift Development Snapshot.

Step 3: Install knutep. and NPM

VSCode extensions are written in JavaScript / TypeScript.
If you are not already set up for JS development,
You can download Node (a JavaScript runtime for the outside browser) and npm (a Node Packet Processing)
with Homebrew using the following commands
or manually, following these instructions:

To verify that you have a workflow,
Run the following command:

Step 4: Build and Install SourceKit-LSP

With all the addictions taken care of,
We are now ready for the main attraction.
From the command line,
klone kildekit-lsp repository,
navigate to the resulting directory,
and build the Swift project.

Start now (or restart) VSCode and open a Swift project,
like this one,
and enjoy an early preview of functionality from
Language Server Protocol support for Swift.

To gain full experience working with Swift from VSCode,
We recommend that you check out too
Swift Language Extension
(for syntax highlighting up to LSP supports this functionality)
and Swift Ribbon Extension
(for real-time style and convention diagnostics).

So there you have –
Establishing a first-class Swift development experience outside Xcode.
Currently Swift support for Language Server Protocol
is limited to codeclocking, quick help, diagnostics,
jump to symbol definitions, and find references.
But we could not be more excited about the future of this project
and what it means for the prospect of the cool language
beyond the Apple ecosystem.