Builtin Solidity Language Server
Tags: solidity, lsp, vscode, vim
Published: 2021-04-06 12:23:57

---
title: Builtin Solidity Language Server
published: true
description: Introduces the new builtin language server mode of the solidity compiler.
tags: solidity, lsp, vscode, vim
cover_image: https://soliditylang.org/images/SolBlueGradient.png
---

Hey fellows!

At Ethereum I am currently part time developing a language server mode as part of the solidity compiler.
While this is still in early development stage, the 3 features I am currently concentrating on are already working:

✅ compiler diagnostics
✅ goto definition (also works across files)
✅ find all references (does not _yet_ work across files)
✅ semantic highlighting

While this is not much, it is a good starting point to not reinvent the wheel but reuse the existing compiler infrastructure to implement a language server on top of it.

For those of you being curious, I would now like to show you how to use it.

## Vim/NeoVim with coc.nvim

This is actually what I am using and your `coc-settings.json` would be extended like this:

```json
{
    // ...
    "languageserver": {
        // ...
        "solidity": {
            "command": "/path/to/solc",
            "args": [ "--lsp" ],
            "trace.server": "verbose",
            "rootPatterns": [".git/"],
            "filetypes": ["solidity"]
        }
    }
}
```

So assuming you already have [https://github.com/neoclide/coc.nvim](coc.nvim) installed and working that is all you need to add to it. Now of course you need to have a `solc` binary available that does indeed support the new command line parameter `--lsp`.

### Download a `solc` with LSP support

I've uploaded a prototype version here:

https://github.com/christianparpart/solidity-language-client-vscode/releases/download/TP_1/solc-linux64

## Visual Studio Code!

When you are on a 64bit Linux, you are lucky. The VScode extension does provide a builtin LSP server that you can use. Other platforms (such as OS/X or Windows) I will provide some precompiled LSP-compatible `solc` executables and even some syntax highlighting, but give me some time on that.

So for VScode, I have just written the glue code extension last week and you can download here:

https://github.com/christianparpart/solidity-language-client-vscode/releases/tag/TP_1

Fetch the `.vsix` file and then run the following command in your virtual terminal emulator:

```sh
code --install-extension solidity-0.0.1.vsix
```

Start (or restart) your VScode and you should be all set. If you now want to use your own `solc` binary (which should more frequently update), then you can configure that in your local `settings.json` as follows:

```json
{
    // ...
    "Solidity.solc.path": "/path/to/solc", // or null if builtin should be used
    "Solidity.trace.server": "messages"
}
```

Bare in mind, if you already had another solidity related extension loaded in VScode you may want to see if you should disable that to not cause any conflicts or confusions. :)

## Other Editors

The `solc`'s `--lsp` mode does use standard Input/Output streams (`stdio`) for communicating with the client. This is fairly standard. In QtCreator for example you can just go to the IDE's config page and put in the path to the `solc` executable, and configure on what file extensions to use that LSP for and you're done with it. I want to try out Neovim's native language client interface at some point, but I am certain it'll just work like any other in this sense. :-)

## Future Outlook

🔨 improving goto definition / find all references / semantic highlighting
🔨 show type signature on hover
🔨 show natspec documentation on hover
🔨 show IR / EVM byte code / gas costs on hover
🔨 code completion at least on `.`
🔨 publish the VScode extension to the VScode marketplace
🔨 configurable list of warning/error codes to suppress?
🔨 and maybe we can integrate that in Remix, too?

## Final Words

I really hope you enjoy doing some early testing on this Solidity language server. Please keep in mind that the features are indeed minimal but slowly I would like to improve on that. Tell me what you feel about it, what you would like to have the most and/or what should be different.

If you are interested in how to build Solidity compiler (including the language server) from source, please drop me a comment and I can do that in a separate post then.

Have fun and take care!
Christian.