Troubleshoot - Neovim LSP Not Working for Language
Pre-requisites:
- Using neovim 0.5.0+
- Using native LSP servers
- Have installed language LSP server (e.g. Ruby, solargraph | Go, gopls)
- Have added LSP to neovim
init.vim
to load
Debug
- Check the LSP’s
default_config
, for theroot_dir
. This is how the LSP detects whether to launch or now.
For example the gopls.lua configuration:
# gopls.lua
# -- snipped --
default_config = {
root_dir = [[root_pattern("go.mod", ".git")]],
},
The above configuration depends on the presence of a go.mod
or .git
file in the current working directory order to detect and activate the LSP. If you are not seeing autocomplete suggestions, check that these files are available in your buffer’s current working directory (:pwd
).
Figure 1: A dropdown menu showing autocomplete suggestions for go using gopls.
Here is another example for the solargraph.lua configuration
# solargraph.lua
# --snipped--
default_config = {
root_dir = [[root_pattern("Gemfile", ".git")]],
},
Similar to gopls
, the solargraph
configuration looks for a Gemfile
or .git
file in the current working directory. If it detects one, it will activate the LSP.