[NeoVim] Better LSP management

This commit is contained in:
2022-08-22 16:01:07 +02:00
parent 32e6c9f4d5
commit ae90912567
4 changed files with 36 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
local M = {} local M = {}
M.file = { local files = {
dictionary = vim.fn.stdpath('config') .. '/spell/en.utf-8.add', dictionary = vim.fn.stdpath('config') .. '/spell/en.utf-8.add',
disabledRules = vim.fn.stdpath('config') .. '/spell/disable.txt', disabledRules = vim.fn.stdpath('config') .. '/spell/disable.txt',
hiddenFalsePositives = vim.fn.stdpath('config') .. '/spell/false.txt', hiddenFalsePositives = vim.fn.stdpath('config') .. '/spell/false.txt',
@@ -14,7 +14,7 @@ local file_exists = function(file)
return f ~= nil return f ~= nil
end end
M.lines_from = function(file) local lines_from = function(file)
if not file_exists(file) then if not file_exists(file) then
return {} return {}
end end
@@ -40,7 +40,7 @@ local update_config = function(lang, configtype)
if client then if client then
if client.config.settings.ltex[configtype] then if client.config.settings.ltex[configtype] then
client.config.settings.ltex[configtype] = { client.config.settings.ltex[configtype] = {
[lang] = M.lines_from(M.file[configtype]), [lang] = lines_from(files[configtype]),
} }
return client.notify('workspace/didChangeConfiguration', client.config.settings) return client.notify('workspace/didChangeConfiguration', client.config.settings)
else else
@@ -52,7 +52,7 @@ local update_config = function(lang, configtype)
end end
local add_to_file = function(configtype, lang, file, value) local add_to_file = function(configtype, lang, file, value)
local dict = M.lines_from(file) local dict = lines_from(file)
for _, v in ipairs(dict) do for _, v in ipairs(dict) do
if v == value then if v == value then
return nil return nil
@@ -71,7 +71,7 @@ end
local do_command = function(arg, configtype) local do_command = function(arg, configtype)
for lang, words in pairs(arg) do for lang, words in pairs(arg) do
for _, word in ipairs(words) do for _, word in ipairs(words) do
add_to_file(configtype, lang, M.file[configtype], word) add_to_file(configtype, lang, files[configtype], word)
end end
end end
end end
@@ -86,7 +86,7 @@ vim.lsp.commands['_ltex.hideFalsePositives'] = function(command, _)
do_command(command.arguments[1].falsePositives, 'hiddenFalsePositives') do_command(command.arguments[1].falsePositives, 'hiddenFalsePositives')
end end
M.on_attach = function() local post_attach = function()
vim.cmd('setlocal spell') vim.cmd('setlocal spell')
vim.cmd('setlocal nospell') vim.cmd('setlocal nospell')
update_config('en-US', 'dictionary') update_config('en-US', 'dictionary')
@@ -108,4 +108,25 @@ M.on_attach = function()
}) })
end end
M.setup = function(opts)
require('lspconfig')['ltex'].setup {
on_attach = function(client)
opts.on_attach(client)
post_attach()
end,
capabilities = opts.capabilities,
flags = opts.flags,
settings = {
ltex = {
dictionary = {},
disabledRules = {},
hiddenFalsePositives = {},
additionalRules = {
enablePickyRules = true,
},
},
},
}
end
return M return M

View File

@@ -1,7 +1,5 @@
local servers = { 'pyright', 'sumneko_lua', 'eslint', 'tsserver', 'ltex' } local servers = { 'pyright', 'sumneko_lua', 'eslint', 'tsserver', 'ltex' }
local ltex = require('lspconfig.ltex')
-- Mappings. -- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions -- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true } local opts = { noremap=true, silent=true }
@@ -41,10 +39,8 @@ require("mason-lspconfig").setup({
ensure_installed = servers ensure_installed = servers
}) })
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
for _, lsp in pairs(servers) do for _, lsp in pairs(servers) do
require('lspconfig')[lsp].setup { local lsp_opts = {
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities, capabilities = capabilities,
flags = { flags = {
@@ -52,30 +48,14 @@ for _, lsp in pairs(servers) do
debounce_text_changes = 150, debounce_text_changes = 150,
} }
} }
local status, config = pcall(require, 'lspconfig.' .. lsp)
if status then
config.setup(lsp_opts)
else
require('lspconfig')[lsp].setup(lsp_opts)
end
end end
require('lspconfig')['ltex'].setup {
on_attach = function(client)
on_attach(client)
ltex.on_attach()
end,
capabilities = capabilities,
flags = {
-- This will be the default in neovim 0.7+
debounce_text_changes = 150,
},
settings = {
ltex = {
dictionary = {},
disabledRules = {},
hiddenFalsePositives = {},
additionalRules = {
enablePickyRules = true,
},
},
},
}
-- luasnip setup -- luasnip setup
local luasnip = require 'luasnip' local luasnip = require 'luasnip'
require('luasnip.loaders.from_vscode').lazy_load() require('luasnip.loaders.from_vscode').lazy_load()

View File

@@ -8,3 +8,5 @@ Mathematica
DSLs DSLs
GPLs GPLs
Plasil Plasil
Monto
Keidel

Binary file not shown.