2021-04-19 02:56:32 +00:00
|
|
|
local util = require "navigator.util"
|
2021-09-05 22:34:26 +00:00
|
|
|
local mk_handler = util.mk_handler
|
2021-04-26 11:45:45 +00:00
|
|
|
local log = util.log
|
2021-04-19 02:56:32 +00:00
|
|
|
local lsphelper = require "navigator.lspwrapper"
|
|
|
|
local gui = require "navigator.gui"
|
2021-05-08 04:54:37 +00:00
|
|
|
local lsp = require "navigator.lspwrapper"
|
2021-05-21 11:39:46 +00:00
|
|
|
local trace = require"navigator.util".trace
|
2021-04-19 02:56:32 +00:00
|
|
|
-- local partial = util.partial
|
2021-09-09 02:59:58 +00:00
|
|
|
-- local cwd = vim.loop.cwd()
|
2021-04-19 02:56:32 +00:00
|
|
|
-- local lsphelper = require "navigator.lspwrapper"
|
|
|
|
local locations_to_items = lsphelper.locations_to_items
|
|
|
|
|
2021-09-09 02:59:58 +00:00
|
|
|
local ref_view = function(err, locations, ctx, cfg)
|
2021-04-19 02:56:32 +00:00
|
|
|
local opts = {}
|
2021-09-05 22:34:26 +00:00
|
|
|
trace("arg1", err, ctx, locations)
|
2021-09-09 02:59:58 +00:00
|
|
|
log(ctx.api)
|
2021-05-21 11:39:46 +00:00
|
|
|
trace(locations)
|
2021-04-19 02:56:32 +00:00
|
|
|
-- log("num", num)
|
|
|
|
-- log("bfnr", bufnr)
|
2021-05-17 03:15:15 +00:00
|
|
|
if err ~= nil then
|
2021-09-05 22:34:26 +00:00
|
|
|
print('lsp ref callback error', err, ctx, vim.inspect(locations))
|
|
|
|
log('ref callback error, lsp may not ready', err, ctx, vim.inspect(locations))
|
2021-05-17 03:15:15 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if type(locations) ~= 'table' then
|
|
|
|
log(locations)
|
2021-09-05 22:34:26 +00:00
|
|
|
log("ctx", ctx)
|
|
|
|
print("incorrect setup", location)
|
|
|
|
return
|
2021-05-17 03:15:15 +00:00
|
|
|
end
|
2021-04-19 02:56:32 +00:00
|
|
|
if locations == nil or vim.tbl_isempty(locations) then
|
|
|
|
print "References not found"
|
|
|
|
return
|
|
|
|
end
|
2021-05-17 03:15:15 +00:00
|
|
|
local items, width = locations_to_items(locations)
|
2021-05-21 11:39:46 +00:00
|
|
|
|
2021-09-05 22:34:26 +00:00
|
|
|
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
|
2021-05-17 03:15:15 +00:00
|
|
|
|
|
|
|
local wwidth = vim.api.nvim_get_option("columns")
|
2021-06-25 10:18:55 +00:00
|
|
|
local mwidth = _NgConfigValues.width
|
|
|
|
width = math.min(width + 30, 120, math.floor(wwidth * mwidth))
|
2021-08-24 07:14:43 +00:00
|
|
|
-- log(items)
|
|
|
|
-- log(width)
|
|
|
|
local listview = gui.new_list_view({
|
2021-06-13 04:03:01 +00:00
|
|
|
items = items,
|
|
|
|
ft = ft,
|
|
|
|
width = width,
|
|
|
|
api = "Reference",
|
|
|
|
enable_preview_edit = true
|
|
|
|
})
|
2021-08-24 07:14:43 +00:00
|
|
|
return listview, items, width
|
2021-09-09 02:59:58 +00:00
|
|
|
end
|
|
|
|
local M = {}
|
|
|
|
local ref_hdlr = mk_handler(function(err, locations, ctx, cfg)
|
|
|
|
|
|
|
|
trace(err, locations, ctx, cfg)
|
|
|
|
M.async_hdlr = vim.loop.new_async(vim.schedule_wrap(function()
|
|
|
|
ref_view(err, locations, ctx, cfg)
|
2021-04-19 02:56:32 +00:00
|
|
|
|
2021-09-09 02:59:58 +00:00
|
|
|
M.async_hdlr:close()
|
|
|
|
end))
|
|
|
|
M.async_hdlr:send()
|
|
|
|
end)
|
2021-04-26 11:45:45 +00:00
|
|
|
local async_reference_request = function()
|
|
|
|
local ref_params = vim.lsp.util.make_position_params()
|
2021-05-08 04:54:37 +00:00
|
|
|
ref_params.context = {includeDeclaration = true}
|
2021-08-14 03:05:40 +00:00
|
|
|
-- lsp.call_async("textDocument/references", ref_params, ref_hdlr) -- return asyncresult, canceller
|
|
|
|
lsp.call_async("textDocument/definition", ref_params, ref_hdlr) -- return asyncresult, canceller
|
2021-04-26 11:45:45 +00:00
|
|
|
end
|
|
|
|
|
2021-09-09 02:59:58 +00:00
|
|
|
return {reference_handler = ref_hdlr, show_reference = async_reference_request, ref_view = ref_view}
|