Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug v3: Order of entries changes, when jumping to next entry in a trouble telescope or quickfix list #399

Open
3 tasks done
tummetott opened this issue Mar 29, 2024 · 4 comments
Labels

Comments

@tummetott
Copy link

tummetott commented Mar 29, 2024

Did you check docs and existing issues?

  • I have read all the trouble.nvim docs
  • I have searched the existing issues of trouble.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

NVIM v0.9.5 Build type: Release LuaJIT 2.1.1703358377

Operating system/version

MacOs 14.2.1

Describe the bug

Lets say I have the 4 files a b c, d opened in a trouble window (e.g. from Telescope from a Quickfix list, it does not matter).
When I execute :lua require'trouble'.next({jump=true}) a few times, the order of the trouble list changes.

Steps To Reproduce

  1. mkdir test && cd test
  2. touch a b c d
  3. nvim -u path/to/repro.lua
  4. :Telescope find_files
  5. Press <C-q> to open all files in a trouble window
  6. :lua require'trouble'.next({jump=true})
  7. :lua require'trouble'.next({jump=true})
    --> The order is already messed up

this also happens with quickfix lists.

BTW: what is the difference between :Trouble qflist and :Trouble quickfix ?? i can open two trouble windows, showing the same content?

Expected Behavior

Order should not change.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    "folke/tokyonight.nvim",
    {
        "folke/trouble.nvim",
        branch = "dev",
        lazy = false,
        opts = {
            follow = false,
            restore = true,
            auto_preview = false,
            auto_refresh = false,
        },
    },
    {
        'nvim-telescope/telescope.nvim',
        dependencies = { 'nvim-lua/plenary.nvim' },
        config = function()
            local open_with_trouble = require("trouble.sources.telescope").open
            require('telescope').setup {
                defaults = {
                    mappings = {
                        i = {
                            ['<C-q>'] = open_with_trouble,
                        }
                    }
                }
            }
        end,
    }
    -- add any other plugins here
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
@bellini666
Copy link
Contributor

Started to migrate to v3, experiencing the same issue

@folke
Copy link
Owner

folke commented Mar 29, 2024

That's actually because of the default sort for some sources.

This is the default for diagnostics for example:

      sort = { { buf = 0 }, "severity", "filename", "pos", "message" },

The first item of the sorter will sort items from your current buffer to the top.

You can change it with:

{
  modes = {
    diagnostics = {
              sort = { "severity", "filename", "pos", "message" },
     }
  }
}

I'll keep this issue open for now, since the default doesn't work well indeed for going to next/previous items

@folke
Copy link
Owner

folke commented Mar 29, 2024

And quickfix is the same as qflist.
I don't fully rememeber, but I probably kept that for backward compatibility.

@tummetott
Copy link
Author

would it make sense then to make the following defaults?

modes = {
    telescope = {
        sort = { "pos", "filename", "severity", "message" },
    },
    quickfix = {
        sort = { "pos", "filename", "severity", "message" },
    },
    loclist = {
        sort = { "pos", "filename", "severity", "message" },
    },
    todo = {
        sort = { "pos", "filename", "severity", "message"}
    },
}

I guess it makes sense for diagnostics that they sort every time you move or jump inside the list, since fixing lsp errors is a continuous task. But for quickfix, loclist, todo comments (which have imho no severity?) and telescope results its quite confusing when the order changes every time you move

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants