Logo

dev-resources.site

for different kinds of informations.

Builtin Solidity Language Server

Published at
4/6/2021
Categories
solidity
lsp
vscode
vim
Author
christianparpart
Categories
4 categories in total
solidity
open
lsp
open
vscode
open
vim
open
Author
16 person written this
christianparpart
open
Builtin Solidity Language Server

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 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:

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:

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!
Christian.

lsp Article's
30 articles in total
Favicon
How to Setup Vim for Kotlin Development
Favicon
Managing LSPs in Neovim: Enable/Disable for the Entire Session
Favicon
Integrating the ruff language server
Favicon
Series Belajar Solid Principle - Liskov Substitution Principle (LSP)
Favicon
Avoid conflicts between denols and tsserver in Neovim
Favicon
Avoid conflicts between denols and tsserver in Neovim
Favicon
Implementing Payment Gateways with the Liskov Substitution Principle
Favicon
SOLID Principles: Liskov Substitution Principle (LSP)
Favicon
Configure Helix to use ElixirLS
Favicon
The Power of Liskov Substitution Principle in Improving Software Design
Favicon
Neovim config from scratch (Part II)
Favicon
Neovim config from scratch (Part I)
Favicon
Integrating a Language Server (LSP) in a VS Code Extension
Favicon
My Neovim setup for React, TypeScript, Tailwind CSS, etc
Favicon
How i setup neovim for speed up React, Js, Ts, etc
Favicon
Solve nvim lsp denols vs tsserver clash
Favicon
Perl Navigator - Language Server for Perl
Favicon
Neovim LSP Setup + Code Completion Engine
Favicon
NeoVim: init.lua, built in LSP e mais
Favicon
How to fix [deno-ts 2339] in the code for Deno Deploy
Favicon
SOLID e o princΓ­pio do 6 por meia dΓΊzia
Favicon
Java LSP in Sublime Text
Favicon
Neovim: Migrando do coc.vim para nvim-lsp
Favicon
Integrating Scala Metals with Doom Emacs using LSP on Pop!_OS/Ubuntu 20.04 LTS
Favicon
Builtin Solidity Language Server
Favicon
Liskov Substitution Principle
Favicon
Emacs as SQL client with LSP
Favicon
Vim Configuration from Minimal to Complete
Favicon
LSP and ISP: The LI of SOLID
Favicon
Go LSP in Sublime Text

Featured ones: