diff --git a/doc/telescope.txt b/doc/telescope.txt index ba864e7..0f09f5e 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -1311,9 +1311,6 @@ builtin.lsp_references({opts}) *builtin.lsp_references()* Parameters: ~ {opts} (table) options to pass to the picker - Options: ~ - {timeout} (number) timeout for the sync call (default: 10000) - builtin.lsp_definitions({opts}) *builtin.lsp_definitions()* Goto the definition of the word under the cursor, if there's only one, @@ -1324,8 +1321,6 @@ builtin.lsp_definitions({opts}) *builtin.lsp_definitions()* {opts} (table) options to pass to the picker Options: ~ - {timeout} (number) timeout for the sync call (default: - 10000) {jump_type} (string) how to goto definition if there is only one, values: "tab", "split", "vsplit", "never" @@ -1341,8 +1336,6 @@ builtin.lsp_type_definitions({opts}) *builtin.lsp_type_definitions()* {opts} (table) options to pass to the picker Options: ~ - {timeout} (number) timeout for the sync call (default: - 10000) {jump_type} (string) how to goto definition if there is only one, values: "tab", "split", "vsplit", "never" @@ -1358,8 +1351,6 @@ builtin.lsp_implementations({opts}) *builtin.lsp_implementations()* {opts} (table) options to pass to the picker Options: ~ - {timeout} (number) timeout for the sync call (default: - 10000) {jump_type} (string) how to goto implementation if there is only one, values: "tab", "split", "vsplit", "never" @@ -1404,8 +1395,6 @@ builtin.lsp_document_symbols({opts}) *builtin.lsp_document_symbols()* {opts} (table) options to pass to the picker Options: ~ - {timeout} (number) timeout for the sync call - (default: 10000) {ignore_filename} (boolean) dont show filenames (default: true) {show_line} (boolean) if true, shows the content of the @@ -1429,8 +1418,6 @@ builtin.lsp_workspace_symbols({opts}) *builtin.lsp_workspace_symbols()* Options: ~ {query} (string) for what to query the workspace (default: "") - {timeout} (number) timeout for the sync call - (default: 10000) {ignore_filename} (boolean) dont show filenames (default: false) {show_line} (boolean) if true, shows the content of the diff --git a/lua/telescope/builtin/diagnostics.lua b/lua/telescope/builtin/diagnostics.lua index 0fce711..6b13e70 100644 --- a/lua/telescope/builtin/diagnostics.lua +++ b/lua/telescope/builtin/diagnostics.lua @@ -86,6 +86,9 @@ local diagnostics_to_tbl = function(opts) end diagnostics.get = function(opts) + if opts.bufnr ~= 0 then + opts.bufnr = nil + end if opts.bufnr == nil then opts.path_display = vim.F.if_nil(opts.path_display, {}) end diff --git a/lua/telescope/builtin/files.lua b/lua/telescope/builtin/files.lua index 886745a..091c818 100644 --- a/lua/telescope/builtin/files.lua +++ b/lua/telescope/builtin/files.lua @@ -271,16 +271,14 @@ files.treesitter = function(opts) end local parsers = require "nvim-treesitter.parsers" - if not parsers.has_parser() then + if not parsers.has_parser(parsers.get_buf_lang(opts.bufnr)) then print "No parser for the current buffer" return end local ts_locals = require "nvim-treesitter.locals" - local bufnr = opts.bufnr or vim.api.nvim_get_current_buf() - local results = {} - for _, definitions in ipairs(ts_locals.get_definitions(bufnr)) do + for _, definitions in ipairs(ts_locals.get_definitions(opts.bufnr)) do local entries = prepare_match(definitions) for _, entry in ipairs(entries) do table.insert(results, entry) @@ -307,17 +305,16 @@ end files.current_buffer_fuzzy_find = function(opts) -- All actions are on the current buffer - local bufnr = vim.api.nvim_get_current_buf() - local filename = vim.fn.expand(vim.api.nvim_buf_get_name(bufnr)) - local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype") + local filename = vim.fn.expand(vim.api.nvim_buf_get_name(opts.bufnr)) + local filetype = vim.api.nvim_buf_get_option(opts.bufnr, "filetype") - local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + local lines = vim.api.nvim_buf_get_lines(opts.bufnr, 0, -1, false) local lines_with_numbers = {} for lnum, line in ipairs(lines) do table.insert(lines_with_numbers, { lnum = lnum, - bufnr = bufnr, + bufnr = opts.bufnr, filename = filename, text = line, }) @@ -329,9 +326,9 @@ files.current_buffer_fuzzy_find = function(opts) end local _, ts_configs = pcall(require, "nvim-treesitter.configs") - local parser_ok, parser = pcall(vim.treesitter.get_parser, bufnr, filetype) + local parser_ok, parser = pcall(vim.treesitter.get_parser, opts.bufnr, filetype) local query_ok, query = pcall(vim.treesitter.get_query, filetype, "highlights") - if parser_ok and query_ok and ts_ok and ts_configs.is_enabled("highlight", filetype, bufnr) then + if parser_ok and query_ok and ts_ok and ts_configs.is_enabled("highlight", filetype, opts.bufnr) then local root = parser:parse()[1]:root() local highlighter = vim.treesitter.highlighter.new(parser) @@ -344,7 +341,7 @@ files.current_buffer_fuzzy_find = function(opts) return obj end, }) - for id, node in query:iter_captures(root, bufnr, 0, -1) do + for id, node in query:iter_captures(root, opts.bufnr, 0, -1) do local hl = highlighter_query:_get_hl_from_capture(id) if hl and type(hl) ~= "number" then local row1, col1, row2, col2 = node:range() diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index 7bb7bfd..af5d4c6 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -101,8 +101,8 @@ local get_current_buf_line = function(winnr) end git.bcommits = function(opts) - opts.current_line = (opts.current_file == nil) and get_current_buf_line(0) or nil - opts.current_file = vim.F.if_nil(opts.current_file, vim.fn.expand "%:p") + opts.current_line = (opts.current_file == nil) and get_current_buf_line(opts.winnr) or nil + opts.current_file = vim.F.if_nil(opts.current_file, vim.api.nvim_buf_get_name(opts.bufnr)) opts.entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_commits(opts)) local git_command = vim.F.if_nil(opts.git_command, { "git", "log", "--pretty=oneline", "--abbrev-commit" }) diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index dc094b5..1edf1c8 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -352,12 +352,10 @@ builtin.jumplist = require_on_exported_call("telescope.builtin.internal").jumpli --- Lists LSP references for word under the cursor, jumps to reference on `` ---@param opts table: options to pass to the picker ----@field timeout number: timeout for the sync call (default: 10000) builtin.lsp_references = require_on_exported_call("telescope.builtin.lsp").references --- 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 timeout number: timeout for the sync call (default: 10000) ---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never" ---@field ignore_filename boolean: dont show filenames (default: true) builtin.lsp_definitions = require_on_exported_call("telescope.builtin.lsp").definitions @@ -365,14 +363,12 @@ builtin.lsp_definitions = require_on_exported_call("telescope.builtin.lsp").defi --- 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 timeout number: timeout for the sync call (default: 10000) ---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never" ---@field ignore_filename boolean: dont show filenames (default: true) builtin.lsp_type_definitions = require("telescope.builtin.lsp").type_definitions --- 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 timeout number: timeout for the sync call (default: 10000) ---@field jump_type string: how to goto implementation if there is only one, values: "tab", "split", "vsplit", "never" ---@field ignore_filename boolean: dont show filenames (default: true) builtin.lsp_implementations = require_on_exported_call("telescope.builtin.lsp").implementations @@ -393,7 +389,6 @@ builtin.lsp_range_code_actions = require_on_exported_call("telescope.builtin.lsp --- - Default keymaps: --- - ``: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`) ---@param opts table: options to pass to the picker ----@field timeout number: timeout for the sync call (default: 10000) ---@field ignore_filename boolean: dont show filenames (default: true) ---@field show_line boolean: if true, shows the content of the line the tag is found on (default: false) ---@field symbols string|table: filter results by symbol kind(s) @@ -405,7 +400,6 @@ builtin.lsp_document_symbols = require_on_exported_call("telescope.builtin.lsp") --- - ``: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`) ---@param opts table: options to pass to the picker ---@field query string: for what to query the workspace (default: "") ----@field timeout number: timeout for the sync call (default: 10000) ---@field ignore_filename boolean: dont show filenames (default: false) ---@field show_line boolean: if true, shows the content of the line the tag is found on (default: false) ---@field symbols string|table: filter results by symbol kind(s) @@ -448,6 +442,8 @@ local apply_config = function(mod) for k, v in pairs(mod) do mod[k] = function(opts) opts = opts or {} + opts.bufnr = opts.bufnr or vim.api.nvim_get_current_buf() + opts.winnr = opts.winnr or vim.api.nvim_get_current_win() local pconf = pickers_conf[k] or {} local defaults = (function() if pconf.theme then diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 1d9785b..3a37664 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -62,6 +62,8 @@ internal.builtin = function(opts) end end + opts.bufnr = vim.api.nvim_get_current_buf() + opts.winnr = vim.api.nvim_get_current_win() pickers.new(opts, { prompt_title = title, finder = finders.new_table { diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua index aa83481..4b9de3c 100644 --- a/lua/telescope/builtin/lsp.lua +++ b/lua/telescope/builtin/lsp.lua @@ -13,10 +13,10 @@ local utils = require "telescope.utils" local lsp = {} lsp.references = function(opts) - local params = vim.lsp.util.make_position_params() + local params = vim.lsp.util.make_position_params(opts.winnr) params.context = { includeDeclaration = true } - vim.lsp.buf_request(0, "textDocument/references", params, function(err, result, ctx, _config) + vim.lsp.buf_request(opts.bufnr, "textDocument/references", params, function(err, result, ctx, _config) if err then vim.api.nvim_err_writeln("Error when finding references: " .. err.message) return @@ -49,8 +49,8 @@ end local function list_or_jump(action, title, opts) opts = opts or {} - local params = vim.lsp.util.make_position_params() - vim.lsp.buf_request(0, action, params, function(err, result, ctx, _config) + local params = vim.lsp.util.make_position_params(opts.winnr) + vim.lsp.buf_request(opts.bufnr, action, params, function(err, result, ctx, _config) if err then vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. err.message) return @@ -106,9 +106,8 @@ lsp.implementations = function(opts) end lsp.document_symbols = function(opts) - local bufnr = vim.api.nvim_get_current_buf() - local params = vim.lsp.util.make_position_params() - vim.lsp.buf_request(0, "textDocument/documentSymbol", params, function(err, result, _ctx, _config) + local params = vim.lsp.util.make_position_params(opts.winnr) + vim.lsp.buf_request(opts.bufnr, "textDocument/documentSymbol", params, function(err, result, _, _) if err then vim.api.nvim_err_writeln("Error when finding document symbols: " .. err.message) return @@ -119,7 +118,7 @@ lsp.document_symbols = function(opts) return end - local locations = vim.lsp.util.symbols_to_items(result or {}, bufnr) or {} + local locations = vim.lsp.util.symbols_to_items(result or {}, opts.bufnr) or {} locations = utils.filter_symbols(locations, opts) if locations == nil then -- error message already printed in `utils.filter_symbols` @@ -127,6 +126,7 @@ lsp.document_symbols = function(opts) end if vim.tbl_isempty(locations) then + print "locations table empty" return end @@ -147,14 +147,15 @@ lsp.document_symbols = function(opts) end lsp.code_actions = function(opts) - local params = vim.F.if_nil(opts.params, vim.lsp.util.make_range_params()) + local params = vim.F.if_nil(opts.params, vim.lsp.util.make_range_params(opts.winnr)) + local lnum = vim.api.nvim_win_get_cursor(opts.winnr)[1] params.context = { - diagnostics = vim.lsp.diagnostic.get_line_diagnostics(), + diagnostics = vim.lsp.diagnostic.get_line_diagnostics(opts.bufnr, lnum - 1), } local results_lsp, err = vim.lsp.buf_request_sync( - 0, + opts.bufnr, "textDocument/codeAction", params, vim.F.if_nil(opts.timeout, 10000) @@ -334,20 +335,19 @@ lsp.code_actions = function(opts) end lsp.range_code_actions = function(opts) - opts.params = vim.lsp.util.make_given_range_params({ opts.start_line, 1 }, { opts.end_line, 1 }) + opts.params = vim.lsp.util.make_given_range_params({ opts.start_line, 1 }, { opts.end_line, 1 }, opts.bufnr) lsp.code_actions(opts) end lsp.workspace_symbols = function(opts) - local bufnr = vim.api.nvim_get_current_buf() local params = { query = opts.query or "" } - vim.lsp.buf_request(0, "workspace/symbol", params, function(err, server_result, _ctx, _config) + vim.lsp.buf_request(opts.bufnr, "workspace/symbol", params, function(err, server_result, _, _) if err then vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. err.message) return end - local locations = vim.lsp.util.symbols_to_items(server_result or {}, bufnr) or {} + local locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr) or {} locations = utils.filter_symbols(locations, opts) if locations == nil then -- error message already printed in `utils.filter_symbols` @@ -400,21 +400,19 @@ local function get_workspace_symbols_requester(bufnr, opts) end lsp.dynamic_workspace_symbols = function(opts) - local curr_bufnr = vim.api.nvim_get_current_buf() - pickers.new(opts, { prompt_title = "LSP Dynamic Workspace Symbols", finder = finders.new_dynamic { entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts), - fn = get_workspace_symbols_requester(curr_bufnr, opts), + fn = get_workspace_symbols_requester(opts.bufnr, opts), }, previewer = conf.qflist_previewer(opts), sorter = conf.generic_sorter(opts), }):find() end -local function check_capabilities(feature) - local clients = vim.lsp.buf_get_clients(0) +local function check_capabilities(feature, bufnr) + local clients = vim.lsp.buf_get_clients(bufnr) local supported_client = false for _, client in pairs(clients) do @@ -452,7 +450,7 @@ local function apply_checks(mod) opts = opts or {} local feature_name = feature_map[k] - if feature_name and not check_capabilities(feature_name) then + if feature_name and not check_capabilities(feature_name, opts.bufnr) then return end v(opts) diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index e3d7638..38a5d9b 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -536,7 +536,7 @@ function make_entry.gen_from_treesitter(opts) return function(entry) local ts_utils = require "nvim-treesitter.ts_utils" local start_row, start_col, end_row, _ = ts_utils.get_node_range(entry.node) - local node_text = ts_utils.get_node_text(entry.node)[1] + local node_text = ts_utils.get_node_text(entry.node, bufnr)[1] return { valid = true, @@ -906,7 +906,7 @@ function make_entry.gen_from_ctags(opts) opts = opts or {} local cwd = vim.fn.expand(opts.cwd or vim.loop.cwd()) - local current_file = Path:new(vim.fn.expand "%"):normalize(cwd) + local current_file = Path:new(vim.api.nvim_buf_get_name(opts.bufnr)):normalize(cwd) local display_items = { { remaining = true },