[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
|
||||
|
||||
Reference in New Issue
Block a user