feat: add option jump_type to lsp_definitions and lsp_implementations (#1077)
This commit is contained in:
@@ -789,6 +789,10 @@ builtin.lsp_definitions({opts}) *builtin.lsp_definitions()*
|
|||||||
Parameters: ~
|
Parameters: ~
|
||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
|
Fields: ~
|
||||||
|
{jump_type} (string) how to go to definition if there is only one,
|
||||||
|
values: "tab", "split", "vsplit", "never"
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_implementations({opts}) *builtin.lsp_implementations()*
|
builtin.lsp_implementations({opts}) *builtin.lsp_implementations()*
|
||||||
Goto the implementation of the word under the cursor if there's only one,
|
Goto the implementation of the word under the cursor if there's only one,
|
||||||
@@ -798,6 +802,10 @@ builtin.lsp_implementations({opts}) *builtin.lsp_implementations()*
|
|||||||
Parameters: ~
|
Parameters: ~
|
||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
|
Fields: ~
|
||||||
|
{jump_type} (string) how to go to implementation if there is only one,
|
||||||
|
values: "tab", "split", "vsplit", "never"
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_code_actions({opts}) *builtin.lsp_code_actions()*
|
builtin.lsp_code_actions({opts}) *builtin.lsp_code_actions()*
|
||||||
Lists any LSP actions for the word under the cursor which can be triggered
|
Lists any LSP actions for the word under the cursor which can be triggered
|
||||||
|
|||||||
@@ -316,10 +316,12 @@ builtin.lsp_references = require("telescope.builtin.lsp").references
|
|||||||
|
|
||||||
--- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
|
--- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
|
---@field jump_type string: how to go to definition if there is only one, values: "tab", "split", "vsplit", "never"
|
||||||
builtin.lsp_definitions = require("telescope.builtin.lsp").definitions
|
builtin.lsp_definitions = require("telescope.builtin.lsp").definitions
|
||||||
|
|
||||||
--- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope
|
--- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
|
---@field jump_type string: how to go to implementation if there is only one, values: "tab", "split", "vsplit", "never"
|
||||||
builtin.lsp_implementations = require("telescope.builtin.lsp").implementations
|
builtin.lsp_implementations = require("telescope.builtin.lsp").implementations
|
||||||
|
|
||||||
--- Lists any LSP actions for the word under the cursor which can be triggered with `<cr>`
|
--- Lists any LSP actions for the word under the cursor which can be triggered with `<cr>`
|
||||||
|
|||||||
@@ -64,7 +64,14 @@ local function list_or_jump(action, title, opts)
|
|||||||
|
|
||||||
if #flattened_results == 0 then
|
if #flattened_results == 0 then
|
||||||
return
|
return
|
||||||
elseif #flattened_results == 1 then
|
elseif #flattened_results == 1 and opts.jump_type ~= "never" then
|
||||||
|
if opts.jump_type == "tab" then
|
||||||
|
vim.cmd "tabedit"
|
||||||
|
elseif opts.jump_type == "split" then
|
||||||
|
vim.cmd "new"
|
||||||
|
elseif opts.jump_type == "vsplit" then
|
||||||
|
vim.cmd "vnew"
|
||||||
|
end
|
||||||
vim.lsp.util.jump_to_location(flattened_results[1])
|
vim.lsp.util.jump_to_location(flattened_results[1])
|
||||||
else
|
else
|
||||||
local locations = vim.lsp.util.locations_to_items(flattened_results)
|
local locations = vim.lsp.util.locations_to_items(flattened_results)
|
||||||
|
|||||||
Reference in New Issue
Block a user