ray-x 2 years ago
parent da9448a88c
commit 4ca6b376a7

@ -21,15 +21,16 @@ local definition_hdlr = util.mk_handler(function(err, locations, ctx, _)
end end
local client = vim.lsp.get_client_by_id(ctx.client_id) local client = vim.lsp.get_client_by_id(ctx.client_id)
local oe = require('navigator.util').encoding()
if vim.tbl_islist(locations) then if vim.tbl_islist(locations) then
if #locations > 1 then if #locations > 1 then
local items = locations_to_items(locations) local items = locations_to_items(locations)
gui.new_list_view({ items = items, api = 'Definition' }) gui.new_list_view({ items = items, api = 'Definition' })
else else
vim.lsp.util.jump_to_location(locations[1], client.offset_encoding) vim.lsp.util.jump_to_location(locations[1], oe)
end end
else else
vim.lsp.util.jump_to_location(locations, client.offset_encoding) vim.lsp.util.jump_to_location(locations, oe)
end end
end) end)

@ -154,7 +154,7 @@ local handle_document_highlight = mk_handler(function(_, result, ctx)
references[ctx.bufnr] = result references[ctx.bufnr] = result
local client_id = ctx.client_id local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id) local client = vim.lsp.get_client_by_id(client_id)
vim.lsp.util.buf_highlight_references(ctx.bufnr, result, client.offset_encoding) vim.lsp.util.buf_highlight_references(ctx.bufnr, result, util.encoding())
end) end)
-- modify from vim-illuminate -- modify from vim-illuminate
local function goto_adjent_reference(opt) local function goto_adjent_reference(opt)
@ -248,7 +248,7 @@ local function documentHighlight()
local client_id = ctx.client_id local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id) local client = vim.lsp.get_client_by_id(client_id)
vim.lsp.util.buf_clear_references(bufnr) vim.lsp.util.buf_clear_references(bufnr)
vim.lsp.util.buf_highlight_references(bufnr, result, client.offset_encoding) vim.lsp.util.buf_highlight_references(bufnr, result, util.encoding())
table.sort(result, function(a, b) table.sort(result, function(a, b)
return before(a.range, b.range) return before(a.range, b.range)
end) end)

@ -10,7 +10,7 @@ return {
local util = require('navigator.util') local util = require('navigator.util')
local log = util.log local log = util.log
local offset_encoding = vim.lsp.get_client_by_id(ctx.client_id).offset_encoding local offset_encoding = util.encoding(vim.lsp.get_client_by_id(ctx.client_id))
-- If the buffer hasn't been modified before the formatting has finished, -- If the buffer hasn't been modified before the formatting has finished,
-- update the buffer -- update the buffer

@ -1,62 +1,67 @@
local vim, api = vim, vim.api local vim, api = vim, vim.api
local lsp = require("vim.lsp") local lsp = require('vim.lsp')
local util = require "navigator.util" local util = require('navigator.util')
local log = util.log local log = util.log
local trace = util.trace local trace = util.trace
local diagnostic_map = function(bufnr) local diagnostic_map = function(bufnr)
local opts = {noremap = true, silent = true} local opts = { noremap = true, silent = true }
api.nvim_buf_set_keymap(bufnr, "n", "]O", ":lua vim.lsp.diagnostic.set_loclist()<CR>", opts) api.nvim_buf_set_keymap(bufnr, 'n', ']O', ':lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
end end
local M = {} local M = {}
M.on_attach = function(client, bufnr) M.on_attach = function(client, bufnr)
bufnr = bufnr or 0
if bufnr == 0 then
log('no bufnr provided')
end
local uri = vim.uri_from_bufnr(bufnr) local uri = vim.uri_from_bufnr(bufnr)
if uri == "file://" or uri == "file:///" or #uri < 11 then if uri == 'file://' or uri == 'file:///' or #uri < 11 then
log("skip for float buffer", uri) log('skip for float buffer', uri)
return {error = "invalid file", result = nil} return { error = 'invalid file', result = nil }
end end
log("attaching: ", bufnr, client.name, uri) log('attaching: ', bufnr, client.name, uri)
trace(client) trace(client)
diagnostic_map(bufnr) diagnostic_map(bufnr)
-- add highlight for Lspxxx -- add highlight for Lspxxx
require"navigator.lspclient.highlight".add_highlight() require('navigator.lspclient.highlight').add_highlight()
require"navigator.lspclient.highlight".diagnositc_config_sign() require('navigator.lspclient.highlight').diagnositc_config_sign()
api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
require("navigator.lspclient.mapping").setup({ require('navigator.lspclient.mapping').setup({
client = client, client = client,
bufnr = bufnr, bufnr = bufnr,
cap = client.resolved_capabilities cap = client.resolved_capabilities,
}) })
if client.resolved_capabilities.document_highlight then if client.resolved_capabilities.document_highlight then
require("navigator.dochighlight").documentHighlight() require('navigator.dochighlight').documentHighlight()
end end
require"navigator.lspclient.lspkind".init() require('navigator.lspclient.lspkind').init()
local config = require"navigator".config_values() local config = require('navigator').config_values()
trace(client.name, "navigator on attach") trace(client.name, 'navigator on attach')
if config.on_attach ~= nil then if config.on_attach ~= nil then
log(client.name, "customized attach for all clients") log(client.name, 'customized attach for all clients')
config.on_attach(client, bufnr) config.on_attach(client, bufnr)
end end
if config.lsp and config.lsp[client.name] and config.lsp[client.name].on_attach ~= nil then if config.lsp and config.lsp[client.name] and config.lsp[client.name].on_attach ~= nil then
log("lsp client specific attach for", client.name) log('lsp client specific attach for', client.name)
config.lsp[client.name].on_attach(client, bufnr) config.lsp[client.name].on_attach(client, bufnr)
end end
if _NgConfigValues.lsp.code_action.enable then if _NgConfigValues.lsp.code_action.enable then
if client.resolved_capabilities.code_action then if client.resolved_capabilities.code_action then
log('code action enabled for client', client.resolved_capabilities.code_action) log('code action enabled for client', client.resolved_capabilities.code_action)
vim.cmd [[autocmd CursorHold,CursorHoldI <buffer> lua require'navigator.codeAction'.code_action_prompt()]] vim.cmd([[autocmd CursorHold,CursorHoldI <buffer> lua require'navigator.codeAction'.code_action_prompt()]])
end end
end end
end end

@ -402,6 +402,17 @@ function M.empty(t)
return next(t) == nil return next(t) == nil
end end
function M.encoding(client)
local oe = client.offset_encoding
if oe == nil then
return 'utf-8'
end
if type(oe) == 'table' then
oe = oe[1] or 'utf-8'
end
return oe
end
-- alternatively: use vim.notify("namespace does not exist or is anonymous", vim.log.levels.ERROR) -- alternatively: use vim.notify("namespace does not exist or is anonymous", vim.log.levels.ERROR)
function M.warn(msg) function M.warn(msg)

Loading…
Cancel
Save