Skip to content

Commit 060fedf

Browse files
authored
feat(lsp-jump-type): tab drop as new jump_type option for go-to LSP pickers (#2751)
1 parent 74ce793 commit 060fedf

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

doc/telescope.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,8 +1549,8 @@ builtin.lsp_references({opts}) *telescope.builtin.lsp_references()*
15491549
{jump_type} (string) how to goto reference if there is
15501550
only one and the definition file is
15511551
different from the current file,
1552-
values: "tab", "split", "vsplit",
1553-
"never"
1552+
values: "tab", "tab drop", "split",
1553+
"vsplit", "never"
15541554
{fname_width} (number) defines the width of the filename
15551555
section (default: 30)
15561556
{show_line} (boolean) show results text (default: true)
@@ -1601,8 +1601,8 @@ builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()*
16011601
Options: ~
16021602
{jump_type} (string) how to goto definition if there is only one
16031603
and the definition file is different from
1604-
the current file, values: "tab", "split",
1605-
"vsplit", "never"
1604+
the current file, values: "tab", "tab
1605+
drop", "split", "vsplit", "never"
16061606
{fname_width} (number) defines the width of the filename section
16071607
(default: 30)
16081608
{show_line} (boolean) show results text (default: true)
@@ -1623,8 +1623,8 @@ builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()*
16231623
Options: ~
16241624
{jump_type} (string) how to goto definition if there is only one
16251625
and the definition file is different from
1626-
the current file, values: "tab", "split",
1627-
"vsplit", "never"
1626+
the current file, values: "tab", "tab
1627+
drop", "split", "vsplit", "never"
16281628
{fname_width} (number) defines the width of the filename section
16291629
(default: 30)
16301630
{show_line} (boolean) show results text (default: true)
@@ -1645,8 +1645,8 @@ builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()*
16451645
Options: ~
16461646
{jump_type} (string) how to goto implementation if there is only
16471647
one and the definition file is different
1648-
from the current file, values: "tab",
1649-
"split", "vsplit", "never"
1648+
from the current file, values: "tab", "tab
1649+
drop", "split", "vsplit", "never"
16501650
{fname_width} (number) defines the width of the filename section
16511651
(default: 30)
16521652
{show_line} (boolean) show results text (default: true)

lua/telescope/builtin/__lsp.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ lsp.references = function(opts)
4747
vim.cmd "new"
4848
elseif opts.jump_type == "vsplit" then
4949
vim.cmd "vnew"
50+
elseif opts.jump_type == "tab drop" then
51+
vim.cmd("tab drop " .. locations[1].filename)
5052
end
5153
end
5254
-- jump to location
@@ -197,6 +199,9 @@ local function list_or_jump(action, title, opts)
197199
vim.cmd "new"
198200
elseif opts.jump_type == "vsplit" then
199201
vim.cmd "vnew"
202+
elseif opts.jump_type == "tab drop" then
203+
local file_path = vim.uri_to_fname(flattened_results[1].uri)
204+
vim.cmd("tab drop " .. file_path)
200205
end
201206
end
202207

lua/telescope/builtin/init.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ builtin.jumplist = require_on_exported_call("telescope.builtin.__internal").jump
416416
---@param opts table: options to pass to the picker
417417
---@field include_declaration boolean: include symbol declaration in the lsp references (default: true)
418418
---@field include_current_line boolean: include current line (default: false)
419-
---@field jump_type string: how to goto reference if there is only one and the definition file is different from the current file, values: "tab", "split", "vsplit", "never"
419+
---@field jump_type string: how to goto reference if there is only one and the definition file is different from the current file, values: "tab", "tab drop", "split", "vsplit", "never"
420420
---@field fname_width number: defines the width of the filename section (default: 30)
421421
---@field show_line boolean: show results text (default: true)
422422
---@field trim_text boolean: trim results text (default: false)
@@ -441,7 +441,7 @@ builtin.lsp_outgoing_calls = require_on_exported_call("telescope.builtin.__lsp")
441441

442442
--- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
443443
---@param opts table: options to pass to the picker
444-
---@field jump_type string: how to goto definition if there is only one and the definition file is different from the current file, values: "tab", "split", "vsplit", "never"
444+
---@field jump_type string: how to goto definition if there is only one and the definition file is different from the current file, values: "tab", "tab drop", "split", "vsplit", "never"
445445
---@field fname_width number: defines the width of the filename section (default: 30)
446446
---@field show_line boolean: show results text (default: true)
447447
---@field trim_text boolean: trim results text (default: false)
@@ -452,7 +452,7 @@ builtin.lsp_definitions = require_on_exported_call("telescope.builtin.__lsp").de
452452
--- Goto the definition of the type of the word under the cursor, if there's only one,
453453
--- otherwise show all options in Telescope
454454
---@param opts table: options to pass to the picker
455-
---@field jump_type string: how to goto definition if there is only one and the definition file is different from the current file, values: "tab", "split", "vsplit", "never"
455+
---@field jump_type string: how to goto definition if there is only one and the definition file is different from the current file, values: "tab", "tab drop", "split", "vsplit", "never"
456456
---@field fname_width number: defines the width of the filename section (default: 30)
457457
---@field show_line boolean: show results text (default: true)
458458
---@field trim_text boolean: trim results text (default: false)
@@ -462,7 +462,7 @@ builtin.lsp_type_definitions = require_on_exported_call("telescope.builtin.__lsp
462462

463463
--- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope
464464
---@param opts table: options to pass to the picker
465-
---@field jump_type string: how to goto implementation if there is only one and the definition file is different from the current file, values: "tab", "split", "vsplit", "never"
465+
---@field jump_type string: how to goto implementation if there is only one and the definition file is different from the current file, values: "tab", "tab drop", "split", "vsplit", "never"
466466
---@field fname_width number: defines the width of the filename section (default: 30)
467467
---@field show_line boolean: show results text (default: true)
468468
---@field trim_text boolean: trim results text (default: false)

0 commit comments

Comments
 (0)