2022-01-18 05:25:48 +00:00
|
|
|
local util = require('navigator.util')
|
|
|
|
local lsphelper = require('navigator.lspwrapper')
|
|
|
|
local gui = require('navigator.gui')
|
2021-04-19 02:56:32 +00:00
|
|
|
local M = {}
|
2022-06-01 15:41:26 +00:00
|
|
|
-- local location = require('guihua.location')
|
2021-04-19 02:56:32 +00:00
|
|
|
local partial = util.partial
|
|
|
|
local locations_to_items = lsphelper.locations_to_items
|
|
|
|
local log = util.log
|
|
|
|
-- dataformat should be same as reference
|
2022-06-01 15:41:26 +00:00
|
|
|
local function location_handler(err, locations, ctx, _, msg)
|
2021-04-19 02:56:32 +00:00
|
|
|
if err ~= nil then
|
2023-02-12 20:34:02 +00:00
|
|
|
vim.notify('ERROR: ' .. tostring(err) .. ' ' .. msg, vim.log.levels.WARN)
|
2021-04-19 02:56:32 +00:00
|
|
|
return
|
|
|
|
end
|
2022-01-18 05:25:48 +00:00
|
|
|
return locations_to_items(locations, ctx)
|
2021-04-19 02:56:32 +00:00
|
|
|
end
|
|
|
|
|
2022-06-01 15:41:26 +00:00
|
|
|
local function implementation_handler(_, err, result, ctx, cfg)
|
2022-01-18 05:25:48 +00:00
|
|
|
local results = location_handler(err, result, ctx, cfg, 'Implementation not found')
|
|
|
|
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, 'ft')
|
2023-02-14 12:58:38 +00:00
|
|
|
gui.new_list_view({ items = results, ft = ft, api = 'Implementation', title = 'Implementation' })
|
2021-04-19 02:56:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.implementation(bang, opts)
|
2022-05-15 13:13:01 +00:00
|
|
|
if not lsphelper.check_capabilities('implementationProvider') then
|
2021-06-13 04:03:01 +00:00
|
|
|
return
|
|
|
|
end
|
2021-04-19 02:56:32 +00:00
|
|
|
|
|
|
|
local params = vim.lsp.util.make_position_params()
|
2022-01-18 05:25:48 +00:00
|
|
|
log('impel params', params)
|
2021-05-17 03:15:15 +00:00
|
|
|
|
2023-02-14 12:58:38 +00:00
|
|
|
lsphelper.call_sync(
|
|
|
|
'textDocument/implementation',
|
|
|
|
params,
|
|
|
|
opts,
|
|
|
|
partial(implementation_handler, bang)
|
|
|
|
)
|
2021-04-19 02:56:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
M.implementation_call = partial(M.implementation, 0)
|
|
|
|
|
|
|
|
M.implementation_handler = partial(implementation_handler, 0)
|
|
|
|
|
|
|
|
return M
|