remove mk_handler. update documentFormator

serverCapcities
ray-x 2 years ago
parent 0ac13663cf
commit 4d93172915

@ -4,8 +4,6 @@
local codelens = require('vim.lsp.codelens')
local log = require('navigator.util').log
local mk_handler = require('navigator.util').mk_handler
local nvim_0_6_1 = require('navigator.util').nvim_0_6_1
local trace = require('navigator.util').trace
local lsphelper = require('navigator.lspwrapper')
@ -49,7 +47,7 @@ local function _update_sign(line)
end
end
local codelens_hdlr = mk_handler(function(err, result, ctx, cfg)
local codelens_hdlr = function(err, result, ctx, cfg)
trace(ctx, result)
M.codelens_ctx = ctx
if err or result == nil then
@ -62,7 +60,7 @@ local codelens_hdlr = mk_handler(function(err, result, ctx, cfg)
for _, v in pairs(result) do
_update_sign(v.range.start.line)
end
end)
end
function M.setup()
vim.cmd('highlight! link LspCodeLens LspDiagnosticsHint')
@ -75,18 +73,13 @@ function M.setup()
vim.cmd("autocmd BufEnter,CursorHold,InsertLeave <buffer> lua require('navigator.codelens').refresh()")
vim.cmd('augroup end')
local on_codelens = vim.lsp.handlers['textDocument/codeLens']
vim.lsp.handlers['textDocument/codeLens'] = mk_handler(function(err, result, ctx, cfg)
vim.lsp.handlers['textDocument/codeLens'] = function(err, result, ctx, cfg)
-- trace(err, result, ctx.client_id, ctx.bufnr, cfg or {})
cfg = cfg or {}
ctx = ctx or { bufnr = vim.api.nvim_get_current_buf() }
if nvim_0_6_1() then
on_codelens(err, result, ctx, cfg)
codelens_hdlr(err, result, ctx, cfg)
else
on_codelens(err, ctx.method, result, ctx.client_id, ctx.bufnr)
codelens_hdlr(err, nil, result, ctx.client_id or 0, ctx.bufnr or 0)
end
end)
on_codelens(err, result, ctx, cfg)
codelens_hdlr(err, result, ctx, cfg)
end
end
M.lsp_clients = {}

@ -5,7 +5,7 @@ local gui = require('navigator.gui')
local log = util.log
local TextView = require('guihua.textview')
-- callback for lsp definition, implementation and declaration handler
local definition_hdlr = util.mk_handler(function(err, locations, ctx, _)
local definition_hdlr = function(err, locations, ctx, _)
-- log(locations)
if err ~= nil then
vim.notify('Defination: ' .. tostring(err) .. vim.inspect(ctx), vim.lsp.log_levels.WARN)
@ -31,7 +31,7 @@ local definition_hdlr = util.mk_handler(function(err, locations, ctx, _)
else
vim.lsp.util.jump_to_location(locations, oe)
end
end)
end
local function get_symbol()
local currentWord = vim.fn.expand('<cword>')

@ -9,7 +9,6 @@ local trace = require('guihua.log').trace
-- trace = log
local error = util.error
local path_sep = require('navigator.util').path_sep()
local mk_handler = require('navigator.util').mk_handler
local path_cur = require('navigator.util').path_cur()
local empty = util.empty
@ -194,7 +193,7 @@ local update_err_marker_async = function()
return debounce(400, error_marker)
end
local diag_hdlr = mk_handler(function(err, result, ctx, config)
local diag_hdlr = function(err, result, ctx, config)
require('navigator.lspclient.highlight').diagnositc_config_sign()
config = config or diagnostic_cfg
if err ~= nil then
@ -305,7 +304,7 @@ local diag_hdlr = mk_handler(function(err, result, ctx, config)
vim.api.nvim_buf_clear_namespace(0, _NG_VT_DIAG_NS, 0, -1)
_NG_VT_DIAG_NS = nil
end
end)
end
local diag_hdlr_async = function()
local debounce = require('navigator.debounce').debounce_trailing

@ -1,7 +1,6 @@
local util = require('navigator.util')
local log = util.log
local trace = util.trace
local mk_handler = util.mk_handler
local api = vim.api
local references = {}
_NG_hi_list = {}
@ -139,7 +138,7 @@ local function before(r1, r2)
return false
end
local handle_document_highlight = mk_handler(function(_, result, ctx)
local handle_document_highlight = function(_, result, ctx)
trace(result, ctx)
if not ctx.bufnr then
log('ducment highlight error', result, ctx)
@ -157,7 +156,7 @@ local handle_document_highlight = mk_handler(function(_, result, ctx)
references[ctx.bufnr] = result
local client_id = ctx.client_id
vim.lsp.util.buf_highlight_references(ctx.bufnr, result, util.encoding(client_id))
end)
end
-- modify from vim-illuminate
local function goto_adjent_reference(opt)
trace(opt)
@ -227,7 +226,7 @@ local function documentHighlight()
]],
false
)
vim.lsp.handlers['textDocument/documentHighlight'] = mk_handler(function(err, result, ctx)
vim.lsp.handlers['textDocument/documentHighlight'] = function(err, result, ctx)
local bufnr = ctx.bufnr or api.nvim_get_current_buf()
if err then
vim.notify(err, vim.lsp.log_levels.ERROR)
@ -250,7 +249,7 @@ local function documentHighlight()
end)
references[bufnr] = result
add_locs(bufnr, result)
end)
end
end
return {

@ -1,5 +1,4 @@
local log = require('navigator.util').log
local mk_handler = require('navigator.util').mk_handler
local lsp = vim.lsp
local api = vim.api
@ -88,7 +87,7 @@ function M.debug_folds()
end
end
M.fold_handler = mk_handler(function(err, result, ctx, config)
M.fold_handler = function(err, result, ctx, config)
-- params: err, method, result, client_id, bufnr
-- XXX: handle err?
if err or result == nil or #result == 0 then
@ -112,7 +111,7 @@ M.fold_handler = mk_handler(function(err, result, ctx, config)
api.nvim_win_set_option(current_window, 'foldmethod', 'expr')
api.nvim_win_set_option(current_window, 'foldexpr', 'foldlsp#foldexpr()')
end
end)
end
function M.adjust_foldstart(line_no)
return line_no + 1

@ -1,8 +1,7 @@
-- https://github.com/wention/dotfiles/blob/master/.config/nvim/lua/config/lsp.lua
-- https://github.com/lukas-reineke/dotfiles/blob/master/vim/lua/lsp/handlers.lua
local mk_handler = require('navigator.util').mk_handler
return {
format_hdl = mk_handler(function(err, result, ctx, cfg) -- FIXME: bufnr is nil
format_hdl = function(err, result, ctx, cfg) -- FIXME: bufnr is nil
if err ~= nil or result == nil then
return
end
@ -31,5 +30,5 @@ return {
-- end
end
end, 100)
end),
end,
}

@ -1,5 +1,4 @@
local util = require('navigator.util')
local mk_handler = util.mk_handler
local lsphelper = require('navigator.lspwrapper')
local gui = require('navigator.gui')
local M = {}

@ -432,8 +432,25 @@ local function load_cfg(ft, client, cfg, loaded)
-- need to verify the lsp server is up
end
local function setup_fmt(client, enabled)
if not require('navigator.util').nvim_0_8() then
if enabled == false then
client.resolved_capabilities.document_formatting = enabled
else
client.resolved_capabilities.document_formatting = client.resolved_capabilities.document_formatting or enabled
end
end
if enabled == false then
client.server_capabilities.documentFormattingProvider = false
else
client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider
or enabled
end
end
local function update_capabilities()
trace(ft, 'lsp startup')
trace(vim.o.ft, 'lsp startup')
local loaded = {}
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
@ -521,6 +538,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
-- filetype disabled
if not vim.tbl_contains(cfg.filetypes or {}, ft) then
trace('ft', ft, 'disabled for', lspclient)
goto continue
end
@ -539,15 +557,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
-- log(lsp_opts[lspclient], cfg)
cfg = vim.tbl_deep_extend('force', cfg, user_lsp_opts[lspclient])
if config.combined_attach == nil then
cfg.on_attach = function(client, bufnr)
on_attach(client, bufnr)
if enable_fmt then
client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider
or enable_fmt
else
client.server_capabilities.documentFormattingProvider = false
end
end
setup_fmt(client, enable_fmt)
end
if config.combined_attach == 'mine' then
if config.on_attach == nil then
@ -555,12 +565,8 @@ local function lsp_startup(ft, retry, user_lsp_opts)
end
cfg.on_attach = function(client, bufnr)
config.on_attach(client, bufnr)
if enable_fmt then
client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider
or enable_fmt
else
client.server_capabilities.documentFormattingProvider = false
end
setup_fmt(client, enable_fmt)
require('navigator.lspclient.mapping').setup({
client = client,
bufnr = bufnr,
@ -572,12 +578,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
cfg.on_attach = function(client, bufnr)
on_attach(client, bufnr)
config.on_attach(client, bufnr)
if enable_fmt then
client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider
or enable_fmt
else
client.server_capabilities.documentFormattingProvider = false
end
setup_fmt(client, enable_fmt)
require('navigator.lspclient.mapping').setup({
client = client,
bufnr = bufnr,
@ -587,12 +588,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
end
if config.combined_attach == 'both' then
cfg.on_attach = function(client, bufnr)
if enable_fmt then
client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider
or enable_fmt
else
client.server_capabilities.documentFormattingProvider = false
end
setup_fmt(client, enable_fmt)
if config.on_attach and type(config.on_attach) == 'function' then
config.on_attach(client, bufnr)
@ -622,12 +618,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
cfg.on_attach = function(client, bufnr)
on_attach(client, bufnr)
if enable_fmt then
client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider
or enable_fmt
else
client.server_capabilities.documentFormattingProvider = false
end
setup_fmt(client, enable_fmt)
end
end

@ -1,7 +1,6 @@
local M = {}
local util = require('navigator.util')
local nvim_0_6_1 = util.nvim_0_6_1()
local gutil = require('guihua.util')
local lsp = require('vim.lsp')
@ -146,11 +145,7 @@ function M.call_sync(method, params, opts, handler)
opts = opts or {}
local results_lsp, err = lsp.buf_request_sync(0, method, params, opts.timeout or vim.g.navtator_timeout or 1000)
if nvim_0_6_1 then
handler(err, extract_result(results_lsp), { method = method }, nil)
else
handler(err, method, extract_result(results_lsp), nil, nil)
end
handler(err, extract_result(results_lsp), { method = method }, nil)
end
function M.call_async(method, params, handler)

@ -1,5 +1,4 @@
local util = require('navigator.util')
local mk_handler = util.mk_handler
local log = util.log
local lsphelper = require('navigator.lspwrapper')
local gui = require('navigator.gui')
@ -135,7 +134,7 @@ local ref_view = function(err, locations, ctx, cfg)
return listview, items, width
end
local ref_hdlr = mk_handler(function(err, locations, ctx, cfg)
local ref_hdlr = function(err, locations, ctx, cfg)
_NgConfigValues.closer = nil
trace(err, locations, ctx, cfg)
M.async_hdlr = vim.loop.new_async(vim.schedule_wrap(function()
@ -145,7 +144,7 @@ local ref_hdlr = mk_handler(function(err, locations, ctx, cfg)
end
end))
M.async_hdlr:send()
end)
end
local async_ref = function()
local ref_params = vim.lsp.util.make_position_params()

@ -1,6 +1,5 @@
local gui = require "navigator.gui"
local util = require "navigator.util"
local mk_handler = util.mk_handler
local log = util.log
local partial = util.partial
local lsphelper = require "navigator.lspwrapper"
@ -47,7 +46,7 @@ local match_parameter = function(result)
end
end
local signature_handler = mk_handler(function(err, result, ctx, config)
local signature_handler = function(err, result, ctx, config)
if config == nil then
log("config nil")
end
@ -71,5 +70,5 @@ local signature_handler = mk_handler(function(err, result, ctx, config)
local syntax = vim.lsp.util.try_trim_markdown_code_blocks(lines)
config.focus_id = ctx.bufnr .. "lsp_signature"
vim.lsp.util.open_floating_preview(lines, syntax, config)
end)
end
return {signature_handler = signature_handler}

@ -2,7 +2,6 @@ local gui = require('navigator.gui')
local M = {}
local log = require('navigator.util').log
local trace = require('navigator.util').trace
local mk_handler = require('navigator.util').mk_handler
local lsphelper = require('navigator.lspwrapper')
local locations_to_items = lsphelper.locations_to_items
local clone = require('guihua.util').clone
@ -43,7 +42,7 @@ function M.document_symbols(opts)
end)
end
M.document_symbol_handler = mk_handler(function(err, result, ctx)
M.document_symbol_handler = function(err, result, ctx)
if err then
vim.notify('failed to get document symbol' .. vim.inspect(ctx), vim.lsp.log_levels.WARN)
end
@ -101,9 +100,9 @@ M.document_symbol_handler = mk_handler(function(err, result, ctx)
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft')
gui.new_list_view({ items = locations, prompt = true, rawdata = true, ft = ft, api = '' })
end)
end
M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg)
M.workspace_symbol_handler = function(err, result, ctx, cfg)
trace(err, result, ctx, cfg)
if err then
vim.notify('failed to get workspace symbol' .. vim.inspect(ctx), vim.lsp.log_levels.WARN)
@ -123,6 +122,6 @@ M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg)
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft')
gui.new_list_view({ items = items, prompt = true, ft = ft, rowdata = true, api = '' })
end)
end
return M

@ -5,6 +5,7 @@ local M = { log_path = vim.lsp.get_log_path() }
-- local is_windows = uv.os_uname().version:match("Windows")
local guihua = require('guihua.util')
local nvim_0_6_1
local nvim_0_8
M.path_sep = function()
local is_win = vim.loop.os_uname().sysname:find('Windows')
@ -354,11 +355,20 @@ function M.nvim_0_6_1()
return nvim_0_6_1
end
function M.nvim_0_8()
if nvim_0_8 ~= nil then
return nvim_0_8
end
nvim_0_8 = vim.fn.has('nvim-0.8') == 1
if nvim_0_8 == false then
M.warn('Please use navigator 0.4 version for neovim version < 0.8')
end
return nvim_0_8
end
function M.mk_handler(fn)
return function(...)
if M.nvim_0_6_1() then
return fn(...)
end
return fn(...)
end
end
@ -392,7 +402,7 @@ function M.encoding(client)
return 'utf-8'
end
if type(oe) == 'table' then
oe = oe[1] or 'utf-8'
return oe[1]
end
return oe
end

Loading…
Cancel
Save