You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you're on the main branch, the LSP interop module is no longer available. I found the peek feature it provided useful, so I gave restoring it in my config a shot.
I grabbed the removed code from #661, placed it in <my config>/plugin/peek.lua, and modified it as shown below. This seems to work so far.
If anyone else has gotten this functionality a less hacky way, please drop a response and let me know!
-- Copied from the nvim-treesiter-textobjects plugin-- This module was removed in https://github.com/nvim-treesitter/nvim-treesitter-textobjects/pull/661localapi=vim.apilocalshared=require("nvim-treesitter-textobjects.shared")
--- @typeinteger|nillocalfloating_winlocalfunctionis_new_signature_handler()
ifdebug.getinfo(vim.lsp.handlers.signature_help).nparams==4thenreturntrueelsereturnfalseendend---@paramlocationtable<string, any>---@paramcontextinteger|TSTextObjects.Range---@returninteger?preview_bufnr---@returninteger?preview_winnrlocalfunctionpreview_location(location, context)
-- location may be LocationLink or Location (more useful for the former)localuri=location.targetUriorlocation.uriifuri==nilthenreturnendlocalbufnr=vim.uri_to_bufnr(uri)
ifnotvim.api.nvim_buf_is_loaded(bufnr) thenvim.fn.bufload(bufnr)
endlocalrange=location.targetRangeorlocation.range--[[@as lsp.Range]]-- don't include a exclusive 0 character lineifrange["end"].character==0thenrange["end"].line=range["end"].line-1endiftype(context) =="table" thenlocalstart_row, _, end_row, _=unpack(context:range4()) ---@typeinteger, integer, integer, integerrange.start.line=math.min(range.start.line, start_row)
range["end"].line=math.max(range["end"].line, end_row)
elseiftype(context) =="number" thenrange["end"].line=math.max(range["end"].line, range.start.line+context)
endlocalopts= {}
localcontents=vim.api.nvim_buf_get_lines(bufnr, range.start.line, range["end"].line+1, false)
localfiletype=vim.bo[bufnr].filetypelocalpreview_buf, preview_win=vim.lsp.util.open_floating_preview(contents, filetype, opts)
vim.bo[preview_buf].filetype=filetypereturnpreview_buf, preview_winend---@paramquery_stringstring---@paramquery_groupstring---@paramcontext?integer|TSTextObjects.Range---@returnfun(err?: table, method: string, result: table<string, any>|table<string, any>[])localfunctionmake_preview_location_callback(query_string, query_group, context)
query_group=query_groupor"textobjects"context=contextor0localcallback=function(err, method, result)
iferrthenerror(tostring(err))
endifresult==nilorvim.tbl_isempty(result) thenprint("No location found: " .. (methodor"unknown error"))
returnendifvim.islist(result) then---@castresulttable<string, any>[]result=result[1]
---@castresulttable<string, any>endlocaluri=result.uriorresult.targetUrilocalrange=result.rangeorresult.targetRange--[[@as lsp.Range]]ifnoturiornotrangethenreturnendlocalbuf=vim.uri_to_bufnr(uri)
vim.fn.bufload(buf)
local_, textobject_at_definition=shared.textobject_at_point(query_string, query_group, buf, { range.start.line+1, range.start.character })
iftextobject_at_definitionthencontext=textobject_at_definitionend_, floating_win=preview_location(result, context)
endlocalsignature_handler=callbackifis_new_signature_handler() thensignature_handler=function(err, result, handler_context)
callback(err, handler_context.method, result)
endendreturnvim.schedule_wrap(signature_handler)
end---@paramquery_stringstring---@paramquery_group?string---@paramlsp_request?string---@paramcontext?integer|TSTextObjects.Rangelocalfunctionpeek_definition_code(query_string, query_group, lsp_request, context)
query_group=query_groupor"textobjects"ifnotshared.check_support(api.nvim_get_current_buf(), "textobjects", { query_string }) thenvim.notify(
("The filetype `%s` does not support the textobjects `%s` for the query file `%s`"):format(
vim.bo.filetype,
query_string,
query_group
),
vim.log.levels.WARN
)
returnendlsp_request=lsp_requestor"textDocument/definition"ifvim.tbl_contains(vim.api.nvim_list_wins(), floating_win) thenassert(floating_win, "The floaing window for peeking is not open")
vim.api.nvim_set_current_win(floating_win)
elselocalparams=vim.lsp.util.make_position_params()
returnvim.lsp.buf_request(
0,
lsp_request,
params,
make_preview_location_callback(query_string, query_group, context)
)
endendvim.keymap.set({ "n", "x" }, "<leader>pf", function()
peek_definition_code("@function.outer", "textobjects")
end, { desc="Peek function definition" })
vim.keymap.set({ "n", "x" }, "<leader>pc", function()
peek_definition_code("@class.outer", "textobjects")
end, { desc="Peek class definition" })
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
If you're on the
main
branch, the LSP interop module is no longer available. I found the peek feature it provided useful, so I gave restoring it in my config a shot.I grabbed the removed code from #661, placed it in
<my config>/plugin/peek.lua
, and modified it as shown below. This seems to work so far.If anyone else has gotten this functionality a less hacky way, please drop a response and let me know!
Beta Was this translation helpful? Give feedback.
All reactions