forked from Archives/navigator.lua
Merge branch 'master' into neovim_0.6
commit
251bb84471
@ -0,0 +1,3 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: ray-x
|
@ -1,4 +1,4 @@
|
||||
function! folding#foldexpr()
|
||||
function! folding#ngfoldexpr()
|
||||
" return luaeval(printf('require"navigator.foldinglsp".get_fold_indic(%d)', v:lnum))
|
||||
return luaeval(printf('require"navigator.foldts".get_fold_indic(%d)', v:lnum))
|
||||
endfunction
|
||||
|
@ -0,0 +1,4 @@
|
||||
autocmd BufRead,BufNewFile *.tf,*.tfvars set filetype=terraform
|
||||
autocmd BufRead,BufNewFile *.tfstate,*.tfstate.backup set filetype=json
|
||||
autocmd BufRead,BufNewFile *.hcl set filetype=hcl
|
||||
autocmd BufRead,BufNewFile .terraformrc,terraform.rc set filetype=hcl
|
@ -0,0 +1,177 @@
|
||||
local type_to_lspkind = { c = 5, m = 7, f = 6, s = 5 }
|
||||
local util = require('navigator.util')
|
||||
local log = util.log
|
||||
local sep = util.path_sep()
|
||||
local vfn = vim.fn
|
||||
local cur_dir = vfn.getcwd()
|
||||
|
||||
-- convert ctags line to lsp entry
|
||||
local function entry_to_item(entry)
|
||||
local item = {}
|
||||
item.name, item.filename, item.line, item.remain = string.match(entry, '(.*)\t(.*)\t(%d+);(.*)')
|
||||
local type = 'combine'
|
||||
item.remain = item.remain or ''
|
||||
if item.remain:sub(1, 1) == [["]] then
|
||||
type = 'number'
|
||||
end
|
||||
if item.name == nil or item.filename == nil then
|
||||
return
|
||||
end
|
||||
|
||||
if type == 'combine' then
|
||||
-- '/^type ServerResponse struct {$/;"\ts\tpackage:client'
|
||||
item.inline, item.type, item.containerName, item.ref = string.match(item.remain, '/^(.*)$/;"\t(%a)\t(.+)')
|
||||
else
|
||||
-- '"\tm\tstruct:store.Customer\ttyperef:typename:string'
|
||||
item.type, item.containerName, item.ref = string.match(item.remain, '"\t(%a)\t(.+)')
|
||||
end
|
||||
item.kind = type_to_lspkind[item.type] or 13
|
||||
item.lnum = tonumber(item.line) - 1
|
||||
item.location = {
|
||||
uri = 'file://' .. cur_dir .. sep .. item.filename,
|
||||
range = {
|
||||
start = { line = item.lnum, character = 0 },
|
||||
['end'] = { line = item.lnum, character = 0 },
|
||||
},
|
||||
}
|
||||
|
||||
item.uri = 'file://' .. cur_dir .. sep .. item.filename
|
||||
item.range = {
|
||||
start = { line = item.lnum, character = 0 },
|
||||
['end'] = { line = item.lnum, character = 0 },
|
||||
}
|
||||
|
||||
-- item.detail = (item.containerName or '') .. (item.ref or '')
|
||||
-- item.text = '[' .. kind .. ']' .. item.name .. ' ' .. item.detail
|
||||
|
||||
if item.lnum == nil then
|
||||
vim.notify('incorrect ctags format, need run ctag with "-excmd=number|combine" option')
|
||||
end
|
||||
item.remain = nil
|
||||
return item
|
||||
end
|
||||
|
||||
local function ctags_gen()
|
||||
local cmd = 'ctags' -- -x -n -u -f - ' .. vfn.expand('%:p')
|
||||
local output = _NgConfigValues.ctags.tagfile
|
||||
-- rm file first
|
||||
util.rm_file(output)
|
||||
local options = '-R --exclude=.git --exclude=node_modules --exclude=test --exclude=vendor --excmd=number '
|
||||
if _NgConfigValues.ctags then
|
||||
cmd = _NgConfigValues.ctags.cmd
|
||||
options = _NgConfigValues.ctags.options or options
|
||||
end
|
||||
|
||||
local lang = vim.o.ft
|
||||
options = options .. '--language=' .. lang
|
||||
cmd = cmd .. ' ' .. options
|
||||
cmd = string.format('%s -f %s %s --language=%s', cmd, output, options, lang)
|
||||
cmd = vim.split(cmd, ' ')
|
||||
log(cmd)
|
||||
vfn.jobstart(cmd, {
|
||||
on_stdout = function(_, _, _)
|
||||
vim.notify('ctags completed')
|
||||
end,
|
||||
|
||||
on_exit = function(_, data, _) -- id, data, event
|
||||
-- log(vim.inspect(data) .. "exit")
|
||||
if data and data ~= 0 then
|
||||
return vim.notify(cmd .. ' failed ' .. tostring(data), vim.lsp.log_levels.ERROR)
|
||||
else
|
||||
vim.notify('ctags generated')
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local symbols_to_items = require('navigator.lspwrapper').symbols_to_items
|
||||
local function ctags_symbols()
|
||||
local height = _NgConfigValues.height or 0.4
|
||||
local width = _NgConfigValues.width or 0.7
|
||||
height = math.floor(height * vfn.winheight('%'))
|
||||
width = math.floor(width * vfn.winwidth('%'))
|
||||
local items = {}
|
||||
local ctags_file = _NgConfigValues.ctags.tagfile
|
||||
if not util.file_exists(ctags_file) then
|
||||
ctags_gen()
|
||||
vim.cmd('sleep 200m')
|
||||
end
|
||||
local cnts = util.io_read(ctags_file)
|
||||
if cnts == nil then
|
||||
return vim.notify('ctags file ' .. ctags_file .. ' not found')
|
||||
end
|
||||
cnts = vfn.split(cnts, '\n')
|
||||
for _, value in pairs(cnts) do
|
||||
local it = entry_to_item(value)
|
||||
if it then
|
||||
table.insert(items, it)
|
||||
end
|
||||
end
|
||||
cnts = nil
|
||||
|
||||
local ft = vim.o.ft
|
||||
local result = symbols_to_items(items)
|
||||
if next(result) == nil then
|
||||
return vim.notify('no symbols found')
|
||||
end
|
||||
log(result[1])
|
||||
local opt = {
|
||||
api = ' ',
|
||||
ft = ft,
|
||||
bg = 'GHListDark',
|
||||
data = result,
|
||||
items = result,
|
||||
enter = true,
|
||||
loc = 'top_center',
|
||||
transparency = 50,
|
||||
prompt = true,
|
||||
rawdata = true,
|
||||
rect = { height = height, pos_x = 0, pos_y = 0, width = width },
|
||||
}
|
||||
|
||||
require('navigator.gui').new_list_view(opt)
|
||||
end
|
||||
|
||||
-- gen_ctags()
|
||||
|
||||
local function ctags(...)
|
||||
local gen = select(1, ...)
|
||||
log(gen)
|
||||
if gen == '-g' then
|
||||
ctags_gen()
|
||||
vim.cmd('sleep 200m')
|
||||
ctags_symbols()
|
||||
else
|
||||
ctags_symbols()
|
||||
end
|
||||
end
|
||||
|
||||
local function testitem()
|
||||
local e = [[ServerResponse internal/clients/server.go /^type ServerResponse struct {$/;" s package:client]]
|
||||
local ecombine = [[ServerResponse internal/clients/server.go 5;/^type ServerResponse struct {$/;" s package:client]]
|
||||
local enumber = [[CustomerID internal/store/models.go 17;" m struct:store.Customer typeref:typename:string]]
|
||||
local enumber2 = [[CustomerDescription internal/controllers/customer.go 27;" c package:controllers]]
|
||||
local enumber3 = [[add_servers lua/navigator/lspclient/clients.lua 680;" f]]
|
||||
local i = entry_to_item(ecombine)
|
||||
print(vim.inspect(i))
|
||||
|
||||
i = entry_to_item(enumber)
|
||||
print(vim.inspect(i))
|
||||
|
||||
i = entry_to_item(enumber2)
|
||||
print(vim.inspect(i))
|
||||
|
||||
i = entry_to_item(enumber3)
|
||||
print(vim.inspect(i))
|
||||
i = entry_to_item(e)
|
||||
print(vim.inspect(i))
|
||||
end
|
||||
-- testitem()
|
||||
-- gen_ctags()
|
||||
-- ctags_symbols()
|
||||
|
||||
return {
|
||||
ctags_gen = ctags_gen,
|
||||
ctags = ctags,
|
||||
ctags_symbols = ctags_symbols,
|
||||
}
|
@ -1,102 +1,311 @@
|
||||
local gui = require "navigator.gui"
|
||||
local util = require "navigator.util"
|
||||
local gui = require('navigator.gui')
|
||||
local util = require('navigator.util')
|
||||
local log = util.log
|
||||
local trace = util.trace
|
||||
local partial = util.partial
|
||||
local lsphelper = require "navigator.lspwrapper"
|
||||
local lsphelper = require('navigator.lspwrapper')
|
||||
|
||||
local path_sep = require"navigator.util".path_sep()
|
||||
local path_cur = require"navigator.util".path_cur()
|
||||
local path_sep = require('navigator.util').path_sep()
|
||||
local path_cur = require('navigator.util').path_cur()
|
||||
local cwd = vim.loop.cwd()
|
||||
local in_method = 'callHierarchy/incomingCalls'
|
||||
local out_method = 'callHierarchy/outgoingCalls'
|
||||
|
||||
local lsp_method = { to = out_method, from = in_method }
|
||||
local panel_method = { to = out_method, from = in_method }
|
||||
|
||||
local M = {}
|
||||
local function call_hierarchy_handler(direction, err, result, ctx, cfg, error_message)
|
||||
local outgoing_calls_handler
|
||||
local incoming_calls_handler
|
||||
local hierarchy_handler
|
||||
|
||||
local call_hierarchy
|
||||
|
||||
local function pick_call_hierarchy_item(call_hierarchy_items)
|
||||
if not call_hierarchy_items then
|
||||
return
|
||||
end
|
||||
if #call_hierarchy_items == 1 then
|
||||
return call_hierarchy_items[1]
|
||||
end
|
||||
local items = {}
|
||||
for i, item in pairs(call_hierarchy_items) do
|
||||
local entry = item.detail or item.name
|
||||
table.insert(items, string.format('%d. %s', i, entry))
|
||||
end
|
||||
local choice = vim.fn.inputlist(items)
|
||||
if choice < 1 or choice > #items then
|
||||
return
|
||||
end
|
||||
return choice
|
||||
end
|
||||
|
||||
-- convert lsp result to navigator items
|
||||
local function call_hierarchy_result_procesor(direction, err, result, ctx, config)
|
||||
math.randomseed(os.clock() * 100000000000)
|
||||
trace(direction, err, ctx, config)
|
||||
trace(result)
|
||||
if not result then
|
||||
vim.notify ("No call hierarchy items found", vim.lsp.log_levels.WARN)
|
||||
vim.notify('No call hierarchy items found', vim.lsp.log_levels.WARN)
|
||||
return
|
||||
end
|
||||
trace('call_hierarchy', result)
|
||||
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
|
||||
-- trace('call_hierarchy', result)
|
||||
|
||||
local bufnr = ctx.bufnr or vim.api.nvim_get_current_buf()
|
||||
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use call hierarchy')
|
||||
if err ~= nil then
|
||||
log("dir", direction, "result", result, "err", err, ctx)
|
||||
vim.notify("ERROR: " .. error_message, vim.lsp.log_levels.WARN)
|
||||
log('dir', direction, 'result', result, 'err', err, ctx)
|
||||
vim.notify('ERROR: ' .. err, vim.lsp.log_levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local items = {}
|
||||
local items = ctx.items or {}
|
||||
|
||||
for _, call_hierarchy_call in pairs(result) do
|
||||
local call_hierarchy_item = call_hierarchy_call[direction]
|
||||
local kind = ' '
|
||||
for _, call_hierarchy_result in pairs(result) do
|
||||
local call_hierarchy_item = call_hierarchy_result[direction]
|
||||
if call_hierarchy_item.kind then
|
||||
kind = require'navigator.lspclient.lspkind'.symbol_kind(call_hierarchy_item.kind) .. ' '
|
||||
kind = require('navigator.lspclient.lspkind').symbol_kind(call_hierarchy_item.kind) .. ' '
|
||||
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)
|
||||
call_hierarchy_item.detail = call_hierarchy_item.detail or ''
|
||||
call_hierarchy_item.detail = string.gsub(call_hierarchy_item.detail, '\n', ' ↳ ')
|
||||
trace(call_hierarchy_item)
|
||||
|
||||
local disp_item = {
|
||||
uri = call_hierarchy_item.uri,
|
||||
local disp_item = vim.tbl_deep_extend('force', {}, call_hierarchy_item)
|
||||
disp_item = vim.tbl_deep_extend('force', disp_item, {
|
||||
filename = filename,
|
||||
display_filename = display_filename,
|
||||
indent_level = ctx.depth or 1,
|
||||
method = lsp_method[direction],
|
||||
node_text = call_hierarchy_item.name,
|
||||
type = kind,
|
||||
id = math.random(1, 100000),
|
||||
text = kind .. call_hierarchy_item.name .. ' ﰲ ' .. call_hierarchy_item.detail,
|
||||
range = range,
|
||||
lnum = range.start.line + 1,
|
||||
col = range.start.character
|
||||
}
|
||||
|
||||
lnum = call_hierarchy_item.selectionRange.start.line + 1,
|
||||
col = call_hierarchy_item.selectionRange.start.character,
|
||||
})
|
||||
table.insert(items, disp_item)
|
||||
-- end
|
||||
end
|
||||
trace(items)
|
||||
return items
|
||||
end
|
||||
|
||||
local call_hierarchy_handler_from = partial(call_hierarchy_handler, "from")
|
||||
local call_hierarchy_handler_to = partial(call_hierarchy_handler, "to")
|
||||
local call_hierarchy_handler_from = partial(call_hierarchy_result_procesor, 'from')
|
||||
local call_hierarchy_handler_to = partial(call_hierarchy_result_procesor, 'to')
|
||||
|
||||
-- the handler that deal all lsp request
|
||||
hierarchy_handler = function(dir, handler, show, api, err, result, ctx, cfg)
|
||||
trace(dir, handler, api, show, err, result, ctx, cfg)
|
||||
ctx = ctx or {} -- can be nil if it is async call
|
||||
cfg = cfg or {}
|
||||
opts = ctx.opts or {}
|
||||
vim.validate({ handler = { handler, 'function' }, show = { show, 'function' }, api = { api, 'string' } })
|
||||
local bufnr = ctx.bufnr or vim.api.nvim_get_current_buf()
|
||||
assert(next(vim.lsp.buf_get_clients(bufnr)), 'Must have a client running to use lsp hierarchy')
|
||||
|
||||
local results = handler(err, result, ctx, cfg, 'Incoming calls not found')
|
||||
|
||||
local ft = vim.api.nvim_buf_get_option(ctx.bufnr or vim.api.nvim_get_current_buf(), 'ft')
|
||||
if ctx.no_show then
|
||||
return results
|
||||
end
|
||||
-- local panel = args.panel
|
||||
-- local items = args.items
|
||||
-- local parent_node = args.node
|
||||
-- local section_id = args.section_id or 1
|
||||
local show_args = {
|
||||
items = results,
|
||||
ft = ft,
|
||||
api = api,
|
||||
bufnr = bufnr,
|
||||
panel = opts.panel,
|
||||
parent_node = opts.parent_node,
|
||||
}
|
||||
local win = show(show_args)
|
||||
return results, win
|
||||
end
|
||||
|
||||
local make_params = function(uri, pos)
|
||||
return {
|
||||
textDocument = {
|
||||
uri = uri,
|
||||
},
|
||||
position = pos,
|
||||
}
|
||||
end
|
||||
|
||||
local function incoming_calls_handler(bang, err, result, ctx, cfg)
|
||||
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp hierarchy")
|
||||
local results = call_hierarchy_handler_from(err, result, ctx, cfg, "Incoming calls not found")
|
||||
local function display_panel(args)
|
||||
-- args = {items=results, ft=ft, api=api}
|
||||
log(args)
|
||||
|
||||
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
|
||||
gui.new_list_view({items = results, ft = ft, api = ' '})
|
||||
local Panel = require('guihua.panel')
|
||||
local bufnr = args.bufnr or vim.api.nvim_get_current_buf()
|
||||
local ft = args.ft or vim.api.nvim_buf_get_option(bufnr, 'buftype')
|
||||
local items = args.items
|
||||
local p = Panel:new({
|
||||
header = args.header or 'Call Hierarchy',
|
||||
render = function(bufnr)
|
||||
return items
|
||||
end,
|
||||
fold = function(panel, node)
|
||||
if node.expanded ~= nil then
|
||||
node.expanded = not node.expanded
|
||||
vim.cmd('normal! za')
|
||||
else
|
||||
expand(panel, node)
|
||||
node.expanded = true
|
||||
end
|
||||
log('fold')
|
||||
return node
|
||||
end,
|
||||
})
|
||||
p:open(true)
|
||||
end
|
||||
|
||||
local function outgoing_calls_handler(bang, err, result, ctx, cfg)
|
||||
local results = call_hierarchy_handler_to(err, result, ctx, cfg, "Outgoing calls not found")
|
||||
local function expand_item(args)
|
||||
-- args = {items=results, ft=ft, api=api}
|
||||
print('dispaly panel')
|
||||
trace(args, args.parent_node)
|
||||
local panel = args.panel
|
||||
local items = args.items
|
||||
local parent_node = args.parent_node
|
||||
local section_id = args.section_id or 1
|
||||
|
||||
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
|
||||
gui.new_list_view({items = results, ft = ft, api = ' '})
|
||||
-- fzf_locations(bang, "", "Outgoing Calls", results, false)
|
||||
local sect
|
||||
local sectid = 1
|
||||
for i, s in pairs(panel.sections) do
|
||||
if s.id == section_id then
|
||||
sectid = i
|
||||
break
|
||||
end
|
||||
end
|
||||
sect = panel.sections[sectid]
|
||||
for i, node in pairs(sect.nodes) do
|
||||
if node.id == parent_node.id then
|
||||
for j in ipairs(items) do
|
||||
items[j].indent_level = parent_node.indent_level + 1
|
||||
table.insert(sect.nodes, i + j, args.items[j])
|
||||
end
|
||||
sect.nodes[i].expanded = true
|
||||
sect.nodes[i].expandable = false
|
||||
break
|
||||
end
|
||||
end
|
||||
trace(panel.sections[sectid])
|
||||
-- render the panel again
|
||||
panel:redraw(false)
|
||||
end
|
||||
|
||||
function M.incoming_calls(bang, opts)
|
||||
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp hierarchy")
|
||||
if not lsphelper.check_capabilities("call_hierarchy") then
|
||||
return
|
||||
incoming_calls_handler = util.partial4(
|
||||
hierarchy_handler,
|
||||
'from',
|
||||
call_hierarchy_handler_from,
|
||||
gui.new_list_view,
|
||||
' '
|
||||
)
|
||||
outgoing_calls_handler = util.partial4(hierarchy_handler, 'to', call_hierarchy_handler_to, gui.new_list_view, ' ')
|
||||
|
||||
local incoming_calls_panel = util.partial4(
|
||||
hierarchy_handler,
|
||||
'from',
|
||||
call_hierarchy_handler_from,
|
||||
display_panel,
|
||||
' '
|
||||
)
|
||||
local outgoing_calls_panel = util.partial4(hierarchy_handler, 'to', call_hierarchy_handler_to, display_panel, ' ')
|
||||
|
||||
local incoming_calls_expand = util.partial4(hierarchy_handler, 'from', call_hierarchy_handler_from, expand_item, ' ')
|
||||
local outgoing_calls_expand = util.partial4(hierarchy_handler, 'to', call_hierarchy_handler_to, expand_item, ' ')
|
||||
|
||||
function expand(panel, node)
|
||||
trace(panel, node)
|
||||
local params = make_params(node.uri, {
|
||||
line = node.range.start.line,
|
||||
character = node.range.start.character,
|
||||
})
|
||||
local handler = incoming_calls_expand
|
||||
if node.api == out_method then
|
||||
handler = outgoing_calls_expand
|
||||
end
|
||||
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
lsphelper.call_sync("callHierarchy/incomingCalls", params, opts, partial(incoming_calls_handler, bang))
|
||||
local bufnr = vim.uri_to_bufnr(node.uri)
|
||||
call_hierarchy(node.method, {
|
||||
params = params,
|
||||
panel = panel,
|
||||
parent_node = node,
|
||||
handler = handler,
|
||||
bufnr = bufnr,
|
||||
})
|
||||
end
|
||||
|
||||
function M.outgoing_calls(bang, opts)
|
||||
assert(#vim.lsp.buf_get_clients() > 0, "Must have a client running to use lsp_tags")
|
||||
if not lsphelper.check_capabilities("call_hierarchy") then
|
||||
local request = vim.lsp.buf_request
|
||||
|
||||
-- call_hierarchy with floating window
|
||||
call_hierarchy = function(method, opts)
|
||||
trace(method, opts)
|
||||
opts = opts or {}
|
||||
local params = opts.params or vim.lsp.util.make_position_params()
|
||||
local bufnr = opts.bufnr
|
||||
local handler = function(err, result, ctx, cfg)
|
||||
ctx.opts = opts
|
||||
return opts.handler(err, result, ctx, cfg)
|
||||
end
|
||||
-- log(opts, params)
|
||||
return request(
|
||||
bufnr,
|
||||
'textDocument/prepareCallHierarchy',
|
||||
params,
|
||||
vim.lsp.with(function(err, result, ctx)
|
||||
if err then
|
||||
vim.notify(err.message, vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
local call_hierarchy_item = pick_call_hierarchy_item(result)
|
||||
local client = vim.lsp.get_client_by_id(ctx.client_id)
|
||||
if client then
|
||||
trace('result', result, 'items', call_hierarchy_item, method, ctx, client.name)
|
||||
client.request(method, {
|
||||
item = call_hierarchy_item,
|
||||
args = {
|
||||
method = method,
|
||||
},
|
||||
}, handler, ctx.bufnr)
|
||||
else
|
||||
vim.notify(string.format('Client with id=%d stopped', ctx.client_id), vim.log.levels.WARN)
|
||||
end
|
||||
end, { direction = method, depth = opts.depth })
|
||||
)
|
||||
end
|
||||
|
||||
function M.incoming_calls(opts)
|
||||
call_hierarchy(in_method, opts)
|
||||
end
|
||||
|
||||
function M.outgoing_calls(opts)
|
||||
call_hierarchy(out_method, opts)
|
||||
end
|
||||
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
lsphelper.call_sync("callHierarchy/outgoingCalls", params, opts, partial(outgoing_calls_handler, bang))
|
||||
function M.incoming_calls_panel(opts)
|
||||
opts = vim.tbl_extend('force', { handler = incoming_calls_panel }, opts or {})
|
||||
call_hierarchy(in_method, opts)
|
||||
end
|
||||
|
||||
M.incoming_calls_call = partial(M.incoming_calls, 0)
|
||||
M.outgoing_calls_call = partial(M.outgoing_calls, 0)
|
||||
function M.outgoing_calls_panel(opts)
|
||||
opts = vim.tbl_extend('force', { handler = outgoing_calls_panel }, opts or {})
|
||||
call_hierarchy(out_method, opts)
|
||||
end
|
||||
|
||||
M.incoming_calls_handler = partial(incoming_calls_handler, 0)
|
||||
M.outgoing_calls_handler = partial(outgoing_calls_handler, 0)
|
||||
M.incoming_calls_handler = incoming_calls_handler
|
||||
M.outgoing_calls_handler = outgoing_calls_handler
|
||||
-- for testing
|
||||
M._call_hierarchy = call_hierarchy
|
||||
|
||||
function M.calltree(args)
|
||||
if args == '-o' then
|
||||
return M.outgoing_calls_panel()
|
||||
end
|
||||
M.incoming_calls_panel()
|
||||
end
|
||||
return M
|
||||
|
@ -0,0 +1,61 @@
|
||||
vim.cmd([[set runtimepath=$VIMRUNTIME]])
|
||||
vim.cmd([[set packpath=/tmp/nvim/site]])
|
||||
|
||||
local package_root = '/tmp/nvim/site/pack'
|
||||
local install_path = package_root .. '/packer/start/packer.nvim'
|
||||
vim.g.coq_settings = {
|
||||
['auto_start'] = 'shut-up',
|
||||
}
|
||||
|
||||
local function load_plugins()
|
||||
require('packer').startup({
|
||||
function(use)
|
||||
use('wbthomason/packer.nvim')
|
||||
use('neovim/nvim-lspconfig')
|
||||
use({
|
||||
'williamboman/nvim-lsp-installer',
|
||||
config = function()
|
||||
local lsp_installer = require('nvim-lsp-installer')
|
||||
lsp_installer.setup{}
|
||||
end,
|
||||
})
|
||||
use({
|
||||
'ray-x/navigator.lua',
|
||||
config = function()
|
||||
require('navigator').setup({
|
||||
debug = true,
|
||||
lsp_installer = true,
|
||||
keymaps = { { key = 'gR', func = "require('navigator.reference').async_ref()" } },
|
||||
})
|
||||
end,
|
||||
})
|
||||
use('ray-x/guihua.lua')
|
||||
-- -- COQ (Autocompletion)
|
||||
use('ms-jpq/coq_nvim')
|
||||
use('ms-jpq/coq.artifacts')
|
||||
use('ms-jpq/coq.thirdparty')
|
||||
use('ray-x/aurora')
|
||||
end,
|
||||
config = {
|
||||
package_root = package_root,
|
||||
compile_path = install_path .. '/plugin/packer_compiled.lua',
|
||||
},
|
||||
})
|
||||
-- navigator/LSP setup
|
||||
end
|
||||
|
||||
if vim.fn.isdirectory(install_path) == 0 then
|
||||
print('install packer')
|
||||
vim.fn.system({
|
||||
'git',
|
||||
'clone',
|
||||
'https://github.com/wbthomason/packer.nvim',
|
||||
install_path,
|
||||
})
|
||||
load_plugins()
|
||||
require('packer').sync()
|
||||
vim.cmd('colorscheme aurora')
|
||||
else
|
||||
load_plugins()
|
||||
vim.cmd('colorscheme aurora')
|
||||
end
|
@ -0,0 +1,79 @@
|
||||
vim.cmd([[set runtimepath=$VIMRUNTIME]])
|
||||
vim.cmd([[set packpath=/tmp/nvim/site]])
|
||||
|
||||
local package_root = '/tmp/nvim/site/pack'
|
||||
local install_path = package_root .. '/packer/start/packer.nvim'
|
||||
|
||||
local function load_plugins()
|
||||
require('packer').startup({
|
||||
function(use)
|
||||
use('wbthomason/packer.nvim')
|
||||
use('neovim/nvim-lspconfig')
|
||||
use({
|
||||
'williamboman/nvim-lsp-installer',
|
||||
config = function()
|
||||
require('nvim-lsp-installer').setup({})
|
||||
end,
|
||||
})
|
||||
use({
|
||||
'ray-x/navigator.lua',
|
||||
-- '~/github/ray-x/navigator.lua',
|
||||
config = function()
|
||||
require('navigator').setup({
|
||||
debug = true,
|
||||
lsp_installer = true,
|
||||
keymaps = { { key = 'gR', func = "require('navigator.reference').async_ref()" } },
|
||||
})
|
||||
end,
|
||||
})
|
||||
use('ray-x/guihua.lua')
|
||||
|
||||
use({
|
||||
'hrsh7th/nvim-cmp',
|
||||
requires = {
|
||||
'hrsh7th/cmp-nvim-lsp',
|
||||
},
|
||||
config = function()
|
||||
local cmp = require('cmp')
|
||||
cmp.setup({
|
||||
mapping = {
|
||||
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||
['<Tab>'] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.confirm({ select = true })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
},
|
||||
sources = {
|
||||
{ name = 'nvim_lsp' },
|
||||
},
|
||||
})
|
||||
end,
|
||||
})
|
||||
use('ray-x/aurora')
|
||||
end,
|
||||
config = {
|
||||
package_root = package_root,
|
||||
compile_path = install_path .. '/plugin/packer_compiled.lua',
|
||||
},
|
||||
})
|
||||
-- navigator/LSP setup
|
||||
end
|
||||
|
||||
if vim.fn.isdirectory(install_path) == 0 then
|
||||
print('install packer')
|
||||
vim.fn.system({
|
||||
'git',
|
||||
'clone',
|
||||
'https://github.com/wbthomason/packer.nvim',
|
||||
install_path,
|
||||
})
|
||||
load_plugins()
|
||||
require('packer').sync()
|
||||
vim.cmd('colorscheme aurora')
|
||||
else
|
||||
load_plugins()
|
||||
vim.cmd('colorscheme aurora')
|
||||
end
|
@ -0,0 +1,14 @@
|
||||
from random import shuffle
|
||||
a = list(range(5))
|
||||
|
||||
def go(beg, c, b):
|
||||
if beg >= len(a):
|
||||
print(a )
|
||||
for i in range(beg, len(a)):
|
||||
a[beg], a[i] = a[i], a[beg]
|
||||
go(beg + 1)
|
||||
a[beg], a[i] = a[i], a[beg]
|
||||
print(a, b)
|
||||
|
||||
go(0, 1, 4)
|
||||
shuffle([1, 2,3 ])
|
@ -0,0 +1,69 @@
|
||||
local busted = require('plenary/busted')
|
||||
|
||||
local eq = assert.are.same
|
||||
local cur_dir = vim.fn.expand('%:p:h')
|
||||
-- local status = require("plenary.reload").reload_module("go.nvim")
|
||||
-- status = require("plenary.reload").reload_module("nvim-treesitter")
|
||||
|
||||
-- local ulog = require('go.utils').log
|
||||
describe('should run lsp call hierarchy', function()
|
||||
vim.cmd([[packadd navigator.lua]])
|
||||
vim.cmd([[packadd guihua.lua]])
|
||||
local status = require('plenary.reload').reload_module('navigator')
|
||||
status = require('plenary.reload').reload_module('guihua')
|
||||
status = require('plenary.reload').reload_module('lspconfig')
|
||||
|
||||
local path = cur_dir .. '/tests/fixtures/interface.go' -- %:p:h ? %:p
|
||||
local cmd = " silent exe 'e " .. path .. "'"
|
||||
vim.cmd(cmd)
|
||||
vim.cmd([[cd %:p:h]])
|
||||
local bufn = vim.fn.bufnr('')
|
||||
require('navigator').setup({
|
||||
debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
|
||||
width = 0.75, -- max width ratio (number of cols for the floating window) / (window width)
|
||||
height = 0.3, -- max list window height, 0.3 by default
|
||||
preview_height = 0.35, -- max height of preview windows
|
||||
border = 'none',
|
||||
})
|
||||
|
||||
-- allow gopls start
|
||||
for _ = 1, 20 do
|
||||
vim.wait(400, function() end)
|
||||
local found = false
|
||||
for _, client in ipairs(vim.lsp.get_active_clients()) do
|
||||
if client.name == 'gopls' then
|
||||
found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if found then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
it('should show panel', function()
|
||||
vim.fn.setpos('.', { bufn, 24, 15, 0 })
|
||||
require('navigator.hierarchy').incoming_calls_panel()
|
||||
|
||||
vim.wait(300, function() end)
|
||||
|
||||
local panel = require('guihua.panel').debug()
|
||||
eq(panel.name, 'Panel')
|
||||
|
||||
vim.wait(500, function() end)
|
||||
panel = require('guihua.panel').debug()
|
||||
print(vim.inspect(panel))
|
||||
-- eq(
|
||||
-- panel.activePanel.sections[1].header[1],
|
||||
-- '──────────Call Hierarchy──────────'
|
||||
-- )
|
||||
-- eq(panel.activePanel.sections[1].nodes[1].name, 'measure')
|
||||
end)
|
||||
|
||||
it('should show hierarchy', function()
|
||||
vim.fn.setpos('.', { bufn, 24, 15, 0 })
|
||||
local ret = require('navigator.hierarchy')._call_hierarchy()
|
||||
vim.wait(400, function() end)
|
||||
eq(ret, {})
|
||||
end)
|
||||
end)
|
@ -0,0 +1,217 @@
|
||||
local golden_result = {
|
||||
{
|
||||
col = 9,
|
||||
display_filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
full_text = 'package main',
|
||||
kind = '🚀',
|
||||
lnum = 1,
|
||||
node_scope = {
|
||||
['end'] = {
|
||||
character = 0,
|
||||
line = 12,
|
||||
},
|
||||
start = {
|
||||
character = 0,
|
||||
line = 0,
|
||||
},
|
||||
},
|
||||
node_text = 'main',
|
||||
indent = '',
|
||||
range = {
|
||||
['end'] = {
|
||||
character = 12,
|
||||
line = 0,
|
||||
},
|
||||
start = {
|
||||
character = 8,
|
||||
line = 0,
|
||||
},
|
||||
},
|
||||
text = ' 🚀 main \t package main',
|
||||
type = 'namespace',
|
||||
uri = 'file:///tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
},
|
||||
{
|
||||
col = 6,
|
||||
display_filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
full_text = 'func interfaceTest()',
|
||||
kind = ' ',
|
||||
lnum = 5,
|
||||
indent = '',
|
||||
node_scope = {
|
||||
['end'] = {
|
||||
character = 1,
|
||||
line = 11,
|
||||
},
|
||||
start = {
|
||||
character = 0,
|
||||
line = 4,
|
||||
},
|
||||
},
|
||||
node_text = 'interfaceTest',
|
||||
range = {
|
||||
['end'] = {
|
||||
character = 18,
|
||||
line = 4,
|
||||
},
|
||||
start = {
|
||||
character = 5,
|
||||
line = 4,
|
||||
},
|
||||
},
|
||||
text = ' interfaceTest\t func interfaceTest()',
|
||||
type = 'function',
|
||||
uri = 'file:///tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
},
|
||||
{
|
||||
col = 2,
|
||||
display_filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
full_text = 'r := rect{width: 3, height: 4}',
|
||||
kind = ' ',
|
||||
lnum = 6,
|
||||
node_scope = {
|
||||
['end'] = {
|
||||
character = 1,
|
||||
line = 11,
|
||||
},
|
||||
start = {
|
||||
character = 21,
|
||||
line = 4,
|
||||
},
|
||||
},
|
||||
|
||||
indent = ' ',
|
||||
node_text = 'r',
|
||||
range = {
|
||||
['end'] = {
|
||||
character = 2,
|
||||
line = 5,
|
||||
},
|
||||
start = {
|
||||
character = 1,
|
||||
line = 5,
|
||||
},
|
||||
},
|
||||
text = ' r \t r := rect{width: 3, height: 4}',
|
||||
type = 'var',
|
||||
uri = 'file:///tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
},
|
||||
{
|
||||
col = 2,
|
||||
display_filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
full_text = 'c := circle{radius: 5}',
|
||||
kind = ' ',
|
||||
lnum = 7,
|
||||
node_scope = {
|
||||
['end'] = {
|
||||
character = 1,
|
||||
line = 11,
|
||||
},
|
||||
start = {
|
||||
character = 21,
|
||||
line = 4,
|
||||
},
|
||||
},
|
||||
node_text = 'c',
|
||||
indent = ' ',
|
||||
range = {
|
||||
['end'] = {
|
||||
character = 2,
|
||||
line = 6,
|
||||
},
|
||||
start = {
|
||||
character = 1,
|
||||
line = 6,
|
||||
},
|
||||
},
|
||||
text = ' c \t c := circle{radius: 5}',
|
||||
type = 'var',
|
||||
uri = 'file:///tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
},
|
||||
{
|
||||
col = 2,
|
||||
display_filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
filename = '/tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
full_text = 'd := circle{radius: 10}',
|
||||
kind = ' ',
|
||||
lnum = 10,
|
||||
indent = ' ',
|
||||
node_scope = {
|
||||
['end'] = {
|
||||
character = 1,
|
||||
line = 11,
|
||||
},
|
||||
start = {
|
||||
character = 21,
|
||||
line = 4,
|
||||
},
|
||||
},
|
||||
node_text = 'd',
|
||||
range = {
|
||||
['end'] = {
|
||||
character = 2,
|
||||
line = 9,
|
||||
},
|
||||
start = {
|
||||
character = 1,
|
||||
line = 9,
|
||||
},
|
||||
},
|
||||
text = ' d \t d := circle{radius: 10}',
|
||||
type = 'var',
|
||||
uri = 'file:///tmp/github/ray-x/navigator.lua/tests/fixtures/interface_test.go',
|
||||
},
|
||||
}
|
||||
|
||||
print(golden_result[1].node_text)
|
||||
|
||||
local busted = require('plenary/busted')
|
||||
|
||||
local eq = assert.are.same
|
||||
local cur_dir = vim.fn.expand('%:p:h')
|
||||
-- local status = require("plenary.reload").reload_module("go.nvim")
|
||||
-- status = require("plenary.reload").reload_module("nvim-treesitter")
|
||||
|
||||
-- local ulog = require('go.utils').log
|
||||
describe('should run lsp reference', function()
|
||||
-- vim.fn.readfile('minimal.vim')
|
||||
it('should show ts nodes', function()
|
||||
local status = require('plenary.reload').reload_module('navigator')
|
||||
local status = require('plenary.reload').reload_module('guihua')
|
||||
local status = require('plenary.reload').reload_module('lspconfig')
|
||||
|
||||
vim.cmd([[packadd nvim-lspconfig]])
|
||||
vim.cmd([[packadd navigator.lua]])
|
||||
vim.cmd([[packadd guihua.lua]])
|
||||
local path = cur_dir .. '/tests/fixtures/interface_test.go' -- %:p:h ? %:p
|
||||
local cmd = " silent exe 'e " .. path .. "'"
|
||||
vim.cmd(cmd)
|
||||
vim.cmd([[cd %:p:h]])
|
||||
local bufn = vim.fn.bufnr('')
|
||||
-- require'lspconfig'.gopls.setup {}
|
||||
require('navigator').setup({
|
||||
debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
|
||||
})
|
||||
|
||||
-- allow gopls start
|
||||
for i = 1, 10 do
|
||||
vim.wait(400, function() end)
|
||||
local clients = vim.lsp.get_active_clients()
|
||||
print('lsp clients: ', #clients)
|
||||
if #clients > 0 then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
vim.fn.setpos('.', { bufn, 15, 4, 0 }) -- width
|
||||
|
||||
vim.bo.filetype = 'go'
|
||||
local view, items, w = require('navigator.treesitter').buf_ts()
|
||||
eq(items[1].node_text, golden_result[1].node_text)
|
||||
eq(items[2].node_text, golden_result[2].node_text)
|
||||
end)
|
||||
end)
|
Loading…
Reference in New Issue