Swift Development with Visual Studio Code

Tram Ho

Visual Studio Code (VSCode) is a cross-platform open source and text editor from Microsoft. It’s one of the coolest open source projects out there today, with regular updates from hundreds of contributors. VSCode is one of the first tools to support Language Server Protocol (LSP), having played a key role in providing a great developer experience in multiple languages ​​and technologies.

This week, I’ll show you how to get started with Swift’s new Language Server Protocol support in Visual Studio Code on macOS. If you haven’t tried writing Swift outside of Xcode, or are already a VSCode user and are completely new to the language, then this article will tell you everything you need to know.

Step 0: Install Xcode

If you don’t have Xcode installed on your machine, open the Terminal app and run the following command:

Running this command will bring up a system prompt.

Click the “Get Xcode” button and continue to install on the App Store.

You can verify that everything is working as expected by running the command sourcekit-lsp:

This command starts a new language server process, but don’t worry if it doesn’t give any response to STDOUT – it means it’s working as expected. Exit the process using ETX signals (Control (^) C).

Step 1: Install Visual Studio Code

Download Visual Studio Code and install it to your system’s Applications folder. Open the app and follow the instructions to launch it from the command line. You need a code command accessible from $ PATH to install the SourceKit-LSP extension later.

https://code.visualstudio.com/ https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line

Step 2: Install Node and NPM

The VSCode extension is written in JavaScript / TypeScript. If you’re not set up for JS development yet, you can download Node (JavaScript run-time for outside the browser) and npm (package manager for Node) with Homebrew using the following commands or manually how to follow these instructions:

To verify that you have the installation working, run the following command:

Step 3: Build and install the SourceKit-LSP extension for Visual Studio Code

From the command line, copy the repository “sourcekit-lsp”: https://github.com/apple/sourcekit-lsp and navigate to Editors / vscode in the output directory. Use npm to create the extension and then use code to install it:

Now reopen VSCode and open a Swift project, such as “this project”: https://github.com/flight-school/money and test Language Server Protocol support for Swift.

So there you have it – creating the best Swift development experience outside of Xcode.

Share the news now

Source : Viblo