This plugin allowes you to customize LSP settings in neovim for each your project and globally in JSON format similar to VSCode.
- Global LSP configuration
- Customize configuration for LSPs for each your project similar to VSCode and
COC/coc-settings.json - Autocompletion with description for most popular LSPs settings.
- Compatibility with
VSCodesettings format. - Easy & flexible configuration
- Neovim v0.11.2 or higher
- nvim-lspconfig
jsonls(optional, for settings autocompletion)
{
"amv-dev/nvim-lspsettings",
dependencies = {
"neovim/nvim-lspconfig",
},
opts = {},
event = "BufRead",
}{
-- Paths where JSON cofiguration will be searched
-- Order matters. All the settings will be merged from top to bottom.
paths = {
vim.fn.stdpath('config') .. "/lspsettings"),
-- compatibility with `nlsp-settings` plugin
vim.fn.stdpath('config') .. "/nlsp-settings"),
-- compatibility with `vscode`
".vscode",
-- compatibility with `nlsp-settings` plugin
".nlsp-settings",
".vim",
},
-- This function will fire on LSP start or on settings file change
on_settings = function(server_name, settings)
local cfg = vim.lsp.config[server_name] or {}
if vim.deep_equal(cfg.settings, settings) then
-- Nothing changed, just quit
return
end
vim.lsp.config(server_name, { settings = settings })
local servers = vim.lsp.get_clients({ name = server_name })
if #servers == 0 then return end
-- restart server if it's already running
vim.cmd.LspRestart(server_name)
end,
}Here is an example with custom on_settings callback, which calls default on_settings first and then shows notification.
{
on_settings = function(server_name, settings)
local Config = require('lspsettings.config')
Config.on_settings(server_name, settings) -- default callback
vim.notify("Settings changed")
end,
}Of course, you can totally rewrite on_settings on your own without calling default implementation.
.vim/rust_analyzer.json
{
"rust-analyzer.checkOnSave": true,
"rust-analyzer.check.features": ["my-feature"]
}Takes 0, 1 or 2 arguments
If no arguments provided, then opens local settings file for LSP for the current buffer
Each argument may be server name, path from config or path index from config. Example:
LspSettings rust_analyzer # opens local settings for `rust_analyzer`
LspSettings 0 rust_analyzer # opens global settings for `rust_analyzer`
LspSettings 0 # opens global settings for current buffer server
LspSettings global # same
LspSettings # opens local settings for current buffer server
This plugin is heavily inspired by tamago324/nlsp-settings.nvim work. Unfortunately, it seems like it is no longer maintained.
I experienced several problems I want to fix:
- Plugin does not work out of the box with neovim v0.11 .
- Schemas for LSP settings options are not properly generated.
- IMHO plugin is overcomplicated and hard to maintain for others due to lot of comments on japanese.
- Neovim docs
- Neovim commands