navigator.lua/lua/navigator/lspclient/attach.lua

61 lines
1.7 KiB
Lua
Raw Normal View History

2021-04-19 02:56:32 +00:00
local vim, api = vim, vim.api
local lsp = require("vim.lsp")
local util = require "navigator.util"
local log = util.log
local trace = util.trace
2021-04-19 02:56:32 +00:00
local diagnostic_map = function(bufnr)
local opts = {noremap = true, silent = true}
api.nvim_buf_set_keymap(bufnr, "n", "]O", ":lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
end
2021-05-28 00:10:28 +00:00
2021-04-19 02:56:32 +00:00
local M = {}
M.on_attach = function(client, bufnr)
local uri = vim.uri_from_bufnr(bufnr)
2021-05-28 00:10:28 +00:00
if uri == "file://" or uri == "file:///" or #uri < 11 then
log("skip for float buffer", uri)
2021-05-28 00:10:28 +00:00
return {error = "invalid file", result = nil}
end
log("attaching", bufnr, client.name, uri)
trace(client)
2021-06-17 23:24:02 +00:00
2021-04-19 02:56:32 +00:00
diagnostic_map(bufnr)
2021-05-28 00:10:28 +00:00
-- add highlight for Lspxxx
require"navigator.lspclient.highlight".add_highlight()
require"navigator.lspclient.highlight".diagnositc_config_sign()
2021-04-19 02:56:32 +00:00
api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
require("navigator.lspclient.mapping").setup({
client = client,
bufnr = bufnr,
cap = client.resolved_capabilities
})
2021-05-08 04:54:37 +00:00
2021-04-19 02:56:32 +00:00
if client.resolved_capabilities.document_highlight then
2021-05-08 04:54:37 +00:00
require("navigator.dochighlight").documentHighlight()
2021-04-19 02:56:32 +00:00
end
require"navigator.lspclient.lspkind".init()
2021-04-19 02:56:32 +00:00
local config = require"navigator".config_values()
trace(client.name, "navigator on attach")
if config.on_attach ~= nil then
2021-07-05 01:21:52 +00:00
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
2021-07-05 01:21:52 +00:00
log("lsp client specific attach for", client.name)
config.lsp[client.name].on_attach(client, bufnr)
end
2021-06-17 14:49:13 +00:00
2021-04-19 02:56:32 +00:00
end
2021-05-28 00:10:28 +00:00
-- M.setup = function(cfg)
-- return M
-- end
2021-04-19 02:56:32 +00:00
return M