Project-Level LSP Configuration in Neovim
Introduction
Recently, while writing Golang code, I needed to isolate certain constants in the code during the build process by using Golang's built-in build tags feature. To achieve this, specific startup parameters for gopls must be configured for correct code indexing. However, gopls configuration needs to be done at the project level, as global configuration might interfere with other projects.
So, how can we configure it?
Configuration Methods
Using Neovim's Built-in exrc Feature
The exrc
feature allows Neovim to read a .exrc
file in the current directory
to load local configurations (essentially achieving configuration by executing code).
However, this method requires a deep understanding of Neovim
and might conflict with other plugins. Therefore, it's not highly recommended.
Using lazy.nvim
lazy.nvim is a powerful Neovim plugin manager
that simplifies plugin management and configuration.
It supports configuring plugins for specific projects through a .lazy.lua
file.
Although lazy.nvim's official documentation barely (actually not at all) mentions this feature,
experienced lazy.nvim users can usually adopt it with ease.
Reference for configuration format: https://lazy.folke.io/spec
return {
"nvim/nvim-lspconfig",
opts = {
servers = {
gopls = {
settings = {
gopls = {
buildFlags = { "-tags=encrypt decrypt" },
},
},
},
},
},
}
This work by 林玮 (Jade Lin) is licensed under
CC BY-NC-ND 4.0