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
|
2021-05-21 11:39:46 +00:00
|
|
|
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)
|
2021-05-27 01:10:32 +00:00
|
|
|
local uri = vim.uri_from_bufnr(bufnr)
|
2021-09-19 02:42:34 +00:00
|
|
|
|
2021-05-28 00:10:28 +00:00
|
|
|
if uri == "file://" or uri == "file:///" or #uri < 11 then
|
2021-05-27 01:10:32 +00:00
|
|
|
log("skip for float buffer", uri)
|
2021-05-28 00:10:28 +00:00
|
|
|
return {error = "invalid file", result = nil}
|
2021-05-27 01:10:32 +00:00
|
|
|
end
|
|
|
|
log("attaching", bufnr, client.name, uri)
|
2021-05-21 11:39:46 +00:00
|
|
|
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
|
2021-05-17 03:15:15 +00:00
|
|
|
require"navigator.lspclient.highlight".add_highlight()
|
2021-09-19 02:42:34 +00:00
|
|
|
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")
|
|
|
|
|
2021-05-17 03:15:15 +00:00
|
|
|
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
|
|
|
|
|
2021-05-17 03:15:15 +00:00
|
|
|
require"navigator.lspclient.lspkind".init()
|
2021-04-19 02:56:32 +00:00
|
|
|
|
2021-05-23 04:10:49 +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")
|
2021-05-23 04:10:49 +00:00
|
|
|
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)
|
2021-05-23 04:10:49 +00:00
|
|
|
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
|