How to get neovim-lsp work with solc (Solidity)

Hi there,

somehow I do not get nvim v0.6.1 running with lsp support for solidity files. It works for rust, it works for python, it works for typescript, but not for .sol files.

Is there any trick? When doing :LspInfo it shows that no language server is attached to the buffer, although I have a .sol file opened. I have solc in version 0.8.13 installed.

nvim-lspconfig now supports solc out of the box.

Edit: the below is not necessary anymore, they merged my PR adding this to the default configuration.

Note for monorepo users with their contracts in a hardhat package: The default solc lsp server config will pick the git repo’s root dir as the lsp root, which can lead to import errors if importing contracts from node packages like @openzeppelin/contracts. I got nvim to properly detect the root of the contracts package (instead of the monorepo root) for the solc lsp with the following configuration:

local lspconfig = require('lspconfig')

-- some lsp config with on_attach to setup keybindings

lspconfig['solc'].setup {
    on_attach = on_attach,
    root_dir = lspconfig.util.root_pattern('hardhat.config.*', '.git'),
}

This gives a hardhat.config.ts (or .js) file precedence for root dir detection over the git repo root.