navigator.lua/lua/navigator/implementation.lua

42 lines
1.3 KiB
Lua
Raw Normal View History

2021-04-19 02:56:32 +00:00
local util = require "navigator.util"
local mk_handler = util.mk_handler
2021-04-19 02:56:32 +00:00
local lsphelper = require "navigator.lspwrapper"
local gui = require "navigator.gui"
local M = {}
local location = require("guihua.location")
local partial = util.partial
local locations_to_items = lsphelper.locations_to_items
local log = util.log
-- dataformat should be same as reference
local function location_handler(err, locations, ctx, cfg, msg)
2021-04-19 02:56:32 +00:00
if err ~= nil then
print("ERROR: " .. tostring(err) .. msg)
2021-04-19 02:56:32 +00:00
return
end
return locations_to_items(locations)
end
local function implementation_handler(bang, err, result, ctx, cfg)
local results = location_handler(err, result, ctx, "Implementation not found")
local ft = vim.api.nvim_buf_get_option(ctx.bufnr, "ft")
gui.new_list_view({items = results, ft = ft, api = 'Implementation'})
2021-04-19 02:56:32 +00:00
end
function M.implementation(bang, opts)
2021-06-13 04:03:01 +00:00
if not lsphelper.check_capabilities("implementation") then
return
end
2021-04-19 02:56:32 +00:00
local params = vim.lsp.util.make_position_params()
2021-06-13 04:03:01 +00:00
log("impel params", params)
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