قالب وردپرس درنا توس
Home / IOS Development / Swift Development with Visual Studio Code

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.


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.

Electronics App
have a reputation for being big and slow,
but do not let it stop you from giving VSCode a try –
It's performance and memory footprint is comparable to a native app.

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.

  $  git clone https://github.com/apple/sourcekit-lsp.git
 $    cd  sourcekit-lsp
 $  fast building

If successful,
The finished binary will be available from
of the hidden .build / debug directory.
Move the binary to a default directory in $ PATH ,
like / usr / local / bin or / usr / bin .

  $    etc.  .build / debug / sourcekit-lsp / usr / local / bin

You can confirm that everything works as expected
by running the command sourcekit-lsp :

This command launches a new language process process,
but do not worry if it does not give any feedback to STDOUT
That means it works as desired.
Exit the process of an ETX signal ( ^ C ).

Step 5: Build and Install SourceKit-LSP Extension for Visual Studio Code

Now that you have the Swift language server available,
The last step is to build and install the extension
which allows the Visual Studio code to communicate with it.

From the directory sourcekit-lsp in the previous step,
navigate to directory Editing / vscode
use npm to build the extension
and then use the command code to install it:

  $    cd  Editors / vscode /
 $  npm run createDevPackage
 $  code  - installation extension  out / sourcekit-lsp-vscode-dev.vsix

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.


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.


Source link