Skip to content

Commit

Permalink
feat: Create Configuration for IncludeDeclaration (#312)
Browse files Browse the repository at this point in the history
Previously, this setting was defaulted to true. Now, it will only
be set to true for modes that are explicitly named.
  • Loading branch information
rkk1995 committed Jul 25, 2023
1 parent bc6e309 commit 7691d93
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Trouble comes with the following defaults:
auto_preview = true, -- automatically preview the location of the diagnostic. <esc> 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 = "",
Expand Down
1 change: 1 addition & 0 deletions doc/trouble.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Trouble comes with the following defaults:
auto_preview = true, -- automatically preview the location of the diagnostic. <esc> 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 = "",
Expand Down
1 change: 1 addition & 0 deletions lua/trouble/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ local defaults = {
auto_preview = true, -- automatically preview the location of the diagnostic. <esc> 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 = "",
Expand Down
13 changes: 7 additions & 6 deletions lua/trouble/providers/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 7691d93

Please sign in to comment.