mirror of
https://github.com/ray-x/navigator.lua
synced 2024-11-05 12:00:21 +00:00
using async call in sidepanel
This commit is contained in:
parent
d202970180
commit
77b235b2c9
50
README.md
50
README.md
@ -755,6 +755,9 @@ 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">
|
||||
|
||||
The side panel is vim buffer. You can toggle folds with za/zo/zc
|
||||
|
||||
|
||||
Calltree (Expandable LSP call hierarchy)
|
||||
<img width="769" alt="image" src="https://user-images.githubusercontent.com/1681295/176998572-e39fc968-4c8c-475d-b3b8-fb7991663646.png">
|
||||
|
||||
@ -914,6 +917,53 @@ end
|
||||
|
||||
[known issues I am working on](https://github.com/ray-x/navigator.lua/issues/1)
|
||||
|
||||
|
||||
## API and extensions
|
||||
The plugin built on top of guihua, you can extend the plugin based on your requirements.
|
||||
e.g. A side pannel of lsp symbols and lsp diagnostics:
|
||||
|
||||
|
||||
```lua
|
||||
local function treesitter_and_diag_panel()
|
||||
local Panel = require('guihua.panel')
|
||||
|
||||
local diag = require('navigator.diagnostics')
|
||||
local ft = vim.bo.filetype
|
||||
local results = diag.diagnostic_list[ft]
|
||||
log(diag.diagnostic_list, ft)
|
||||
|
||||
local bufnr = api.nvim_get_current_buf()
|
||||
local p = Panel:new({
|
||||
header = 'treesitter',
|
||||
render = function(b)
|
||||
log('render for ', bufnr, b)
|
||||
return require('navigator.treesitter').all_ts_nodes(b)
|
||||
end,
|
||||
})
|
||||
p:add_section({
|
||||
header = 'diagnostic',
|
||||
render = function(buf)
|
||||
log(buf, diagnostic)
|
||||
if diag.diagnostic_list[ft] ~= nil then
|
||||
local display_items = {}
|
||||
for _, client_items in pairs(results) do
|
||||
for _, items in pairs(client_items) do
|
||||
for _, it in pairs(items) do
|
||||
log(it)
|
||||
table.insert(display_items, it)
|
||||
end
|
||||
end
|
||||
end
|
||||
return display_items
|
||||
else
|
||||
return {}
|
||||
end
|
||||
end,
|
||||
})
|
||||
p:open(true)
|
||||
end
|
||||
```
|
||||
|
||||
## Todo
|
||||
|
||||
- The project is in the early phase, bugs expected, PRs and suggestions are welcome
|
||||
|
@ -1,4 +1,3 @@
|
||||
local gui = require('navigator.gui')
|
||||
local diagnostic = vim.diagnostic or vim.lsp.diagnostic
|
||||
local util = require('navigator.util')
|
||||
local log = util.log
|
||||
@ -57,18 +56,31 @@ function M.lsp_and_diag_panel()
|
||||
if ft == 'nofile' or ft == 'guihua' or ft == 'prompt' then
|
||||
return
|
||||
end
|
||||
local lsp
|
||||
local p = Panel:new({
|
||||
header = 'symbols',
|
||||
render = function(bufnr)
|
||||
bufnr = bufnr or api.nvim_get_current_buf()
|
||||
local params = vim.lsp.util.make_range_params()
|
||||
local sync_req = require('navigator.lspwrapper').call_sync
|
||||
local lsp = sync_req(
|
||||
'textDocument/documentSymbol',
|
||||
params,
|
||||
{ timeout = 2000, bufnr = bufnr, no_show = true },
|
||||
vim.lsp.with(require('navigator.symbols').document_symbol_handler, { no_show = true })
|
||||
)
|
||||
local lsp_call = require('navigator.lspwrapper').call_sync
|
||||
if not Panel:is_open() or vim.fn.empty(lsp) == 1 then
|
||||
lsp = lsp_call(
|
||||
'textDocument/documentSymbol',
|
||||
params,
|
||||
{ timeout = 2000, bufnr = bufnr, no_show = true },
|
||||
vim.lsp.with(require('navigator.symbols').document_symbol_handler, { no_show = true })
|
||||
)
|
||||
else
|
||||
lsp_call = require('navigator.lspwrapper').call_async
|
||||
local f = function(err, result, ctx)
|
||||
-- log(result, ctx)
|
||||
ctx = ctx or {}
|
||||
ctx.no_show = true
|
||||
lsp = require('navigator.symbols').document_symbol_handler(err, result, ctx)
|
||||
return lsp
|
||||
end
|
||||
lsp_call('textDocument/documentSymbol', params, f, bufnr)
|
||||
end
|
||||
return lsp
|
||||
end,
|
||||
})
|
||||
|
@ -26,7 +26,7 @@ function M.document_symbols(opts)
|
||||
api = ' ',
|
||||
}
|
||||
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
|
||||
vim.list_extend(lspopts, opts)
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
params.context = { includeDeclaration = true }
|
||||
|
Loading…
Reference in New Issue
Block a user