add debounce setup in lsp

neovim_0_5
ray-x 3 years ago
parent 01cd2e8020
commit b56ca88390

@ -0,0 +1,24 @@
-- https://github.com/wention/dotfiles/blob/master/.config/nvim/lua/config/lsp.lua
-- https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/handlers.lua
return {
format_hdl = function(err, _, result, _, bufnr) -- FIXME: bufnr is nil
if err ~= nil or result == nil then
return
end
-- If the buffer hasn't been modified before the formatting has finished,
-- update the buffer
if not vim.api.nvim_buf_get_option(bufnr, 'modified') then
local view = vim.fn.winsaveview()
vim.lsp.util.apply_text_edits(result, bufnr)
vim.fn.winrestview(view)
-- FIXME: commented out as a workaround
-- if bufnr == vim.api.nvim_get_current_buf() then
vim.api.nvim_command('noautocmd :update')
-- Trigger post-formatting autocommand which can be used to refresh gitgutter
-- vim.api.nvim_command('silent doautocmd <nomodeline> User FormatterPost')
-- end
end
end
}

@ -53,6 +53,7 @@ M.on_attach = function(client, bufnr)
trace(client.name, "custom attach")
config.lsp[client.name].on_attach(client, bufnr)
end
end
-- M.setup = function(cfg)

@ -103,6 +103,7 @@ local setups = {
},
settings = {
gopls = {
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
analyses = {unusedparams = true, unreachable = false},
codelenses = {
generate = true, -- show the `go generate` lens.
@ -124,6 +125,7 @@ local setups = {
end
},
clangd = {
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
cmd = {
"clangd", "--background-index", "--suggest-missing-includes", "--clang-tidy",
"--header-insertion=iwyu"
@ -148,7 +150,8 @@ local setups = {
cargo = {loadOutDirsFromCheck = true},
procMacro = {enable = true}
}
}
},
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
},
sqls = {
filetypes = {"sql"},
@ -157,6 +160,7 @@ local setups = {
highlight.diagnositc_config_sign()
require"sqls".setup {picker = "telescope"} -- or default
end,
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
settings = {
cmd = {"sqls", "-config", "$HOME/.config/sqls/config.yml"}
-- alterantively:
@ -172,6 +176,7 @@ local setups = {
cmd = {"lua-language-server"},
filetypes = {"lua"},
on_attach = on_attach,
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
settings = {
Lua = {
runtime = {
@ -199,6 +204,7 @@ local setups = {
pyright = {
cmd = {"pyright-langserver", "--stdio"},
filetypes = {"python"},
flags = { allow_incremental_sync = true, debounce_text_changes = 500},
settings = {
python = {
analysis = {
@ -215,7 +221,8 @@ local setups = {
root_dir = [[ util.root_pattern("compile_commands.json", "compile_flags.txt", "CMakeLists.txt", "Makefile", ".git") or util.path.dirname ]],
index = {threads = 2},
clang = {excludeArgs = {"-frounding-math"}}
}
},
flags = { allow_incremental_sync = true },
}
}
@ -227,7 +234,7 @@ local servers = {
"terraformls"
}
local default_cfg = {on_attach = on_attach}
local default_cfg = {on_attach = on_attach, flags = { allow_incremental_sync = true, debounce_text_changes = 500 },}
-- check and load based on file type
local function load_cfg(ft, client, cfg, loaded)
@ -290,6 +297,7 @@ local function wait_lsp_startup(ft, retry, lsp_opts)
trace(cfg)
end
load_cfg(ft, lspclient, cfg, loaded)
::continue::
end

@ -199,6 +199,7 @@ function M.setup(user_opts)
end
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {border = single})
vim.lsp.handlers["textDocument/formatting"] = require"navigator.formatting".format_hdl
end
return M

Loading…
Cancel
Save