improve on_attach override

neovim_0_5
ray-x 3 years ago
parent 47656e063e
commit e64c56789f

@ -5,6 +5,7 @@ _NgConfigValues = {
preview_height = 0.35,
height = 0.35,
default_mapping = true,
combined_attach = "both", -- both: use both customized attach and navigator default attach, mine: only use my attach defined in vimrc
on_attach = nil,
-- function(client, bufnr)
-- -- your on_attach will be called at end of navigator on_attach

@ -13,7 +13,6 @@ end
local M = {}
M.on_attach = function(client, bufnr)
log("on_attach")
local uri = vim.uri_from_bufnr(bufnr)
if uri == "file://" or uri == "file:///" or #uri < 11 then
log("skip for float buffer", uri)
@ -43,11 +42,11 @@ M.on_attach = function(client, bufnr)
local config = require"navigator".config_values()
trace(client.name, "navigator on attach")
if config.on_attach ~= nil then
trace(client.name, "general attach")
log(client.name, "customized attach for all clients")
config.on_attach(client, bufnr)
end
if config.lsp and config.lsp[client.name] and config.lsp[client.name].on_attach ~= nil then
trace(client.name, "custom attach")
log("lsp client specific attach for", client.name)
config.lsp[client.name].on_attach(client, bufnr)
end

@ -316,6 +316,19 @@ local function wait_lsp_startup(ft, retry, lsp_opts)
if lsp_opts[lspclient] ~= nil then
-- log(lsp_opts[lspclient], cfg)
cfg = vim.tbl_deep_extend("force", cfg, lsp_opts[lspclient])
if _NgConfigValues.combined_attach == "both" or _NgConfigValues.combined_attach == nil then
cfg.on_attach = on_attach
elseif _NgConfigValues == "mine" then
cfg.on_attach = function(client, bufnr)
if _NgConfigValues.on_attach then
_NgConfigValues.on_attach(client, bufnr)
end
if setups[lspclient] and setups[lspclient].on_attach then
setups[lspclient].on_attach(client, bufnr)
end
end
end
end
load_cfg(ft, lspclient, cfg, loaded)

Loading…
Cancel
Save