From c04d962650481ab8fa92ceb89cda9b1a257e8e7a Mon Sep 17 00:00:00 2001 From: Blackmorse Date: Wed, 28 Feb 2024 14:13:04 +0400 Subject: [PATCH 1/2] feat(lsp_jump_type): jump type can be passed as a function --- doc/telescope.txt | 16 ++++++++++++---- lua/telescope/builtin/__lsp.lua | 2 ++ lua/telescope/builtin/init.lua | 8 ++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index 7004e85447..3e7e7e0420 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1558,7 +1558,9 @@ builtin.lsp_references({opts}) *telescope.builtin.lsp_references()* only one and the definition file is different from the current file, values: "tab", "tab drop", "split", - "vsplit", "never" + "vsplit", "never" or a function, + which will be executed before the + jump {show_line} (boolean) show results text (default: true) {trim_text} (boolean) trim results text (default: false) {file_encoding} (string) file encoding for the previewer @@ -1604,7 +1606,9 @@ builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()* {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" + drop", "split", "vsplit", "never" or a function, + which will be executed before the + jump {show_line} (boolean) show results text (default: true) {trim_text} (boolean) trim results text (default: false) {reuse_win} (boolean) jump to existing window if buffer is @@ -1624,7 +1628,9 @@ builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()* {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" + drop", "split", "vsplit", "never" or a function, + which will be executed before the + jump {show_line} (boolean) show results text (default: true) {trim_text} (boolean) trim results text (default: false) {reuse_win} (boolean) jump to existing window if buffer is @@ -1644,7 +1650,9 @@ builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()* {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" + drop", "split", "vsplit", "never" or a function, + which will be executed before the + jump {show_line} (boolean) show results text (default: true) {trim_text} (boolean) trim results text (default: false) {reuse_win} (boolean) jump to existing window if buffer is diff --git a/lua/telescope/builtin/__lsp.lua b/lua/telescope/builtin/__lsp.lua index 90dec93af1..73826ad949 100644 --- a/lua/telescope/builtin/__lsp.lua +++ b/lua/telescope/builtin/__lsp.lua @@ -162,6 +162,8 @@ local function list_or_jump(action, title, params, opts) elseif opts.jump_type == "tab drop" then local file_path = vim.uri_to_fname(target_uri) vim.cmd("tab drop " .. file_path) + elseif type(opts.jump_type) == "function" then + opts.jump_type() end end diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index e40ef2c6ed..1758907996 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -416,7 +416,7 @@ builtin.jumplist = require_on_exported_call("telescope.builtin.__internal").jump ---@param opts table: options to pass to the picker ---@field include_declaration boolean: include symbol declaration in the lsp references (default: true) ---@field include_current_line boolean: include current line (default: false) ----@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" +---@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" or a function, which will be executed before the jump ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field file_encoding string: file encoding for the previewer @@ -438,7 +438,7 @@ builtin.lsp_outgoing_calls = require_on_exported_call("telescope.builtin.__lsp") --- 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 ----@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" +---@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" or a function, which will be executed before the jump ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field reuse_win boolean: jump to existing window if buffer is already opened (default: false) @@ -448,7 +448,7 @@ builtin.lsp_definitions = require_on_exported_call("telescope.builtin.__lsp").de --- Goto the definition of the type 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 ----@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" +---@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" or a function, which will be executed before the jump ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field reuse_win boolean: jump to existing window if buffer is already opened (default: false) @@ -457,7 +457,7 @@ builtin.lsp_type_definitions = require_on_exported_call("telescope.builtin.__lsp --- 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 ----@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" +---@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" or a function, which will be executed before the jump ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field reuse_win boolean: jump to existing window if buffer is already opened (default: false) From 1e098a2061e23d5d08fbe4e70494179811d9f580 Mon Sep 17 00:00:00 2001 From: Blackmorse Date: Thu, 18 Sep 2025 22:38:35 +0400 Subject: [PATCH 2/2] improved signature docs for jump_type --- doc/telescope.txt | 98 +++++++++++++++++----------------- lua/telescope/builtin/init.lua | 8 +-- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/doc/telescope.txt b/doc/telescope.txt index df76dd538b..5217fc74d4 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1605,22 +1605,22 @@ builtin.lsp_references({opts}) *telescope.builtin.lsp_references()* {opts} (table) options to pass to the picker Options: ~ - {include_declaration} (boolean) include symbol declaration in the - lsp references (default: true) - {include_current_line} (boolean) include current line (default: - false) - {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" or a function, - which will be executed before the - jump - {show_line} (boolean) show results text (default: true) - {trim_text} (boolean) trim results text (default: false) - {reuse_win} (boolean) jump to existing window if buffer is - already opened (default: false) - {file_encoding} (string) file encoding for the previewer + {include_declaration} (boolean) include symbol declaration in the + lsp references (default: true) + {include_current_line} (boolean) include current line (default: + false) + {jump_type} (string|function) 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" or a function, + which will be executed before the + jump + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {reuse_win} (boolean) jump to existing window if buffer is + already opened (default: false) + {file_encoding} (string) file encoding for the previewer builtin.lsp_incoming_calls({opts}) *telescope.builtin.lsp_incoming_calls()* @@ -1660,17 +1660,17 @@ builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()* {opts} (table) options to pass to the picker Options: ~ - {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" or a function, - which will be executed before the - jump - {show_line} (boolean) show results text (default: true) - {trim_text} (boolean) trim results text (default: false) - {reuse_win} (boolean) jump to existing window if buffer is - already opened (default: false) - {file_encoding} (string) file encoding for the previewer + {jump_type} (string|function) 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" or a function, + which will be executed before the + jump + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {reuse_win} (boolean) jump to existing window if buffer is + already opened (default: false) + {file_encoding} (string) file encoding for the previewer builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()* @@ -1682,17 +1682,17 @@ builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()* {opts} (table) options to pass to the picker Options: ~ - {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" or a function, - which will be executed before the - jump - {show_line} (boolean) show results text (default: true) - {trim_text} (boolean) trim results text (default: false) - {reuse_win} (boolean) jump to existing window if buffer is - already opened (default: false) - {file_encoding} (string) file encoding for the previewer + {jump_type} (string|function) 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" or a function, + which will be executed before the + jump + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {reuse_win} (boolean) jump to existing window if buffer is + already opened (default: false) + {file_encoding} (string) file encoding for the previewer builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()* @@ -1704,17 +1704,17 @@ builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()* {opts} (table) options to pass to the picker Options: ~ - {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" or a function, - which will be executed before the - jump - {show_line} (boolean) show results text (default: true) - {trim_text} (boolean) trim results text (default: false) - {reuse_win} (boolean) jump to existing window if buffer is - already opened (default: false) - {file_encoding} (string) file encoding for the previewer + {jump_type} (string|function) 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" or a function, + which will be executed before the + jump + {show_line} (boolean) show results text (default: true) + {trim_text} (boolean) trim results text (default: false) + {reuse_win} (boolean) jump to existing window if buffer is + already opened (default: false) + {file_encoding} (string) file encoding for the previewer builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()* diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index c45d8598fe..c8f69fca52 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -423,7 +423,7 @@ builtin.jumplist = require_on_exported_call("telescope.builtin.__internal").jump ---@param opts table: options to pass to the picker ---@field include_declaration boolean: include symbol declaration in the lsp references (default: true) ---@field include_current_line boolean: include current line (default: false) ----@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" or a function, which will be executed before the jump +---@field jump_type string|function: 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" or a function, which will be executed before the jump ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field reuse_win boolean: jump to existing window if buffer is already opened (default: false) @@ -446,7 +446,7 @@ builtin.lsp_outgoing_calls = require_on_exported_call("telescope.builtin.__lsp") --- 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 ----@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" or a function, which will be executed before the jump +---@field jump_type string|function: 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" or a function, which will be executed before the jump ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field reuse_win boolean: jump to existing window if buffer is already opened (default: false) @@ -456,7 +456,7 @@ builtin.lsp_definitions = require_on_exported_call("telescope.builtin.__lsp").de --- Goto the definition of the type 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 ----@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" or a function, which will be executed before the jump +---@field jump_type string|function: 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" or a function, which will be executed before the jump ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field reuse_win boolean: jump to existing window if buffer is already opened (default: false) @@ -465,7 +465,7 @@ builtin.lsp_type_definitions = require_on_exported_call("telescope.builtin.__lsp --- 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 ----@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" or a function, which will be executed before the jump +---@field jump_type string|function: 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" or a function, which will be executed before the jump ---@field show_line boolean: show results text (default: true) ---@field trim_text boolean: trim results text (default: false) ---@field reuse_win boolean: jump to existing window if buffer is already opened (default: false)