Updata on_attach logic, allow lsp specific on_attach as well as generic

on_attach. Document updates
neovim_0_5
ray-x 3 years ago
parent 7c6c37d169
commit 8c055b7b03

@ -155,6 +155,7 @@ require.'navigator'.setup({
-- function(client, bufnr)
-- -- the on_attach will be called at end of navigator on_attach
-- end,
-- The attach code will apply to all LSP clients
treesitter_analysis = true, -- treesitter variable context
sumneko_root_path = vim.fn.expand("$HOME") .. "/github/sumneko/lua-language-server",
@ -168,6 +169,12 @@ require.'navigator'.setup({
-- set to {} to disable the lspclient for all filetype
},
gopls = { -- gopls setting
on_attach = function(client, bufnr) -- on_attach for gopls
-- your special on attach here
-- e.g. disable gopls format because a known issue https://github.com/golang/go/issues/45732
print("i am a hook, I will disable document format")
client.resolved_capabilities.document_formatting = false
end,
settings = {
gopls = {gofumpt = false} -- disable gofumpt etc,
}

@ -12,17 +12,12 @@ end
local M = {}
M.on_attach = function(client, bufnr)
local uri = vim.uri_from_bufnr(bufnr)
log("loading for ft ", ft, uri)
if uri == 'file://' or uri == 'file:///' then
log("skip loading for ft ", ft, uri)
return
end
log("attaching", bufnr)
log("attaching", bufnr, client.name)
trace(client)
local hassig, sig = pcall(require, "lsp_signature")
if hassig then sig.on_attach() end
if hassig then
sig.on_attach()
end
diagnostic_map(bufnr)
-- lspsaga
require"navigator.lspclient.highlight".add_highlight()
@ -43,10 +38,20 @@ M.on_attach = function(client, bufnr)
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
local config = require"navigator".config_value
if config ~= nil and config.on_attach ~= nil then config.on_attach(client, bufnr) end
local config = require"navigator".config_values()
trace(client.name, "navigator on attach")
if config.on_attach ~= nil then
trace(client.name, "general attach")
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")
config.lsp[client.name].on_attach(client, bufnr)
end
end
M.setup = function(cfg) return M end
M.setup = function(cfg)
return M
end
return M

@ -336,6 +336,7 @@ local function setup(user_opts)
highlight.diagnositc_config_sign()
highlight.add_highlight()
local lsp_opts = user_opts.lsp
_Loading = true
wait_lsp_startup(ft, retry, lsp_opts)
_LoadedClients[ft] = true

@ -85,7 +85,7 @@ function M.get_relative_path(base_path, my_path)
return data
end
local default_config = {plugin = "navigator", use_console = false, use_file = true, level = "info"}
local default_config = {plugin = "navigator", use_console = false, use_file = true, level = "error"}
M._log = require("guihua.log").new({level = default_config.level}, true)

Loading…
Cancel
Save