bug fix #91 outgoing_calls failure for pyright

neovim_0.6
ray-x 3 years ago
parent 36c01adc2d
commit d6b81ba8ab

@ -132,10 +132,10 @@ function M.new_list_view(opts)
width = math.floor(wwidth * config.width)
end
width = math.min(120, width, opts.width or 120)
local wheight = math.floor(1 + api.nvim_get_option("lines")
* (_NgConfigValues.height + _NgConfigValues.preview_height))
local pheight = math.max(_NgConfigValues.preview_lines, math.floor(
api.nvim_get_option("lines") * _NgConfigValues.preview_height))
local wheight = math.floor(
1 + api.nvim_get_option("lines") * (_NgConfigValues.height + _NgConfigValues.preview_height))
local pheight = math.max(_NgConfigValues.preview_lines,
math.floor(api.nvim_get_option("lines") * _NgConfigValues.preview_height))
local prompt = opts.prompt or false
if opts.rawdata then
data = items

@ -9,7 +9,6 @@ local path_sep = require"navigator.util".path_sep()
local path_cur = require"navigator.util".path_cur()
local cwd = vim.loop.cwd()
local M = {}
local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_message)
trace('call_hierarchy', result)
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
@ -27,21 +26,26 @@ local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_me
if call_hierarchy_item.kind then
kind = require'navigator.lspclient.lspkind'.symbol_kind(call_hierarchy_item.kind) .. ' '
end
for _, range in pairs(call_hierarchy_call.fromRanges) do
local filename = assert(vim.uri_to_fname(call_hierarchy_item.uri))
local display_filename = filename:gsub(cwd .. path_sep, path_cur, 1)
call_hierarchy_item.detail = call_hierarchy_item.detail:gsub("\n", "")
table.insert(items, {
uri = call_hierarchy_item.uri,
filename = filename,
display_filename = display_filename,
text = kind .. call_hierarchy_item.name .. '' .. call_hierarchy_item.detail,
range = range,
lnum = range.start.line,
col = range.start.character
})
end
-- for _, range in pairs(call_hierarchy_call.fromRanges) do
range = call_hierarchy_item.range or call_hierarchy_item.selectionRange
local filename = assert(vim.uri_to_fname(call_hierarchy_item.uri))
local display_filename = filename:gsub(cwd .. path_sep, path_cur, 1)
call_hierarchy_item.detail = call_hierarchy_item.detail or ""
call_hierarchy_item.detail = call_hierarchy_item.detail:gsub("\n", "")
trace(range, call_hierarchy_item)
local disp_item = {
uri = call_hierarchy_item.uri,
filename = filename,
display_filename = display_filename,
text = kind .. call_hierarchy_item.name .. '' .. call_hierarchy_item.detail,
range = range,
lnum = range.start.line + 1,
col = range.start.character
}
table.insert(items, disp_item)
-- end
end
return items
end
@ -72,8 +76,7 @@ function M.incoming_calls(bang, opts)
end
local params = vim.lsp.util.make_position_params()
lsphelper.call_sync("callHierarchy/incomingCalls", params, opts,
partial(incoming_calls_handler, bang))
lsphelper.call_sync("callHierarchy/incomingCalls", params, opts, partial(incoming_calls_handler, bang))
end
function M.outgoing_calls(bang, opts)
@ -83,8 +86,7 @@ function M.outgoing_calls(bang, opts)
end
local params = vim.lsp.util.make_position_params()
lsphelper.call_sync("callHierarchy/outgoingCalls", params, opts,
partial(outgoing_calls_handler, bang))
lsphelper.call_sync("callHierarchy/outgoingCalls", params, opts, partial(outgoing_calls_handler, bang))
end
M.incoming_calls_call = partial(M.incoming_calls, 0)

@ -158,8 +158,9 @@ local function set_mapping(user_opts)
del_keymap('n', fmtkey)
end
if user_opts.cap.document_range_formatting then
log(user_opts.cap)
log("formatting enabled", user_opts.cap)
end
if not range_fmt then
del_keymap("v", rfmtkey)
end

@ -8,6 +8,7 @@ local ok, ts_locals = pcall(require, "nvim-treesitter.locals")
if not ok then
error("treesitter not installed")
return nil
end
local parsers = require "nvim-treesitter.parsers"
@ -84,8 +85,7 @@ function M.find_definition(range, bufnr)
if not root then
return
end
local node_at_point = root:named_descendant_for_range(symbolpos[1], symbolpos[2], symbolpos[1],
symbolpos[2])
local node_at_point = root:named_descendant_for_range(symbolpos[1], symbolpos[2], symbolpos[1], symbolpos[2])
if not node_at_point then
lerr("no node at cursor")
return
@ -103,8 +103,7 @@ function M.find_definition(range, bufnr)
local r, c = definition:range()
return {start = {line = r, character = c}}
else
trace("error: def not found in ", bufnr, definition:range(), definition:type(),
definition:parent():type())
trace("error: def not found in ", bufnr, definition:range(), definition:type(), definition:parent():type())
end
end
@ -184,8 +183,7 @@ local function get_scope(type, source)
end
if type == "var" and next ~= nil then
if next:type() == "function" or next:type() == "arrow_function" or next:type()
== "function_definition" then
if next:type() == "function" or next:type() == "arrow_function" or next:type() == "function_definition" then
trace(current:type(), current:range())
return next, true
elseif parent:type() == 'function_declaration' then
@ -371,8 +369,7 @@ local function get_all_nodes(bufnr, filter, summary)
if is_func then
-- hack for lua and maybe other language aswell
local parent = tsdata:parent()
if parent ~= nil and parent:type() == 'function_name' or parent:type()
== 'function_name_field' then
if parent ~= nil and parent:type() == 'function_name' or parent:type() == 'function_name_field' then
item.node_text = ts_utils.get_node_text(parent, bufnr)[1]
log(parent:type(), item.node_text)
end
@ -403,8 +400,7 @@ local function get_all_nodes(bufnr, filter, summary)
if item.node_text == "_" then
goto continue
end
item.full_text = vim.trim(api.nvim_buf_get_lines(bufnr, start_line_node, start_line_node + 1,
false)[1] or "")
item.full_text = vim.trim(api.nvim_buf_get_lines(bufnr, start_line_node, start_line_node + 1, false)[1] or "")
item.full_text = item.full_text:gsub('%s*[%[%(%{]*%s*$', '')
item.uri = uri
@ -419,8 +415,7 @@ local function get_all_nodes(bufnr, filter, summary)
indent = string.rep(" ", #parents - 1) .. ""
end
item.text = string.format(" %s %s%-10s\t %s", item.kind, indent, item.node_text,
item.full_text)
item.text = string.format(" %s %s%-10s\t %s", item.kind, indent, item.node_text, item.full_text)
if #item.text > length then
length = #item.text
end
@ -580,4 +575,34 @@ function M.get_node_at_line(lnum)
return node
end
local usage_namespace = vim.api.nvim_create_namespace("nvim-treesitter-usages")
function M.highlight_usages(bufnr)
M.clear_usage_highlights(bufnr)
local node_at_point = ts_utils.get_node_at_cursor()
local references = locals.get_references(bufnr)
if not node_at_point or not vim.tbl_contains(references, node_at_point) then
return
end
local def_node, scope = locals.find_definition(node_at_point, bufnr)
local usages = locals.find_usages(def_node, scope, bufnr)
for _, usage_node in ipairs(usages) do
if usage_node ~= node_at_point then
ts_utils.highlight_node(usage_node, bufnr, usage_namespace, "TSDefinitionUsage")
end
end
if def_node ~= node_at_point then
ts_utils.highlight_node(def_node, bufnr, usage_namespace, "TSDefinition")
end
end
function M.clear_usage_highlights(bufnr)
api.nvim_buf_clear_namespace(bufnr, usage_namespace, 0, -1)
end
return M

Loading…
Cancel
Save