Skip to content

Commit d6b81ba

Browse files
committed
bug fix #91 outgoing_calls failure for pyright
1 parent 36c01ad commit d6b81ba

File tree

4 files changed

+65
-37
lines changed

4 files changed

+65
-37
lines changed

lua/navigator/gui.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ function M.new_list_view(opts)
132132
width = math.floor(wwidth * config.width)
133133
end
134134
width = math.min(120, width, opts.width or 120)
135-
local wheight = math.floor(1 + api.nvim_get_option("lines")
136-
* (_NgConfigValues.height + _NgConfigValues.preview_height))
137-
local pheight = math.max(_NgConfigValues.preview_lines, math.floor(
138-
api.nvim_get_option("lines") * _NgConfigValues.preview_height))
135+
local wheight = math.floor(
136+
1 + api.nvim_get_option("lines") * (_NgConfigValues.height + _NgConfigValues.preview_height))
137+
local pheight = math.max(_NgConfigValues.preview_lines,
138+
math.floor(api.nvim_get_option("lines") * _NgConfigValues.preview_height))
139139
local prompt = opts.prompt or false
140140
if opts.rawdata then
141141
data = items

lua/navigator/hierarchy.lua

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ local path_sep = require"navigator.util".path_sep()
99
local path_cur = require"navigator.util".path_cur()
1010
local cwd = vim.loop.cwd()
1111
local M = {}
12-
1312
local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_message)
1413
trace('call_hierarchy', result)
1514
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
2726
if call_hierarchy_item.kind then
2827
kind = require'navigator.lspclient.lspkind'.symbol_kind(call_hierarchy_item.kind) .. ' '
2928
end
30-
for _, range in pairs(call_hierarchy_call.fromRanges) do
31-
local filename = assert(vim.uri_to_fname(call_hierarchy_item.uri))
32-
local display_filename = filename:gsub(cwd .. path_sep, path_cur, 1)
33-
call_hierarchy_item.detail = call_hierarchy_item.detail:gsub("\n", "")
34-
35-
table.insert(items, {
36-
uri = call_hierarchy_item.uri,
37-
filename = filename,
38-
display_filename = display_filename,
39-
text = kind .. call_hierarchy_item.name .. '' .. call_hierarchy_item.detail,
40-
range = range,
41-
lnum = range.start.line,
42-
col = range.start.character
43-
})
44-
end
29+
-- for _, range in pairs(call_hierarchy_call.fromRanges) do
30+
range = call_hierarchy_item.range or call_hierarchy_item.selectionRange
31+
local filename = assert(vim.uri_to_fname(call_hierarchy_item.uri))
32+
local display_filename = filename:gsub(cwd .. path_sep, path_cur, 1)
33+
call_hierarchy_item.detail = call_hierarchy_item.detail or ""
34+
call_hierarchy_item.detail = call_hierarchy_item.detail:gsub("\n", "")
35+
trace(range, call_hierarchy_item)
36+
37+
local disp_item = {
38+
uri = call_hierarchy_item.uri,
39+
filename = filename,
40+
display_filename = display_filename,
41+
text = kind .. call_hierarchy_item.name .. '' .. call_hierarchy_item.detail,
42+
range = range,
43+
lnum = range.start.line + 1,
44+
col = range.start.character
45+
}
46+
47+
table.insert(items, disp_item)
48+
-- end
4549
end
4650
return items
4751
end
@@ -72,8 +76,7 @@ function M.incoming_calls(bang, opts)
7276
end
7377

7478
local params = vim.lsp.util.make_position_params()
75-
lsphelper.call_sync("callHierarchy/incomingCalls", params, opts,
76-
partial(incoming_calls_handler, bang))
79+
lsphelper.call_sync("callHierarchy/incomingCalls", params, opts, partial(incoming_calls_handler, bang))
7780
end
7881

7982
function M.outgoing_calls(bang, opts)
@@ -83,8 +86,7 @@ function M.outgoing_calls(bang, opts)
8386
end
8487

8588
local params = vim.lsp.util.make_position_params()
86-
lsphelper.call_sync("callHierarchy/outgoingCalls", params, opts,
87-
partial(outgoing_calls_handler, bang))
89+
lsphelper.call_sync("callHierarchy/outgoingCalls", params, opts, partial(outgoing_calls_handler, bang))
8890
end
8991

9092
M.incoming_calls_call = partial(M.incoming_calls, 0)

lua/navigator/lspclient/mapping.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ local function set_mapping(user_opts)
158158
del_keymap('n', fmtkey)
159159
end
160160
if user_opts.cap.document_range_formatting then
161-
log(user_opts.cap)
161+
log("formatting enabled", user_opts.cap)
162162
end
163+
163164
if not range_fmt then
164165
del_keymap("v", rfmtkey)
165166
end

lua/navigator/treesitter.lua

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local ok, ts_locals = pcall(require, "nvim-treesitter.locals")
88

99
if not ok then
1010
error("treesitter not installed")
11+
return nil
1112
end
1213

1314
local parsers = require "nvim-treesitter.parsers"
@@ -84,8 +85,7 @@ function M.find_definition(range, bufnr)
8485
if not root then
8586
return
8687
end
87-
local node_at_point = root:named_descendant_for_range(symbolpos[1], symbolpos[2], symbolpos[1],
88-
symbolpos[2])
88+
local node_at_point = root:named_descendant_for_range(symbolpos[1], symbolpos[2], symbolpos[1], symbolpos[2])
8989
if not node_at_point then
9090
lerr("no node at cursor")
9191
return
@@ -103,8 +103,7 @@ function M.find_definition(range, bufnr)
103103
local r, c = definition:range()
104104
return {start = {line = r, character = c}}
105105
else
106-
trace("error: def not found in ", bufnr, definition:range(), definition:type(),
107-
definition:parent():type())
106+
trace("error: def not found in ", bufnr, definition:range(), definition:type(), definition:parent():type())
108107
end
109108
end
110109

@@ -184,8 +183,7 @@ local function get_scope(type, source)
184183
end
185184

186185
if type == "var" and next ~= nil then
187-
if next:type() == "function" or next:type() == "arrow_function" or next:type()
188-
== "function_definition" then
186+
if next:type() == "function" or next:type() == "arrow_function" or next:type() == "function_definition" then
189187
trace(current:type(), current:range())
190188
return next, true
191189
elseif parent:type() == 'function_declaration' then
@@ -371,8 +369,7 @@ local function get_all_nodes(bufnr, filter, summary)
371369
if is_func then
372370
-- hack for lua and maybe other language aswell
373371
local parent = tsdata:parent()
374-
if parent ~= nil and parent:type() == 'function_name' or parent:type()
375-
== 'function_name_field' then
372+
if parent ~= nil and parent:type() == 'function_name' or parent:type() == 'function_name_field' then
376373
item.node_text = ts_utils.get_node_text(parent, bufnr)[1]
377374
log(parent:type(), item.node_text)
378375
end
@@ -403,8 +400,7 @@ local function get_all_nodes(bufnr, filter, summary)
403400
if item.node_text == "_" then
404401
goto continue
405402
end
406-
item.full_text = vim.trim(api.nvim_buf_get_lines(bufnr, start_line_node, start_line_node + 1,
407-
false)[1] or "")
403+
item.full_text = vim.trim(api.nvim_buf_get_lines(bufnr, start_line_node, start_line_node + 1, false)[1] or "")
408404

409405
item.full_text = item.full_text:gsub('%s*[%[%(%{]*%s*$', '')
410406
item.uri = uri
@@ -419,8 +415,7 @@ local function get_all_nodes(bufnr, filter, summary)
419415
indent = string.rep(" ", #parents - 1) .. ""
420416
end
421417

422-
item.text = string.format(" %s %s%-10s\t %s", item.kind, indent, item.node_text,
423-
item.full_text)
418+
item.text = string.format(" %s %s%-10s\t %s", item.kind, indent, item.node_text, item.full_text)
424419
if #item.text > length then
425420
length = #item.text
426421
end
@@ -580,4 +575,34 @@ function M.get_node_at_line(lnum)
580575
return node
581576
end
582577

578+
local usage_namespace = vim.api.nvim_create_namespace("nvim-treesitter-usages")
579+
580+
function M.highlight_usages(bufnr)
581+
M.clear_usage_highlights(bufnr)
582+
583+
local node_at_point = ts_utils.get_node_at_cursor()
584+
local references = locals.get_references(bufnr)
585+
586+
if not node_at_point or not vim.tbl_contains(references, node_at_point) then
587+
return
588+
end
589+
590+
local def_node, scope = locals.find_definition(node_at_point, bufnr)
591+
local usages = locals.find_usages(def_node, scope, bufnr)
592+
593+
for _, usage_node in ipairs(usages) do
594+
if usage_node ~= node_at_point then
595+
ts_utils.highlight_node(usage_node, bufnr, usage_namespace, "TSDefinitionUsage")
596+
end
597+
end
598+
599+
if def_node ~= node_at_point then
600+
ts_utils.highlight_node(def_node, bufnr, usage_namespace, "TSDefinition")
601+
end
602+
end
603+
604+
function M.clear_usage_highlights(bufnr)
605+
api.nvim_buf_clear_namespace(bufnr, usage_namespace, 0, -1)
606+
end
607+
583608
return M

0 commit comments

Comments
 (0)