DEV Community

Cover image for Builtin Solidity Language Server

Builtin Solidity Language Server

christianparpart profile image Christian Parpart ・3 min read

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:

    // ...
    "languageserver": {
        // ...
        "solidity": {
            "command": "/path/to/solc",
            "args": [ "--lsp" ],
            "trace.server": "verbose",
            "rootPatterns": [".git/"],
            "filetypes": ["solidity"]
Enter fullscreen mode Exit fullscreen mode

So assuming you already have 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:

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:

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

code --install-extension solidity-0.0.1.vsix
Enter fullscreen mode Exit fullscreen mode

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:

    // ...
    "Solidity.solc.path": "/path/to/solc", // or null if builtin should be used
    "Solidity.trace.server": "messages"
Enter fullscreen mode Exit fullscreen mode

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!

Discussion (5)

Editor guide
miloops profile image
Emilio Tagua

This is great. Can you jump to definition using coc on nvim? I get:

[coc.nvim]: Error on notification "jumpImplementation": implementation provider not found for current buffer, your language server doesn't support it.

christianparpart profile image
Christian Parpart Author

Hey. Can you please tell me what coc-nvim version you are using? I am actually mainly using coc-nvim and it works, but it may be that your coc-nvim implementation requires an explicit feature registration that I am not doing yet. Will do so then. And please keep on track at our Github issue at:

miloops profile image
Emilio Tagua

Hey! I'm using latest Plug 'neoclide/coc.nvim', {'branch': 'release'} . I'll keep an eye on that issue, thanks!

0xpaella profile image
Carlos González Juárez

Great work! I wanted to know how to get the solidity compiler to accept the "--lsp" argument. I'm in Mac so I can't use the file you just shared and I haven't been able to find any documentation to do it on my own.
Any tips are welcomed :D

christianparpart profile image
Christian Parpart Author

Hey Carlos, I have not provided a builtin binary for Mac just yet (I was actually just answering the very same question in our official github ticket lol). I will provide one in a next VScode extension release as the interest seems to exist.

What you can do right now however would be to build solidity from source yourself (using the lsp branch) and configure the VScode solidity extension to use the solc binary you manually compiled.

-- On the other hand, if you are not used to that manual work, I'd favor to spare you from that and would kindly ask you to just wait a bit longer. Check the above posted URL to the github issue, track it. and I'll release a new version soon. :)

p.s.: can't state often enough. It's still beta (i.e. not feature complete), so please bare with me :)