neovim setup for solidity
It has been over 2.5 months now since the solidity-analyzer introduction post and the development has been slow after the burst of development after start. Next things to do for me on solidity-analyzer
is to add code navigation and I have been thinking of using tree-sitter for it.
I recently started using nvim again since I wanted to test the LSP with something other than VSCode too. I figured out how to hook solidity-analyzer into nvim past week and have added the same to the project readme as well and is likely to be more up-to-date than this post.
Here’s how:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
local configs = require 'lspconfig.configs'
local lspconfig = require 'lspconfig'
-- Check if the config is already defined (useful when reloading this file)
if not configs.solidity_analyer_lsp then
configs.solidity_analyzer_lsp = {
default_config = {
cmd = {vim.fn.expand('$HOME/.cargo/bin/solidity-analyzer-ls')},
filetypes = {'solidity'},
root_dir = lspconfig.util.root_pattern('foundry.toml') or function(fname)
return lspconfig.util.find_git_ancestor(fname)
end,
settings = {},
},
}
end
lspconfig.solidity_analyzer_lsp.setup{}
This is what I have along with the kickstart.nvim starter config which adds a bunch of lsp utilities and most importantly the on_attach
handler for LSP.
Another thing I have is nvim-treesitter-context configured for solidity. The config for which is quite simple and is more documented in their readme.
Here’s my excerpt:
1
2
3
require "treesitter-context".setup {
mode = "topline",
}