forked from Archives/navigator.lua
Compare commits
171 Commits
neovim_0.7
...
master
Author | SHA1 | Date |
---|---|---|
ray-x | cd98ca2c5b | 2 years ago |
ray-x | 451d761f76 | 2 years ago |
sp4ke | 8278f71878 | 2 years ago |
ray-x | 443fd4d585 | 2 years ago |
ray-x | 10fd76d6d0 | 2 years ago |
ray-x | 8d00282020 | 2 years ago |
ray-x | 9afcd37854 | 2 years ago |
ray-x | c70d032b08 | 2 years ago |
ray-x | fb6d19ddf4 | 2 years ago |
ray-x | af7fc7d649 | 2 years ago |
ray-x | d8f19f6fc1 | 2 years ago |
ray-x | df7f4d7229 | 2 years ago |
ray-x | fb87a0b1b7 | 2 years ago |
ray-x | 927c464b70 | 2 years ago |
ray-x | e9a40aca40 | 2 years ago |
ray-x | edee3e39c6 | 2 years ago |
sp4ke | a7886fc055 | 2 years ago |
yyk | de018d9ae3 | 2 years ago |
ray-x | ef0cee5bbd | 2 years ago |
ray-x | ab2e383b20 | 2 years ago |
ray-x | 1b262556c0 | 2 years ago |
rayx | b4ff1c43b9 | 2 years ago |
ray-x | ebd88f5d09 | 2 years ago |
ray-x | 28d245510f | 2 years ago |
ray-x | 213b30950e | 2 years ago |
ray-x | f05d2ec142 | 2 years ago |
ray-x | 9f151cf718 | 2 years ago |
ray-x | b131251ad8 | 2 years ago |
ray-x | 8978bdb1e3 | 2 years ago |
ray-x | ae251289b3 | 2 years ago |
ray-x | a9c223cc22 | 2 years ago |
ray-x | 0ab4b02ff7 | 2 years ago |
ray-x | 6c0e286170 | 2 years ago |
ray-x | f24a337f5d | 2 years ago |
ray-x | 3d87ed3b87 | 2 years ago |
ray-x | 5713f79265 | 2 years ago |
ray-x | 01ef2ce1a1 | 2 years ago |
ray-x | 547f2bc15d | 2 years ago |
ray-x | dc0b8504bb | 2 years ago |
ray-x | 486085070d | 2 years ago |
ray-x | bc356d555f | 2 years ago |
ray-x | 5b5a946d73 | 2 years ago |
ray-x | fca2fa5aaa | 2 years ago |
rayx | 49dbca889d | 2 years ago |
ray-x | 861ae038dd | 2 years ago |
ray-x | 814b712e91 | 2 years ago |
ray-x | dcc40278c5 | 2 years ago |
ray-x | 6736293182 | 2 years ago |
ray-x | 10ef469286 | 2 years ago |
ray-x | 4775d43218 | 2 years ago |
ray-x | 89dd02c927 | 2 years ago |
ray-x | bbdf86a66e | 2 years ago |
ray-x | ed47d386e6 | 2 years ago |
ray-x | 480824d3f3 | 2 years ago |
ray-x | c3ef990390 | 2 years ago |
ray-x | de5c88c766 | 2 years ago |
ray-x | 348ab9dced | 2 years ago |
ray-x | 967fd32bae | 2 years ago |
ray-x | 4aef8dc5f2 | 2 years ago |
ray-x | 0de6c290cf | 2 years ago |
ray-x | 9aad2978dc | 2 years ago |
ray-x | 49c3e5cd4d | 2 years ago |
ray-x | 47545e03c0 | 2 years ago |
ray-x | e5d16e4488 | 2 years ago |
ray-x | 3d9a9582dd | 2 years ago |
rayx | 05dfed9ed9 | 2 years ago |
ray-x | 05753da8db | 2 years ago |
ray-x | 4623677b2a | 2 years ago |
ray-x | 85e3f6e045 | 2 years ago |
ray-x | c30ccd07c9 | 2 years ago |
ray-x | 4c5d0e67d0 | 2 years ago |
ray-x | be6da35767 | 2 years ago |
ray-x | f567f1b99c | 2 years ago |
ray-x | a93f7cb20f | 2 years ago |
ray-x | 289f67013d | 2 years ago |
ray-x | 56b00b83d5 | 2 years ago |
ray-x | 3fe9a876c4 | 2 years ago |
rayx | acca6009e0 | 2 years ago |
ray-x | 792fd2831a | 2 years ago |
ray-x | a225d18eaf | 2 years ago |
ray-x | 7d84a9f0c0 | 2 years ago |
ray-x | 22e858f261 | 2 years ago |
ray-x | edba3efd1e | 2 years ago |
ray-x | 724d5f3439 | 2 years ago |
ray-x | 3dc8c02c39 | 2 years ago |
ray-x | 91d1366b65 | 2 years ago |
ray-x | d951a5fcd2 | 2 years ago |
ray-x | 68eb18c310 | 2 years ago |
ray-x | 8d77c3ab1e | 2 years ago |
ray-x | 309afcd681 | 2 years ago |
rayx | 9f7bd6ebff | 2 years ago |
ray-x | aba0d89745 | 2 years ago |
ray-x | c1b0694bef | 2 years ago |
ray-x | 9dee73010b | 2 years ago |
ray-x | 1b3a02df3e | 2 years ago |
ray-x | f856fa7033 | 2 years ago |
rayx | 1f6103ed95 | 2 years ago |
ray-x | 7bfd9157fe | 2 years ago |
ray-x | 48e35f4e56 | 2 years ago |
ray-x | 27442d2784 | 2 years ago |
ray-x | 3ad93531b5 | 2 years ago |
ray-x | c15bae89ab | 2 years ago |
ray-x | 61a82559d6 | 2 years ago |
ray-x | f8985d7aa2 | 2 years ago |
ray-x | 516d643ffe | 2 years ago |
ray-x | 6b4cfa3d59 | 2 years ago |
ray-x | cce0e90544 | 2 years ago |
rayx | 2f35446fbe | 2 years ago |
ray-x | 1908ea5175 | 2 years ago |
ray-x | 6c3ee44729 | 2 years ago |
ray-x | 6e937e9019 | 2 years ago |
ray-x | 01801ba8fa | 2 years ago |
ray-x | d0ab595b93 | 2 years ago |
ray-x | 3f49769abc | 2 years ago |
ray-x | 32ddd66dd2 | 2 years ago |
ray-x | feb780fb10 | 2 years ago |
ray-x | ea2c207ec9 | 2 years ago |
ray-x | b249d1680a | 2 years ago |
ray-x | 13c3dd4072 | 2 years ago |
ray-x | a0eff2c5a3 | 2 years ago |
ray-x | 51a05252a5 | 2 years ago |
Michael Adler | 2e96dcd327 | 2 years ago |
Michael Adler | ff4bcc6d83 | 2 years ago |
ray-x | 8a32139e1a | 2 years ago |
rayx | a73fb38ef9 | 2 years ago |
ray-x | 96ca715ea6 | 2 years ago |
ray-x | 45385ccc9a | 2 years ago |
ray-x | 4d93172915 | 2 years ago |
ray-x | 0ac13663cf | 2 years ago |
ray-x | 500553ae6b | 2 years ago |
rayx | c416d99f6f | 2 years ago |
ray-x | d1836f4299 | 2 years ago |
rayx | 5131b30ad7 | 2 years ago |
ray-x | eb75b09a33 | 2 years ago |
ray-x | 93e28f36d0 | 2 years ago |
ray-x | 77b572dd5a | 2 years ago |
rayx | 794e86057d | 2 years ago |
ray-x | 03d0aaa05d | 2 years ago |
ray-x | 9c67158d9c | 2 years ago |
ray-x | 0c31d692ee | 2 years ago |
ray-x | 9ceeb41b6f | 2 years ago |
ray-x | 0bdaf1f63c | 2 years ago |
ray-x | c2c1c57136 | 2 years ago |
0x7a7a | 595263e8b4 | 2 years ago |
ray-x | 2f3e2847a3 | 2 years ago |
ray-x | cd53b02f93 | 2 years ago |
ray-x | 15e6b315b7 | 2 years ago |
ray-x | 31f2f920e1 | 2 years ago |
ray-x | ab4daceede | 2 years ago |
ray-x | 23e25c298e | 2 years ago |
ray-x | 8b43ed23e2 | 2 years ago |
ray-x | 8dbac5efc9 | 2 years ago |
ray-x | d08d78f6a4 | 2 years ago |
ray-x | 3d217bffce | 2 years ago |
ray-x | 2ed33d7d60 | 2 years ago |
ray-x | e55ae08e9d | 2 years ago |
ray-x | d990da84a6 | 2 years ago |
ray-x | bb018d541b | 2 years ago |
ray-x | b69154f9ee | 2 years ago |
ray-x | 5c8b3b9ca1 | 2 years ago |
ray-x | 7f22411b1f | 2 years ago |
ray-x | 77dd031f8a | 2 years ago |
ray-x | d8e4787bfb | 2 years ago |
ray-x | ab96133b47 | 2 years ago |
ray-x | 34c3bc9c76 | 2 years ago |
ray-x | 46aeb778ce | 2 years ago |
studierer | 035917c57a | 2 years ago |
ray-x | a316e7f449 | 2 years ago |
ray-x | 209e5321a8 | 2 years ago |
ray-x | 4018cab16d | 2 years ago |
ray-x | 3e03e37d9f | 2 years ago |
@ -0,0 +1,3 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: ray-x
|
@ -1,3 +1,3 @@
|
||||
|
||||
selene.toml
|
||||
lua/navigator.lua.bak
|
||||
tests/fixtures/tests
|
||||
tests/fixtures/tests
|
||||
|
@ -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(vim.api.nvim_get_option('columns') * width)
|
||||
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 = 'GuihuaListDark',
|
||||
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,312 @@
|
||||
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 = ' '
|
||||
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')
|
||||
|
||||
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")
|
||||
-- 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 {}
|
||||
local 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 ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
|
||||
gui.new_list_view({items = results, ft = ft, api = ' '})
|
||||
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 function outgoing_calls_handler(bang, err, result, ctx, cfg)
|
||||
local results = call_hierarchy_handler_to(err, result, ctx, cfg, "Outgoing calls not found")
|
||||
local make_params = function(uri, pos)
|
||||
return {
|
||||
textDocument = {
|
||||
uri = uri,
|
||||
},
|
||||
position = pos,
|
||||
}
|
||||
end
|
||||
|
||||
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 function display_panel(args)
|
||||
-- args = {items=results, ft=ft, api=api}
|
||||
log(args)
|
||||
|
||||
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(buf)
|
||||
log(buf)
|
||||
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
|
||||
|
||||
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
|
||||
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 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
|
||||
|
||||
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
|
||||
return
|
||||
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
|
||||
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
lsphelper.call_sync("callHierarchy/outgoingCalls", params, opts, partial(outgoing_calls_handler, bang))
|
||||
function M.outgoing_calls(opts)
|
||||
call_hierarchy(out_method, opts)
|
||||
end
|
||||
|
||||
M.incoming_calls_call = partial(M.incoming_calls, 0)
|
||||
M.outgoing_calls_call = partial(M.outgoing_calls, 0)
|
||||
function M.incoming_calls_panel(opts)
|
||||
opts = vim.tbl_extend('force', { handler = incoming_calls_panel }, opts or {})
|
||||
call_hierarchy(in_method, opts)
|
||||
end
|
||||
|
||||
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,191 @@
|
||||
local M = {}
|
||||
local vfn = vim.fn
|
||||
M.defaults = function()
|
||||
local has_lsp, lspconfig = pcall(require, 'lspconfig')
|
||||
local highlight = require('navigator.lspclient.highlight')
|
||||
if not has_lsp then
|
||||
return {
|
||||
setup = function()
|
||||
vim.notify('loading lsp config failed LSP may not working correctly', vim.lsp.log_levels.WARN)
|
||||
end,
|
||||
}
|
||||
end
|
||||
local util = lspconfig.util
|
||||
local on_attach = require('navigator.lspclient.attach').on_attach
|
||||
|
||||
|
||||
local setups = {
|
||||
clojure_lsp = {
|
||||
root_dir = function(fname)
|
||||
return util.root_pattern('deps.edn', 'build.boot', 'project.clj', 'shadow-cljs.edn', 'bb.edn', '.git')(fname)
|
||||
or util.path.dirname(fname)
|
||||
end,
|
||||
on_attach = on_attach,
|
||||
filetypes = { 'clojure', 'edn' },
|
||||
message_level = vim.lsp.protocol.MessageType.error,
|
||||
cmd = { 'clojure-lsp' },
|
||||
},
|
||||
|
||||
elixirls = {
|
||||
on_attach = on_attach,
|
||||
filetypes = { 'elixir', 'eelixir' },
|
||||
cmd = { 'elixir-ls' },
|
||||
message_level = vim.lsp.protocol.MessageType.error,
|
||||
settings = {
|
||||
elixirLS = {
|
||||
dialyzerEnabled = true,
|
||||
fetchDeps = false,
|
||||
},
|
||||
},
|
||||
root_dir = function(fname)
|
||||
return util.root_pattern('mix.exs', '.git')(fname) or util.path.dirname(fname)
|
||||
end,
|
||||
},
|
||||
|
||||
gopls = {
|
||||
on_attach = on_attach,
|
||||
-- capabilities = cap,
|
||||
filetypes = { 'go', 'gomod', 'gohtmltmpl', 'gotexttmpl' },
|
||||
message_level = vim.lsp.protocol.MessageType.Error,
|
||||
cmd = {
|
||||
'gopls', -- share the gopls instance if there is one already
|
||||
'-remote=auto', --[[ debug options ]] --
|
||||
-- "-logfile=auto",
|
||||
-- "-debug=:0",
|
||||
'-remote.debug=:0',
|
||||
-- "-rpc.trace",
|
||||
},
|
||||
|
||||
flags = { allow_incremental_sync = true, debounce_text_changes = 1000 },
|
||||
settings = {
|
||||
gopls = {
|
||||
-- more settings: https://github.com/golang/tools/blob/master/gopls/doc/settings.md
|
||||
-- flags = {allow_incremental_sync = true, debounce_text_changes = 500},
|
||||
-- not supported
|
||||
analyses = { unusedparams = true, unreachable = false },
|
||||
codelenses = {
|
||||
generate = true, -- show the `go generate` lens.
|
||||
gc_details = true, -- // Show a code lens toggling the display of gc's choices.
|
||||
test = true,
|
||||
tidy = true,
|
||||
},
|
||||
usePlaceholders = true,
|
||||
completeUnimported = true,
|
||||
staticcheck = true,
|
||||
matcher = 'fuzzy',
|
||||
diagnosticsDelay = '500ms',
|
||||
experimentalWatchedFileDelay = '1000ms',
|
||||
symbolMatcher = 'fuzzy',
|
||||
gofumpt = false, -- true, -- turn on for new repos, gofmpt is good but also create code turmoils
|
||||
buildFlags = { '-tags', 'integration' },
|
||||
-- buildFlags = {"-tags", "functional"}
|
||||
},
|
||||
},
|
||||
root_dir = function(fname)
|
||||
return util.root_pattern('go.mod', '.git')(fname) or dirname(fname) -- util.path.dirname(fname)
|
||||
end,
|
||||
},
|
||||
clangd = {
|
||||
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
|
||||
cmd = {
|
||||
'clangd',
|
||||
'--background-index',
|
||||
'--suggest-missing-includes',
|
||||
'--clang-tidy',
|
||||
'--header-insertion=iwyu',
|
||||
'--clang-tidy-checks=-*,llvm-*,clang-analyzer-*',
|
||||
'--cross-file-rename',
|
||||
},
|
||||
filetypes = { 'c', 'cpp', 'objc', 'objcpp' },
|
||||
on_attach = function(client, bufnr)
|
||||
client.server_capabilities.documentFormattingProvider = client.server_capabilities.documentFormattingProvider
|
||||
or true
|
||||
on_attach(client, bufnr)
|
||||
end,
|
||||
},
|
||||
rust_analyzer = {
|
||||
root_dir = function(fname)
|
||||
return util.root_pattern('Cargo.toml', 'rust-project.json', '.git')(fname) or util.path.dirname(fname)
|
||||
end,
|
||||
filetypes = { 'rust' },
|
||||
message_level = vim.lsp.protocol.MessageType.error,
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
['rust-analyzer'] = {
|
||||
assist = { importMergeBehavior = 'last', importPrefix = 'by_self' },
|
||||
cargo = { loadOutDirsFromCheck = true },
|
||||
procMacro = { enable = true },
|
||||
},
|
||||
},
|
||||
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
|
||||
},
|
||||
sqls = {
|
||||
filetypes = { 'sql' },
|
||||
on_attach = function(client, _)
|
||||
client.server_capabilities.executeCommandProvider = client.server_capabilities.documentFormattingProvider
|
||||
or true
|
||||
highlight.diagnositc_config_sign()
|
||||
require('sqls').setup({ picker = 'telescope' }) -- or default
|
||||
end,
|
||||
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
|
||||
settings = {
|
||||
cmd = { 'sqls', '-config', '$HOME/.config/sqls/config.yml' },
|
||||
-- alterantively:
|
||||
-- connections = {
|
||||
-- {
|
||||
-- driver = 'postgresql',
|
||||
-- datasourcename = 'host=127.0.0.1 port=5432 user=postgres password=password dbname=user_db sslmode=disable',
|
||||
-- },
|
||||
-- },
|
||||
},
|
||||
},
|
||||
|
||||
pyright = {
|
||||
on_attach = on_attach,
|
||||
cmd = { 'pyright-langserver', '--stdio' },
|
||||
filetypes = { 'python' },
|
||||
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
|
||||
settings = {
|
||||
python = {
|
||||
formatting = { provider = 'black' },
|
||||
analysis = {
|
||||
autoSearchPaths = true,
|
||||
useLibraryCodeForTypes = true,
|
||||
diagnosticMode = 'workspace',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ccls = {
|
||||
on_attach = on_attach,
|
||||
init_options = {
|
||||
compilationDatabaseDirectory = 'build',
|
||||
root_dir = [[ util.root_pattern("compile_commands.json", "compile_flags.txt", "CMakeLists.txt", "Makefile", ".git") or util.path.dirname ]],
|
||||
index = { threads = 2 },
|
||||
clang = { excludeArgs = { '-frounding-math' } },
|
||||
},
|
||||
flags = { allow_incremental_sync = true },
|
||||
},
|
||||
jdtls = {
|
||||
settings = {
|
||||
java = { signatureHelp = { enabled = true }, contentProvider = { preferred = 'fernflower' } },
|
||||
},
|
||||
},
|
||||
omnisharp = {
|
||||
cmd = { 'omnisharp', '--languageserver', '--hostPID', tostring(vfn.getpid()) },
|
||||
},
|
||||
terraformls = {
|
||||
filetypes = { 'terraform', 'tf' },
|
||||
},
|
||||
|
||||
sourcekit = {
|
||||
cmd = { 'sourcekit-lsp' },
|
||||
filetypes = { 'swift' }, -- This is recommended if you have separate settings for clangd.
|
||||
},
|
||||
}
|
||||
|
||||
setups.sumneko_lua = require('navigator.lspclient.sumneko_lua').sumneko_lua()
|
||||
return setups
|
||||
end
|
||||
|
||||
return M
|
@ -0,0 +1,47 @@
|
||||
return {
|
||||
'angularls',
|
||||
'gopls',
|
||||
'tsserver',
|
||||
'flow',
|
||||
'bashls',
|
||||
'dockerls',
|
||||
'julials',
|
||||
'pylsp',
|
||||
'pyright',
|
||||
'jedi_language_server',
|
||||
'jdtls',
|
||||
'sumneko_lua',
|
||||
'vimls',
|
||||
'html',
|
||||
'jsonls',
|
||||
'solargraph',
|
||||
'cssls',
|
||||
'yamlls',
|
||||
'clangd',
|
||||
'ccls',
|
||||
'sqls',
|
||||
'denols',
|
||||
'graphql',
|
||||
'dartls',
|
||||
'dotls',
|
||||
'kotlin_language_server',
|
||||
'nimls',
|
||||
'intelephense',
|
||||
'vuels',
|
||||
'volar',
|
||||
'phpactor',
|
||||
'omnisharp',
|
||||
'r_language_server',
|
||||
'rust_analyzer',
|
||||
'terraformls',
|
||||
'svelte',
|
||||
'texlab',
|
||||
'clojure_lsp',
|
||||
'elixirls',
|
||||
'sourcekit',
|
||||
'fsautocomplete',
|
||||
'vls',
|
||||
'hls',
|
||||
'tflint',
|
||||
'terraform_lsp',
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
local vfn = vim.fn
|
||||
|
||||
local library = {}
|
||||
local sumneko_cfg = {
|
||||
cmd = { 'lua-language-server' },
|
||||
filetypes = { 'lua' },
|
||||
on_attach = on_attach,
|
||||
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
||||
version = 'LuaJIT',
|
||||
},
|
||||
diagnostics = {
|
||||
enable = true,
|
||||
-- Get the language server to recognize the `vim` global
|
||||
globals = { 'vim', 'describe', 'it', 'before_each', 'after_each', 'teardown', 'pending' },
|
||||
},
|
||||
completion = { callSnippet = 'Both' },
|
||||
workspace = {
|
||||
-- Make the server aware of Neovim runtime files
|
||||
library = library,
|
||||
maxPreload = 2000,
|
||||
preloadFileSize = 40000,
|
||||
},
|
||||
telemetry = { enable = false },
|
||||
},
|
||||
},
|
||||
on_new_config = function(cfg, root)
|
||||
local libs = vim.tbl_deep_extend('force', {}, library)
|
||||
libs[root] = nil
|
||||
cfg.settings.Lua.workspace.library = libs
|
||||
return cfg
|
||||
end,
|
||||
}
|
||||
|
||||
local function add(lib)
|
||||
for _, p in pairs(vfn.expand(lib, false, true)) do
|
||||
p = vim.loop.fs_realpath(p)
|
||||
if p then
|
||||
library[p] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
local function sumneko_lua()
|
||||
-- add runtime
|
||||
-- add plugins it may be very slow to add all in path
|
||||
add('$VIMRUNTIME')
|
||||
-- add your config
|
||||
-- local home = vfn.expand("$HOME")
|
||||
add(vfn.stdpath('config'))
|
||||
|
||||
library[vfn.expand('$VIMRUNTIME/lua')] = true
|
||||
library[vfn.expand('$VIMRUNTIME/lua/vim')] = true
|
||||
library[vfn.expand('$VIMRUNTIME/lua/vim/lsp')] = true
|
||||
|
||||
local on_attach = require('navigator.lspclient.attach').on_attach
|
||||
local luadevcfg = {
|
||||
library = {
|
||||
vimruntime = true, -- runtime path
|
||||
types = true, -- full signature, docs and completion of vim.api, vim.treesitter, vim.lsp and others
|
||||
plugins = { 'nvim-treesitter', 'plenary.nvim' },
|
||||
},
|
||||
lspconfig = {
|
||||
-- cmd = {sumneko_binary},
|
||||
on_attach = on_attach,
|
||||
},
|
||||
}
|
||||
|
||||
local luadev = {}
|
||||
local user_luadev = _NgConfigValues.lsp['lua-dev']
|
||||
if user_luadev then
|
||||
luadevcfg = vim.tbl_deep_extend('force', luadevcfg, user_luadev)
|
||||
end
|
||||
require('navigator.lazyloader').load('lua-dev.nvim', 'folke/lua-dev.nvim')
|
||||
|
||||
local ok, l = pcall(require, 'lua-dev')
|
||||
if ok and l then
|
||||
luadev = l.setup(luadevcfg)
|
||||
end
|
||||
|
||||
sumneko_cfg = vim.tbl_deep_extend('force', sumneko_cfg, luadev)
|
||||
return sumneko_cfg
|
||||
end
|
||||
|
||||
return {
|
||||
sumneko_lua = sumneko_lua,
|
||||
}
|
@ -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
|
@ -1 +1,6 @@
|
||||
std="vim"
|
||||
std="lua52+vim"
|
||||
|
||||
[rules]
|
||||
global_usage = "allow"
|
||||
multiple_statements = "allow"
|
||||
unused_variable = "allow"
|
||||
|
@ -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 not crash and show hierarchy', function()
|
||||
vim.fn.setpos('.', { bufn, 24, 15, 0 })
|
||||
local ret = require('navigator.hierarchy')._call_hierarchy()
|
||||
vim.wait(400, function() end)
|
||||
eq(ret, ret) -- make sure doesn't crash the result
|
||||
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)
|
@ -0,0 +1,47 @@
|
||||
---
|
||||
base: lua52
|
||||
name: vim
|
||||
globals:
|
||||
_G:
|
||||
property: new-fields
|
||||
_NgConfigValues:
|
||||
any: true
|
||||
after_each:
|
||||
args:
|
||||
- type: function
|
||||
assert.equals:
|
||||
args:
|
||||
- type: any
|
||||
- type: any
|
||||
- required: false
|
||||
type: any
|
||||
assert.is_not:
|
||||
any: true
|
||||
assert.same:
|
||||
args:
|
||||
- type: any
|
||||
- type: any
|
||||
assert.spy:
|
||||
args:
|
||||
- type: any
|
||||
assert.stub:
|
||||
args:
|
||||
- type: any
|
||||
assert.truthy:
|
||||
args:
|
||||
- type: any
|
||||
before_each:
|
||||
args:
|
||||
- type: function
|
||||
debug:
|
||||
property: read-only
|
||||
describe:
|
||||
args:
|
||||
- type: string
|
||||
- type: function
|
||||
it:
|
||||
args:
|
||||
- type: string
|
||||
- type: function
|
||||
vim:
|
||||
any: true
|
Loading…
Reference in New Issue