diff --git a/README.md b/README.md index 6f153e9..ebf7843 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,10 @@ null_ls.setup { Will enable `:lua vim.lsp.buf.code_action()` to retrieve code actions from Gitsigns. Alternatively if you have [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) installed, you can use `:Telescope lsp_code_actions`. +### [trouble.nvim](https://github.com/folke/trouble.nvim) + +If installed and enabled (via `config.trouble`; defaults to true if installed), `:Gitsigns setqflist` or `:Gitsigns seqloclist` will open Trouble instead of Neovim's built-in quickfix or location list windows. + ## Similar plugins - [coc-git](https://github.com/neoclide/coc-git) diff --git a/doc/gitsigns.txt b/doc/gitsigns.txt index f123783..9746944 100644 --- a/doc/gitsigns.txt +++ b/doc/gitsigns.txt @@ -708,6 +708,12 @@ current_line_blame_formatter *gitsigns-config-current_line_blame_formatter* The result of this function is passed directly to the `opts.virt_text` field of |nvim_buf_set_extmark|. +trouble *gitsigns-config-trouble* + Type: `boolean`, Default: true if installed + + When using setqflist() or setloclist(), open Trouble instead of the + quickfix/location list window. + yadm *gitsigns-config-yadm* Type: `table`, Default: `{ enable = false }` diff --git a/lua/gitsigns/actions.lua b/lua/gitsigns/actions.lua index 279f65e..6438f93 100644 --- a/lua/gitsigns/actions.lua +++ b/lua/gitsigns/actions.lua @@ -703,10 +703,18 @@ M.setqflist = void(function(target, opts) if opts.use_location_list then local nr = opts.nr or 0 vim.fn.setloclist(nr, {}, ' ', qfopts) - vim.cmd([[lopen]]) + if config.trouble then + require('trouble').open("loclist") + else + vim.cmd([[lopen]]) + end else vim.fn.setqflist({}, ' ', qfopts) - vim.cmd([[copen]]) + if config.trouble then + require('trouble').open("quickfix") + else + vim.cmd([[copen]]) + end end end) diff --git a/lua/gitsigns/config.lua b/lua/gitsigns/config.lua index 45b2155..6408a1d 100644 --- a/lua/gitsigns/config.lua +++ b/lua/gitsigns/config.lua @@ -89,6 +89,8 @@ local M = {Config = {DiffOpts = {}, SignsConfig = {}, watch_gitdir = {}, current + + @@ -536,6 +538,19 @@ M.schema = { ]], }, + trouble = { + type = 'boolean', + default = function() + local has_trouble = pcall(require, 'trouble') + return has_trouble + end, + default_help = "true if installed", + description = [[ + When using setqflist() or setloclist(), open Trouble instead of the + quickfix/location list window. + ]], + }, + yadm = { type = 'table', default = { enable = false }, diff --git a/teal/gitsigns/actions.tl b/teal/gitsigns/actions.tl index b76c6e6..5fc9540 100644 --- a/teal/gitsigns/actions.tl +++ b/teal/gitsigns/actions.tl @@ -703,10 +703,18 @@ M.setqflist = void(function(target: integer|string, opts: M.QFListOpts) if opts.use_location_list then local nr = opts.nr or 0 vim.fn.setloclist(nr, {}, ' ', qfopts) - vim.cmd[[lopen]] + if config.trouble then + require'trouble'.open("loclist") + else + vim.cmd[[lopen]] + end else vim.fn.setqflist({}, ' ', qfopts) - vim.cmd[[copen]] + if config.trouble then + require'trouble'.open("quickfix") + else + vim.cmd[[copen]] + end end end) diff --git a/teal/gitsigns/config.tl b/teal/gitsigns/config.tl index 54d32ee..c75e0fc 100644 --- a/teal/gitsigns/config.tl +++ b/teal/gitsigns/config.tl @@ -80,6 +80,8 @@ local record M enable: boolean end + trouble: boolean + -- Undocumented word_diff: boolean _refresh_staged_on_update: boolean @@ -536,6 +538,19 @@ M.schema = { ]] }, + trouble = { + type = 'boolean', + default = function(): boolean + local has_trouble = pcall(require, 'trouble') + return has_trouble + end, + default_help = "true if installed", + description = [[ + When using setqflist() or setloclist(), open Trouble instead of the + quickfix/location list window. + ]] + }, + yadm = { type = 'table', default = { enable = false }, diff --git a/types/trouble.d.tl b/types/trouble.d.tl new file mode 100644 index 0000000..17c77f1 --- /dev/null +++ b/types/trouble.d.tl @@ -0,0 +1,5 @@ +local record Trouble + open: function(mode: string) +end + +return Trouble