From 7691d93131be9c4ef7788892a9c52374642beb89 Mon Sep 17 00:00:00 2001 From: rkk1995 <50536089+rkk1995@users.noreply.github.com> Date: Tue, 25 Jul 2023 13:38:10 -0400 Subject: [PATCH] feat: Create Configuration for IncludeDeclaration (#312) Previously, this setting was defaulted to true. Now, it will only be set to true for modes that are explicitly named. --- README.md | 1 + doc/trouble.nvim.txt | 1 + lua/trouble/config.lua | 1 + lua/trouble/providers/lsp.lua | 13 +++++++------ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9ee8a952..85483226 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ Trouble comes with the following defaults: auto_preview = true, -- automatically preview the location of the diagnostic. to close preview and go back to last window auto_fold = false, -- automatically fold a file trouble list at creation auto_jump = {"lsp_definitions"}, -- for the given modes, automatically jump if there is only a single result + include_declaration = { "lsp_references", "lsp_implementations", "lsp_definitions" }, -- for the given modes, include the declaration of the current symbol in the results signs = { -- icons / text used for a diagnostic error = "", diff --git a/doc/trouble.nvim.txt b/doc/trouble.nvim.txt index 2853ca37..e239e714 100644 --- a/doc/trouble.nvim.txt +++ b/doc/trouble.nvim.txt @@ -117,6 +117,7 @@ Trouble comes with the following defaults: auto_preview = true, -- automatically preview the location of the diagnostic. to close preview and go back to last window auto_fold = false, -- automatically fold a file trouble list at creation auto_jump = {"lsp_definitions"}, -- for the given modes, automatically jump if there is only a single result + include_declaration = { "lsp_references", "lsp_implementations", "lsp_definitions" }, -- for the given modes, include the declaration of the current symbol in the results signs = { -- icons / text used for a diagnostic error = "", diff --git a/lua/trouble/config.lua b/lua/trouble/config.lua index a57c1d13..91a38212 100644 --- a/lua/trouble/config.lua +++ b/lua/trouble/config.lua @@ -51,6 +51,7 @@ local defaults = { auto_preview = true, -- automatically preview the location of the diagnostic. to close preview and go back to last window auto_fold = false, -- automatically fold a file trouble list at creation auto_jump = { "lsp_definitions" }, -- for the given modes, automatically jump if there is only a single result + include_declaration = { "lsp_references", "lsp_implementations", "lsp_definitions" }, -- for the given modes, include the declaration of the current symbol in the results signs = { -- icons / text used for a diagnostic error = "", diff --git a/lua/trouble/providers/lsp.lua b/lua/trouble/providers/lsp.lua index d9794d4f..536299ea 100644 --- a/lua/trouble/providers/lsp.lua +++ b/lua/trouble/providers/lsp.lua @@ -11,10 +11,11 @@ local function lsp_buf_request(buf, method, params, handler) end ---@return Item[] -function M.references(win, buf, cb, _options) +function M.references(win, buf, cb, options) local method = "textDocument/references" local params = util.make_position_params(win, buf) - params.context = { includeDeclaration = true } + params.context = { includeDeclaration = vim.tbl_contains(options.include_declaration, options.mode) } + lsp_buf_request(buf, method, params, function(err, result) if err then util.error("an error happened getting references: " .. err.message) @@ -29,10 +30,10 @@ function M.references(win, buf, cb, _options) end ---@return Item[] -function M.implementations(win, buf, cb, _options) +function M.implementations(win, buf, cb, options) local method = "textDocument/implementation" local params = util.make_position_params(win, buf) - params.context = { includeDeclaration = true } + params.context = { includeDeclaration = vim.tbl_contains(options.include_declaration, options.mode) } lsp_buf_request(buf, method, params, function(err, result) if err then util.error("an error happened getting implementation: " .. err.message) @@ -47,10 +48,10 @@ function M.implementations(win, buf, cb, _options) end ---@return Item[] -function M.definitions(win, buf, cb, _options) +function M.definitions(win, buf, cb, options) local method = "textDocument/definition" local params = util.make_position_params(win, buf) - params.context = { includeDeclaration = true } + params.context = { includeDeclaration = vim.tbl_contains(options.include_declaration, options.mode) } lsp_buf_request(buf, method, params, function(err, result) if err then util.error("an error happened getting definitions: " .. err.message)