updates vim.notify

neovim_0.6
ray-x 2 years ago
parent 9957766620
commit 23090c567c

@ -1,28 +1,28 @@
local util = require "navigator.util"
local lsphelper = require "navigator.lspwrapper"
local util = require('navigator.util')
local lsphelper = require('navigator.lspwrapper')
local locations_to_items = lsphelper.locations_to_items
local gui = require "navigator.gui"
local gui = require('navigator.gui')
local log = util.log
local TextView = require("guihua.textview")
local TextView = require('guihua.textview')
-- callback for lsp definition, implementation and declaration handler
local definition_hdlr = util.mk_handler(function(err, locations, ctx, _)
-- log(locations)
if err ~= nil then
vim.notify(err, ctx, vim.lsp.log_levels.WARN)
vim.notify('Defination: ', tostring(err) .. vim.inspect(ctx), vim.lsp.log_levels.WARN)
return
end
if type(locations) == "number" then
if type(locations) == 'number' then
log(locations)
log("unable to handle request")
log('unable to handle request')
end
if locations == nil or vim.tbl_isempty(locations) then
vim.notify "Definition not found"
vim.notify('Definition not found')
return
end
if vim.tbl_islist(locations) then
if #locations > 1 then
local items = locations_to_items(locations)
gui.new_list_view({items = items, api = 'Definition'})
gui.new_list_view({ items = items, api = 'Definition' })
else
vim.lsp.util.jump_to_location(locations[1])
end
@ -37,13 +37,13 @@ local function get_symbol()
end
local function def_preview(timeout_ms)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running")
local method = "textDocument/definition"
assert(#vim.lsp.buf_get_clients() > 0, 'Must have a client running')
local method = 'textDocument/definition'
local params = vim.lsp.util.make_position_params()
local result = vim.lsp.buf_request_sync(0, method, params, timeout_ms or 1000)
if result == nil or vim.tbl_isempty(result) then
vim.notify("No result found: " .. method, vim.lsp.log_levels.WARN)
vim.notify('No result found: ' .. method, vim.lsp.log_levels.WARN)
return nil
end
@ -58,7 +58,7 @@ local function def_preview(timeout_ms)
end
if vim.tbl_isempty(data) then
vim.notify("No result found: " .. method, vim.lsp.log_levels.WARN)
vim.notify('No result found: ' .. method, vim.lsp.log_levels.WARN)
return nil
end
@ -77,13 +77,13 @@ local function def_preview(timeout_ms)
vim.fn.bufload(bufnr)
end
local ok, parsers = pcall(require, "nvim-treesitter.parsers")
local ok, parsers = pcall(require, 'nvim-treesitter.parsers')
local lines_num = 12
if ok then
local ts = require 'navigator.treesitter'
local ts = require('navigator.treesitter')
local root = parsers.get_parser(bufnr)
log(range)
local def_node = ts.get_node_at_pos({range['start'].line, range['start'].character}, root)
local def_node = ts.get_node_at_pos({ range['start'].line, range['start'].character }, root)
local sr, _, er, _ = ts.get_node_scope(def_node)
log(sr, er)
@ -91,7 +91,7 @@ local function def_preview(timeout_ms)
end
-- TODO: 12 should be an option
local definition = vim.api.nvim_buf_get_lines(bufnr, row, range["end"].line + lines_num, false)
local definition = vim.api.nvim_buf_get_lines(bufnr, row, range['end'].line + lines_num, false)
local def_line = vim.api.nvim_buf_get_lines(bufnr, range.start.line, range.start.line + 1, false)
for _ = 1, math.min(3, #definition), 1 do
if #definition[1] < 2 then
@ -108,30 +108,30 @@ local function def_preview(timeout_ms)
width = math.max(width, #value + 4)
width = math.min(maxwidth, width)
end
definition = vim.list_extend({"  [" .. get_symbol() .. "] Definition: "}, definition)
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
definition = vim.list_extend({ '  [' .. get_symbol() .. '] Definition: ' }, definition)
local filetype = vim.api.nvim_buf_get_option(bufnr, 'filetype')
-- TODO multiple resuts?
local opts = {
relative = "cursor",
style = "minimal",
relative = 'cursor',
style = 'minimal',
ft = filetype,
rect = {width = width, height = #definition + 3},
rect = { width = width, height = #definition + 3 },
data = definition,
enter = true,
border = _NgConfigValues.border or "shadow"
border = _NgConfigValues.border or 'shadow',
}
TextView:new(opts)
delta = delta + 1 -- header
local cmd = "normal! " .. tostring(delta) .. "G"
local cmd = 'normal! ' .. tostring(delta) .. 'G'
vim.cmd(cmd)
vim.cmd('set cursorline')
if #def_line > 0 then
local niddle = require('guihua.util').add_escape(def_line[1])
-- log(def_line[1], niddle)
vim.fn.matchadd("Search", niddle)
vim.fn.matchadd('Search', niddle)
end
-- TODO:
-- https://github.com/oblitum/goyo.vim/blob/master/autoload/goyo.vim#L108-L135
@ -143,17 +143,16 @@ local def = function()
local ref_params = vim.lsp.util.make_position_params()
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr)
if client.resolved_capabilities.goto_definition then
client.request("textDocument/definition", ref_params, definition_hdlr, _bufnr)
client.request('textDocument/definition', ref_params, definition_hdlr, _bufnr)
end
end)
end
vim.lsp.handlers["textDocument/definition"] = definition_hdlr
vim.lsp.handlers['textDocument/definition'] = definition_hdlr
return {
definition = def,
definition_handler = definition_hdlr,
definition_preview = def_preview,
declaration_handler = definition_hdlr,
typeDefinition_handler = definition_hdlr
typeDefinition_handler = definition_hdlr,
}

@ -93,7 +93,7 @@ M.fold_handler = mk_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
vim.notify(err, ctx.method, ctx.client_id, vim.lsp.log_levels.WARN)
vim.notify(string.format("%s %s ", tostring(err), vim.inspect(ctx)), vim.lsp.log_levels.WARN)
return
end
M.debug_folds()

@ -459,9 +459,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
log(lspclient)
if lspconfig[lspclient] == nil then
vim.notify(
'lspclient',
lspclient,
'no longer support by lspconfig, please submit an issue',
'lspclient' .. vim.inspect(lspclient) .. 'no longer support by lspconfig, please submit an issue',
vim.lsp.log_levels.WARN
)
goto continue
@ -470,7 +468,7 @@ local function lsp_startup(ft, retry, user_lsp_opts)
if lspconfig[lspclient].document_config and lspconfig[lspclient].document_config.default_config then
default_config = lspconfig[lspclient].document_config.default_config
else
vim.notify('missing document config for client: ', lspclient, vim.lsp.log_levels.WARN)
vim.notify('missing document config for client: ' .. vim.inspect(lspclient), vim.lsp.log_levels.WARN)
goto continue
end

@ -29,7 +29,7 @@ local ref_view = function(err, locations, ctx, cfg)
local definitions = ctx.results.definitions
local references = ctx.results.references
if definitions.error and references.error then
vim.notify('lsp ref callback error', vim.inspect(ctx.result), vim.lsp.log_levels.WARN)
vim.notify('lsp ref callback error' .. vim.inspect(ctx.result), vim.lsp.log_levels.WARN)
end
locations = {}
if definitions.result then
@ -49,14 +49,17 @@ local ref_view = function(err, locations, ctx, cfg)
-- log("num", num)
-- log("bfnr", bufnr)
if err ~= nil then
vim.notify('lsp ref callback error', err, ctx, vim.inspect(locations), vim.lsp.log_levels.WARN)
vim.notify(
'lsp ref callback error' .. vim.inspect(err) .. vim.inspect(ctx) .. vim.inspect(locations),
vim.lsp.log_levels.WARN
)
log('ref callback error, lsp may not ready', err, ctx, vim.inspect(locations))
return
end
if type(locations) ~= 'table' then
log(locations)
log('ctx', ctx)
vim.notify('incorrect setup', locations, vim.lsp.log_levels.WARN)
vim.notify('incorrect setup' .. vim.inspect(locations), vim.lsp.log_levels.WARN)
return
end
if locations == nil or vim.tbl_isempty(locations) then
@ -82,7 +85,7 @@ local ref_view = function(err, locations, ctx, cfg)
ft = ft,
width = width,
api = 'Reference',
enable_preview_edit = true
enable_preview_edit = true,
}
local listview = gui.new_list_view(opts)
@ -131,11 +134,11 @@ end)
local async_ref = function()
local ref_params = vim.lsp.util.make_position_params()
local results = {definitions = {}, references = {}}
ref_params.context = {includeDeclaration = false}
local results = { definitions = {}, references = {} }
ref_params.context = { includeDeclaration = false }
lsp.call_async('textDocument/definition', ref_params, function(err, result, ctx, config)
trace(err, result, ctx, config)
results.definitions = {error = err, result = result, ctx = ctx, config = config}
results.definitions = { error = err, result = result, ctx = ctx, config = config }
ctx = ctx or {}
ctx.results = results
ctx.combine = true
@ -143,7 +146,7 @@ local async_ref = function()
end) -- return asyncresult, canceller
lsp.call_async('textDocument/references', ref_params, function(err, result, ctx, config)
trace(err, result, ctx, config)
results.references = {error = err, result = result, ctx = ctx, config = config}
results.references = { error = err, result = result, ctx = ctx, config = config }
ctx = ctx or {}
ctx.results = results
ctx.combine = true
@ -157,7 +160,7 @@ local ref_req = function()
_NgConfigValues.closer()
end
local ref_params = vim.lsp.util.make_position_params()
ref_params.context = {includeDeclaration = true}
ref_params.context = { includeDeclaration = true }
-- lsp.call_async("textDocument/references", ref_params, ref_hdlr) -- return asyncresult, canceller
local bufnr = vim.api.nvim_get_current_buf()
log('bufnr', bufnr)
@ -179,7 +182,6 @@ local ref = function()
end)
end
return {
reference_handler = ref_hdlr,
@ -188,6 +190,5 @@ return {
ref_view = ref_view,
async_ref = async_ref
async_ref = async_ref,
}

@ -52,7 +52,7 @@ local signature_handler = mk_handler(function(err, result, ctx, config)
log("config nil")
end
if err then
vim.notify("signature help error: ", err, vim.inspect(result), ctx, config, vim.lsp.log_levels.WARN)
vim.notify("signature help error: ".. vim.inspect(err) .. vim.inspect(result), ctx, config, vim.lsp.log_levels.WARN)
end
config = config or {}
if config.border == nil then

@ -15,13 +15,13 @@ function M.workspace_symbols(query)
loc = 'top_center',
prompt = true,
-- rawdata = true,
api = ''
api = '',
}
query = query or pcall(vim.fn.input, 'Query: ')
local bufnr = vim.api.nvim_get_current_buf()
vim.list_extend(lspopts, opts)
local params = {query = query}
local params = { query = query }
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr)
if client.resolved_capabilities.workspace_symbol then
client.request('workspace/symbol', params, M.workspace_symbol_handler, _bufnr)
@ -35,13 +35,13 @@ function M.document_symbols(opts)
loc = 'top_center',
prompt = true,
-- rawdata = true,
api = ''
api = '',
}
local bufnr = vim.api.nvim_get_current_buf()
vim.list_extend(lspopts, opts)
local params = vim.lsp.util.make_position_params()
params.context = {includeDeclaration = true}
params.context = { includeDeclaration = true }
params.query = opts.prompt or ''
vim.lsp.for_each_buffer_client(bufnr, function(client, client_id, _bufnr)
if client.resolved_capabilities.document_symbol then
@ -52,12 +52,12 @@ end
M.document_symbol_handler = mk_handler(function(err, result, ctx)
if err then
vim.notify('failed to get document symbol', ctx, vim.lsp.log_levels.WARN)
vim.notify('failed to get document symbol' .. vim.inspect(ctx), vim.lsp.log_levels.WARN)
end
local bufnr = ctx.bufnr or 0
if not result or vim.tbl_isempty(result) then
vim.notify('symbol not found for buf', ctx, vim.lsp.log_levels.WARN)
vim.notify('symbol not found for buf' .. vim.inspect(ctx), vim.lsp.log_levels.WARN)
return
end
local locations = {}
@ -103,16 +103,16 @@ M.document_symbol_handler = mk_handler(function(err, result, ctx)
end
local ft = vim.api.nvim_buf_get_option(bufnr, 'ft')
gui.new_list_view({items = locations, prompt = true, rawdata = true, ft = ft, api = ''})
gui.new_list_view({ items = locations, prompt = true, rawdata = true, ft = ft, api = '' })
end)
M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg)
trace(err, result, ctx, cfg)
if err then
vim.notify('failed to get workspace symbol', ctx, vim.lsp.log_levels.WARN)
vim.notify('failed to get workspace symbol' .. vim.inspect(ctx), vim.lsp.log_levels.WARN)
end
if not result or vim.tbl_isempty(result) then
vim.notify('symbol not found for buf', ctx, vim.lsp.log_levels.WARN)
vim.notify('symbol not found for buf' .. vim.inpsect(ctx), vim.lsp.log_levels.WARN)
return
end
log(result[1])
@ -120,8 +120,7 @@ M.workspace_symbol_handler = mk_handler(function(err, result, ctx, cfg)
log(items[1])
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft')
gui.new_list_view({items = items, prompt = true, ft = ft, rowdata = true, api = ""})
gui.new_list_view({ items = items, prompt = true, ft = ft, rowdata = true, api = '' })
end)
return M

Loading…
Cancel
Save