A plugin to configure Neovim LSP using json files like coc-settings.json
.
Using nlsp-settings.nvim
and lspconfig and jsonls and nvim-compe and vim-vsnip
Using nlsp-settings.nvim
, you can write some of the settings
to be passed to lspconfig.xxx.setup()
in a json file.
You can also use it with jsonls to complete the configuration values.
- Neovim
- neovim/nvim-lspconfig
Plug 'neovim/nvim-lspconfig'
Plug 'tamago324/nlsp-settings.nvim'
jsonls allows for configuration value completion.
require"lspconfig".jsonls.setup {
cmd = { '/path/to/json-languageserver', '--stdio' },
-- Set the schema so that it can be completed in settings json file.
-- The schemas defined in `jsonls.json` will be merged with the list configured here.
settings = {
json = {
schemas = require'nlspsettings.jsonls'.get_default_schemas()
}
}
}
For a list of language servers that have JSON Schema, see here.
Example) Settings the sumneko_lua settings:
:NlspConfig sumneko_lua
Create a settings file in ~/.config/nvim/nlsp-settings/sumneko_lua.json
.
{
"Lua.runtime.version": "LuaJIT",
"Lua.diagnostics.enable": true,
"Lua.diagnostics.globals": [
"vim", "describe", "it", "before_each", "after_each"
],
"Lua.diagnostics.disable": [
"unused-local", "unused-vararg", "lowercase-global", "undefined-field"
],
"Lua.completion.callSnippet": "Both",
"Lua.completion.keywordSnippet": "Both"
}
NOTE: The path where settings json file is stored can be changed by the config_home
argument of nlspsettings.setup()
.
require'nlspsettings'.setup {
config_home = vim.fn.stdpath('config') .. '/lspsettings'
}
By calling nlspsettings.setup()
, you can use on_new_config
to automatically load JSON files on all language servers.
-- You need to call lspconfig.*.setup().
require'nlspsettings'.setup()
It is still possible to write settings
in lua.
However, if you have the same key, the value in the JSON file will take precedence.
Example) Write sumneko_lua settings in Lua
lspconfig.sumneko_lua.setup{
cmd = { '/path/to/bin/Linux/lua-language-server', '-E', '/path/to/main.lua', },
-- You can also specify a value in settings, but if it is the same key,
-- it will be overwritten by the value in the JSON file.
settings = {
Lua = {
workspace = {
library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.stdpath("config") .. '/lua'] = true,
}
}
}
}
}
- If your language server lacks support, please feel free to make a pull request or issue.
- All contributions are welcome.
MIT