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"]
}
}
}
So assuming you already have https://github.com/neoclide/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:
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:
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:
{
// ...
"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.
Top comments (11)
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.
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: github.com/ethereum/solidity/issue...
Hey! I'm using latest
Plug 'neoclide/coc.nvim', {'branch': 'release'}
. I'll keep an eye on that issue, thanks!Nice guide, i've followed the steps needed to set this up on vim with coc, i've noticed that my language server only reports possible compile errors but auto-suggestions doesn't seem to work, it this intended to be happening, am i missing something?
my coc config looks like this
`
Hey. Many thanks for your interest. Yes, that is intended as it is - for now - just a PoC (proof of concept). I definitely want to continue working on this and we have it in our high priority item list, so it will come. I will by then also keep posting updates. I am really happy about all the positive Feedback have have gotten so far. Many thanks.
p.s. auto complete is a non-trivial task, given the way the compiler currently works. So expect other features before that will come.
Many thanks!
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
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 :)
Hey Christian, I was recently interested in building and LSP Server for Solidity as well. Could you hook me up with some resources to refer?
Join us on matrix (or gitter). There we can talk more in real-time. My nick there should be "christianparpart" as well. Generally, the first place to look at should be the LSP specification. That's at least what I did.
But instead of creating another LSP, maybe we can collaborate.
Also, keep in mind, we strictly only provide the LSP and most editors / IDEs are fine with this, but some are not, such as VScode. So there's also head-room for projects on top of our LSP natively built into solc.
This is exactly what i need. But I can install solc support LSP. Can you help me ?
I am using Neovim
You guys make me want to be more active on dev.to. i cannot as of right now (busy). But as soon as I can i will also update the binaries and extension package. :)