diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cd2c6b69..e37efe355 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,12 +53,14 @@ jobs: version: nightly - name: luajit - uses: leafo/gh-actions-lua@v10 + uses: leafo/gh-actions-lua@v11 with: luaVersion: "luajit-2.1.0-beta3" - name: luarocks - uses: leafo/gh-actions-luarocks@v4 + uses: leafo/gh-actions-luarocks@v5 + with: + luarocksVersion: "3.12.2" - name: run test shell: bash diff --git a/doc/lspsaga.nvim.txt b/doc/lspsaga.nvim.txt index ddccef32d..a8ce8b184 100644 --- a/doc/lspsaga.nvim.txt +++ b/doc/lspsaga.nvim.txt @@ -1,4 +1,4 @@ -*lspsaga.nvim.txt* For Nvim 0.8.0 Last change: 2025 June 25 +*lspsaga.nvim.txt* For Nvim 0.8.0 Last change: 2025 September 10 ============================================================================== Table of Contents *lspsaga.nvim-table-of-contents* diff --git a/lua/lspsaga/finder/init.lua b/lua/lspsaga/finder/init.lua index c436b93d8..de69aac2d 100644 --- a/lua/lspsaga/finder/init.lua +++ b/lua/lspsaga/finder/init.lua @@ -489,16 +489,25 @@ function fd:new(args) self.inexist = config.finder.sp_inexist end self.layout = layout or config.finder.layout + + local curbuf = api.nvim_get_current_buf() + local params = lsp.util.make_position_params(0, util.get_offset_encoding({ bufnr = curbuf })) + params.context = { + includeDeclaration = true, + } + if type(config.finder.ref_opt) == 'boolean' then + params.context = { + includeDeclaration = config.finder.ref_opt, + } + end + if #meth == 0 then meth = vim.split(config.finder.default, '+', { plain = true }) end local methods = box.get_methods(meth) - methods = vim.tbl_filter(function(method) return #util.get_client_by_method(method) > 0 end, methods) - local curbuf = api.nvim_get_current_buf() - self.ft = vim.bo[curbuf].filetype if #methods == 0 then vim.notify( ('[lspsaga] no servers of buffer %s makes these methods available %s'):format( @@ -510,23 +519,24 @@ function fd:new(args) return end + local methods_with_params = vim.tbl_map(function(method) + return util.gen_param_by_config(method, params, config.finder.ref_opt) + end, methods) + + self.ft = vim.bo[curbuf].filetype self.list = slist.new() - local params = lsp.util.make_position_params(0, util.get_offset_encoding({ bufnr = curbuf })) - params.context = { - includeDeclaration = true, - } local spin_close = box.spinner() local count = 0 coroutine.resume(coroutine.create(function() local retval = {} local co = coroutine.running() - for _, method in ipairs(methods) do - lsp.buf_request_all(curbuf, method, params, function(results) + for _, item in ipairs(methods_with_params) do + lsp.buf_request_all(curbuf, item[1], item[2], function(results) count = count + 1 - results = box.filter(method, results) + results = box.filter(item[1], results) if results and not util.res_isempty(results) then - retval[method] = results + retval[item[1]] = results end if count == #methods then coroutine.resume(co) diff --git a/lua/lspsaga/init.lua b/lua/lspsaga/init.lua index d54040ac5..e621f348c 100644 --- a/lua/lspsaga/init.lua +++ b/lua/lspsaga/init.lua @@ -86,6 +86,7 @@ local default_config = { ly_botright = false, number = vim.o.number, relativenumber = vim.o.relativenumber, + ref_opt = true, keys = { shuttle = '[w', toggle_or_open = 'o', diff --git a/lua/lspsaga/util.lua b/lua/lspsaga/util.lua index dc1e77a5e..6cb620fcd 100644 --- a/lua/lspsaga/util.lua +++ b/lua/lspsaga/util.lua @@ -73,6 +73,33 @@ function M.get_client_by_method(method) return supports end +--- generate LSP RPC method `textDocument/references` parameters by configuration. +---@param method string LSP RPC method name +---@param params table parameters for LSP RPC method +---@param config table|boolean configuration for config.finder.ref_opt +---@return table +function M.gen_param_by_config(method, params, config) + if type(config) == 'table' and method == 'textDocument/references' then + local bufnr = vim.api.nvim_get_current_buf() + local clients = lsp.get_clients({ bufnr = bufnr }) + + for _, client in ipairs(clients or {}) do + -- Replace characters dash('-') to underscore('_') for LSP client name, + -- which is useful for some LSP client like `rust-analyzer`. + local client_name = string.gsub(client.name, '-', '_') + local v = vim.tbl_get(config, client_name) + if v ~= nil then + params.context = { + includeDeclaration = v, + } + return { method, params } + end + end + end + + return { method, params } +end + function M.feedkeys(key) local k = api.nvim_replace_termcodes(key, true, false, true) api.nvim_feedkeys(k, 'nx', false)