Merge branch 'master' into nvim_0_7

pull/200/head
ray-x 2 years ago
commit 3697da176c

@ -618,8 +618,8 @@ require'navigator'.setup({
require('rust-tools').setup({
server = {
on_attach = function(_, _)
require('navigator.lspclient.mapping').setup() -- setup navigator keymaps here,
on_attach = function(client, bufnr)
require('navigator.lspclient.mapping').setup({client=client, bufnr=bufnr}) -- setup navigator keymaps here,
-- otherwise, you can define your own commands to call navigator functions
end,
}
@ -627,8 +627,8 @@ require('rust-tools').setup({
require("clangd_extensions").setup {
server = {
on_attach = function(_, _)
require('navigator.lspclient.mapping').setup() -- setup navigator keymaps here,
on_attach = function(client, bufnr)
require('navigator.lspclient.mapping').setup({client=client, bufnr=bufnr}) -- setup navigator keymaps here,
-- otherwise, you can define your own commands to call navigator functions
end,
}
@ -703,9 +703,8 @@ Treesitter outline and Diagnostics
<img width="708" alt="image" src="https://user-images.githubusercontent.com/1681295/174791609-0023e68f-f1f4-4335-9ea2-d2360e9f0bfd.png">
<img width="733" alt="image" src="https://user-images.githubusercontent.com/1681295/174804579-26f87fbf-426b-46d0-a7a3-a5aab69c032f.png">
Calltree (LSP call hierarchy)
<img width="892" alt="image" src="https://user-images.githubusercontent.com/1681295/176054287-edede515-118d-458d-835a-097319ba99c3.png">
Calltree (Expandable LSP call hierarchy)
<img width="769" alt="image" src="https://user-images.githubusercontent.com/1681295/176998572-e39fc968-4c8c-475d-b3b8-fb7991663646.png">
### GUI and multigrid support

@ -253,7 +253,7 @@ call_hierarchy = function(method, opts)
return opts.handler(err, result, ctx, cfg)
end
-- log(opts, params)
request(
return request(
bufnr,
'textDocument/prepareCallHierarchy',
params,
@ -299,6 +299,8 @@ end
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

@ -1,8 +1,13 @@
local util = require('navigator.util')
local log = util.log
local trace = util.trace
<<<<<<< HEAD
local api = vim.api
||||||| 91d1366
=======
>>>>>>> master
local event_hdlrs = {
{ ev = 'BufWritePre', func = require('navigator.diagnostics').set_diag_loclist },
{ ev = { 'CursorHold', 'CursorHoldI' }, func = vim.lsp.buf.document_highlight },
@ -132,12 +137,17 @@ local function set_cmds(_)
end
end
local function set_mapping(lsp_info)
-- should works for both 1)attach from known lsp client or from a disabled lsp client
local function set_mapping(lsp_attach_info)
local opts = { noremap = true, silent = true }
lsp_info = lsp_info or {}
log('setup mapping', lsp_info.client.name, lsp_info.client.cmd)
vim.validate({
lsp_attach_info = { lsp_attach_info, 'table' },
})
if _NgConfigValues.debug then
log('setup mapping for client', lsp_attach_info.client.name, lsp_attach_info.client.cmd)
end
local user_key = _NgConfigValues.keymaps or {}
local bufnr = lsp_info.bufnr or 0
local bufnr = lsp_attach_info.bufnr or 0
local function del_keymap(mode, key, ...)
local ks = vim.api.nvim_buf_get_keymap(bufnr, mode)
@ -153,7 +163,7 @@ local function set_mapping(lsp_info)
-- local function buf_set_option(...)
-- vim.api.nvim_buf_set_option(bufnr, ...)
-- end
local doc_fmt, range_fmt, ccls = check_cap(lsp_info)
local doc_fmt, range_fmt, ccls = check_cap(lsp_attach_info)
if ccls then
vim.list_extend(key_maps, ccls_mappings)
@ -243,8 +253,8 @@ local function set_mapping(lsp_info)
del_keymap('n', fmtkey)
end
if lsp_info.cap and lsp_info.cap.document_range_formatting then
log('formatting enabled', lsp_info.cap)
if lsp_attach_info.cap and lsp_attach_info.cap.document_range_formatting then
log('formatting enabled', lsp_attach_info.cap)
end
if not range_fmt and rfmtkey then
@ -318,15 +328,21 @@ M.toggle_lspformat = function(on)
end
end
function M.setup(user_opts)
user_opts = user_opts or _NgConfigValues
set_mapping(user_opts)
set_cmds(user_opts)
function M.setup(attach_opts)
if not attach_opts or not attach_opts.client then
vim.notify(
'please call require"navigator.mapping".setup({bufnr=bufnr, client=client}) inside on_attach(client,bufnr)',
vim.lsp.log_levels.WARN
)
end
attach_opts = attach_opts or { bufnr = 0, client = {}, cap = {} }
set_mapping(attach_opts)
set_cmds(attach_opts)
autocmd()
set_event_handler(user_opts)
set_event_handler(attach_opts)
local client = user_opts.client or {}
local client = attach_opts.client or {}
local cap = client.server_capabilities or vim.lsp.protocol.make_client_capabilities()
log('lsp cap:', cap.codeActionProvider)

@ -146,6 +146,7 @@ function M.side_panel()
local Panel = require('guihua.panel')
local buf = vim.api.nvim_get_current_buf()
local p = Panel:new({
scope = 'range',
render = function(bufnr)
local ft = vim.api.nvim_buf_get_option(bufnr, 'buftype')
if ft == 'nofile' or ft == 'guihua' or ft == 'prompt' then

@ -623,7 +623,7 @@ function M.all_ts_nodes(bufnr)
return
end
local bufnr = bufnr or api.nvim_get_current_buf()
bufnr = bufnr or api.nvim_get_current_buf()
local all_nodes, width = get_all_nodes(bufnr)
return all_nodes, width
end
@ -641,6 +641,7 @@ function M.side_panel()
end
return require('navigator.treesitter').all_ts_nodes(b)
end,
scope = 'node_scope'
})
panel:open(true)
end

@ -4,12 +4,12 @@ local util = require('navigator.util')
local gutil = require('guihua.util')
local lsphelper = require('navigator.lspwrapper')
local symbols_to_items = lsphelper.symbols_to_items
-- local rename_prompt = 'Rename -> '
local vfn = vim.fn
M.add_workspace_folder = function()
util.log(vim.ui.input)
local input = require('guihua.floating').input
input({ prompt = 'Workspace To Add: ', default = vim.fn.expand('%:p:h') }, function(inputs)
input({ prompt = 'Workspace To Add: ', default = vfn.expand('%:p:h') }, function(inputs)
vim.lsp.buf.add_workspace_folder(inputs)
end)
end
@ -35,7 +35,7 @@ end
function M.workspace_symbol_live()
local height = _NgConfigValues.height or 0.4
height = math.floor(height * vim.fn.winheight('%'))
height = math.floor(height * vfn.winheight('%'))
local width = _NgConfigValues.width or 0.7
width = math.floor(width * vfn.winwidth('%'))
local bufnr = vim.api.nvim_get_current_buf()

@ -42,7 +42,7 @@ local function load_plugins()
use({ 'ray-x/aurora' })
use({
'ray-x/navigator.lua',
-- '~/github/navigator.lua',
-- '~/github/ray-x/navigator.lua',
requires = { 'ray-x/guihua.lua', run = 'cd lua/fzy && make' },
config = function()
require('navigator').setup({

@ -0,0 +1,65 @@
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()
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 navigator.lua]])
vim.cmd([[packadd guihua.lua]])
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('')
vim.bo.filetype = 'go'
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',
})
vim.bo.filetype = 'go'
-- 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()
local panel = require('guihua.panel').debug()
eq(panel.name, 'Panel')
vim.wait(400, function() end)
panel = require('guihua.panel').debug()
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 })
require('navigator.hierarchy')._call_hierarchy()
vim.wait(400, function() end)
end)
end)

@ -44,94 +44,59 @@ describe('should run lsp reference', function()
uri = 'file://' .. cur_dir .. '/tests/fixtures/interface_test.go',
},
}
it('should show references', 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 navigator.lua]])
vim.cmd([[packadd guihua.lua]])
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'lspconfig'.gopls.setup {}
require('navigator').setup({
debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
icons = { code_action_icon = 'A ' },
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',
})
if vim.fn.has('nvim-0.7') then
_NgConfigValues.treesitter_analysis = true
else
_NgConfigValues.treesitter_analysis = false
end
-- 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
local status = require('plenary.reload').reload_module('navigator')
status = require('plenary.reload').reload_module('guihua')
status = require('plenary.reload').reload_module('lspconfig')
vim.cmd([[packadd navigator.lua]])
vim.cmd([[packadd guihua.lua]])
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'lspconfig'.gopls.setup {}
require('navigator').setup({
debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
icons = { code_action_icon = 'A ' },
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',
})
if vim.fn.has('nvim-0.7') then
_NgConfigValues.treesitter_analysis = true
else
_NgConfigValues.treesitter_analysis = false
end
-- 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 references', function()
vim.fn.setpos('.', { bufn, 15, 4, 0 }) -- width
vim.bo.filetype = 'go'
-- vim.lsp.buf.references()
vim.lsp.buf.references()
eq(1, 1)
end)
it('reference handler should return items', function()
local status = require('plenary.reload').reload_module('navigator')
local status = require('plenary.reload').reload_module('guihua')
vim.cmd([[packadd navigator.lua]])
vim.cmd([[packadd guihua.lua]])
local path = cur_dir .. '/tests/fixtures/interface.go' -- %:p:h ? %:p
print(path)
local cmd = " silent exe 'e " .. path .. "'"
vim.cmd(cmd)
-- vim.cmd([[cd %:p:h]])
local bufn = vim.fn.bufnr('')
vim.fn.setpos('.', { bufn, 15, 4, 0 }) -- width
vim.bo.filetype = 'go'
require('navigator').setup({
debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
icons = { code_action_icon = 'A ' },
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
debug_console_output = true,
border = 'none',
})
if vim.fn.has('nvim-0.7') then
_NgConfigValues.treesitter_analysis = true
else
_NgConfigValues.treesitter_analysis = false
end
_NgConfigValues.debug_console_output = true
vim.bo.filetype = 'go'
-- allow gopls start
for i = 1, 10 do
vim.wait(400, function() end)
local clients = vim.lsp.get_active_clients()
print('clients ', #clients)
if #clients > 0 then
break
end
end
-- allow gopls start
vim.wait(200, function() end)
@ -156,50 +121,6 @@ describe('should run lsp reference', function()
-- eq(width, 60)
end)
it('reference handler should return items with thread', function()
local status = require('plenary.reload').reload_module('navigator')
local status = require('plenary.reload').reload_module('guihua')
vim.cmd([[packadd navigator.lua]])
vim.cmd([[packadd guihua.lua]])
local path = cur_dir .. '/tests/fixtures/interface.go' -- %:p:h ? %:p
print(path)
local cmd = "silent exe 'e " .. path .. "'"
vim.cmd(cmd)
vim.cmd([[cd %:p:h]])
local bufn = vim.fn.bufnr('')
vim.fn.setpos('.', { bufn, 15, 4, 0 }) -- width
vim.bo.filetype = 'go'
require('navigator').setup({
debug = true, -- log output, set to true and log path: ~/.local/share/nvim/gh.log
icons = { code_action_icon = 'A ' },
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
debug_console_output = true,
border = 'none',
})
if vim.fn.has('nvim-0.7') then
_NgConfigValues.treesitter_analysis = true
else
_NgConfigValues.treesitter_analysis = false
end
_NgConfigValues.debug_console_output = true
vim.bo.filetype = 'go'
-- allow gopls start
for i = 1, 10 do
vim.wait(400, function() end)
local clients = vim.lsp.get_active_clients()
print('clients ', #clients)
if #clients > 0 then
break
end
end
-- allow gopls start
vim.wait(200, function() end)
local win, items, width
@ -213,7 +134,6 @@ describe('should run lsp reference', function()
else
win, items, width = require('navigator.reference').reference_handler(nil, 'textDocument/references', result, 1, 1)
end
print('win', vim.inspect(win))
print('items', vim.inspect(items))
-- eq(win.ctrl.data, "./interface.go")

Loading…
Cancel
Save