[NeoVim] Better LSP management
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
local M = {}
|
||||
|
||||
M.file = {
|
||||
local files = {
|
||||
dictionary = vim.fn.stdpath('config') .. '/spell/en.utf-8.add',
|
||||
disabledRules = vim.fn.stdpath('config') .. '/spell/disable.txt',
|
||||
hiddenFalsePositives = vim.fn.stdpath('config') .. '/spell/false.txt',
|
||||
@@ -14,7 +14,7 @@ local file_exists = function(file)
|
||||
return f ~= nil
|
||||
end
|
||||
|
||||
M.lines_from = function(file)
|
||||
local lines_from = function(file)
|
||||
if not file_exists(file) then
|
||||
return {}
|
||||
end
|
||||
@@ -40,7 +40,7 @@ local update_config = function(lang, configtype)
|
||||
if client then
|
||||
if client.config.settings.ltex[configtype] then
|
||||
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)
|
||||
else
|
||||
@@ -52,7 +52,7 @@ local update_config = function(lang, configtype)
|
||||
end
|
||||
|
||||
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
|
||||
if v == value then
|
||||
return nil
|
||||
@@ -71,7 +71,7 @@ end
|
||||
local do_command = function(arg, configtype)
|
||||
for lang, words in pairs(arg) 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
|
||||
@@ -86,7 +86,7 @@ vim.lsp.commands['_ltex.hideFalsePositives'] = function(command, _)
|
||||
do_command(command.arguments[1].falsePositives, 'hiddenFalsePositives')
|
||||
end
|
||||
|
||||
M.on_attach = function()
|
||||
local post_attach = function()
|
||||
vim.cmd('setlocal spell')
|
||||
vim.cmd('setlocal nospell')
|
||||
update_config('en-US', 'dictionary')
|
||||
@@ -108,4 +108,25 @@ M.on_attach = function()
|
||||
})
|
||||
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
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
local servers = { 'pyright', 'sumneko_lua', 'eslint', 'tsserver', 'ltex' }
|
||||
|
||||
local ltex = require('lspconfig.ltex')
|
||||
|
||||
-- Mappings.
|
||||
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
||||
local opts = { noremap=true, silent=true }
|
||||
@@ -41,10 +39,8 @@ require("mason-lspconfig").setup({
|
||||
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
|
||||
require('lspconfig')[lsp].setup {
|
||||
local lsp_opts = {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
flags = {
|
||||
@@ -52,30 +48,14 @@ for _, lsp in pairs(servers) do
|
||||
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
|
||||
|
||||
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
|
||||
local luasnip = require 'luasnip'
|
||||
require('luasnip.loaders.from_vscode').lazy_load()
|
||||
|
||||
Reference in New Issue
Block a user