Visual Studio Code Extension

Solang has language server built into the executable, which can be used by the Visual Studio Code extension. This extension provides the following:

  1. Syntax highlighting
  2. Compiler warnings and errors are displayed in the problems tab and marked with squiqqly lines, this is also known as diagnostics.
  3. Hovering over variables, types, functions etc and more will give information, For example this will give the struct fields when hovering over a variable which is a reference to a struct.
_images/extension-screenshot.png

Both the Visual Studio Code extension code and the language server were developed under a Hyperledger Mentorship programme.

Using the extension

The extension can be found on the Visual Studio Marketplace.

On first start, the extension will ask to download the Solang binary. Once this is done, it should just automatically work. However, you should set the blockchain target in the extension settings. The Solidity language differs in subtle ways depending on which target you are building for. Different blockchains offer different builtins, for example. See the language documentation.

_images/extension-config.png

Development

The code is spread over two parts. The first part the vscode extension client code, written in TypeScript. This part deals with syntax highlighting, and calling out to the Solang language server when needed. The client needs npm and node installed. The client implementation is present in src/client. The extension client code is in src/client/extension.ts.

Secondly, there is the language server which is written in Rust. The Solang binary has an option --language-server, which start the built-in language server.

Once you have node and npm installed, you can build the extension like so:

git clone https://github.com/hyperledger-labs/solang
cd solang/vscode
npm install
npm install -g vsce
vsce package

You should now have an extension file called solang-0.2.0.vsix which can be installed using code –install-extension solang-0.2.0.vsix.

Alternatively, the extension be run from vscode itself.

  1. Inside a vscode instance, Ctrl+Shift+B to build the project
  2. On the task bar at the bottom of the IDE select Launch Client
  3. Open a Solidity file (.sol) to test the extension.

To run the tests:

  1. Inside a vscode instance, Ctrl+Shift+B to build the project
  2. On the task bar at the bottom of the IDE select Extensions tests
  3. The result should be displayed in the debug console of the host IDE instance.