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

fix: error when adding qf entries from telescope / :vim #8

Closed
wants to merge 1 commit into from
Closed

fix: error when adding qf entries from telescope / :vim #8

wants to merge 1 commit into from

Conversation

Axlefublr
Copy link

Truthfully I have no clue why this error happened and what it implies, but defaulting to zero worked and doesn't seem to give me any issues anymore.
I tried removing my change just now to re-get the error, and yet the bug didn't happen again.

@stevearc
Copy link
Owner

stevearc commented Aug 8, 2024

Hmmm...this could only happen if the quickfix rendered a line without the proper separators. I'd like to dig in more and try to find the root cause, because I think this quick fix will be insufficient if that's actually what's going on.

What does your config look like? Are you lazy loading at all? Could you possibly find a consistent repro so I can check it on my machine?

@Axlefublr
Copy link
Author

Fairly certain now why it happens, and it comes in tandem with #9

So first, I trigger the #9 bug. I then close the qflist.

I try to fill it again via something like :vim;function; % — blammo, error.

So at least in theory this bug shouldn't be your responsibility either; I'll see if changing up guessindent will fix both issues.

@Axlefublr
Copy link
Author

#9 got mostly fixed, but this, turns out, is indeed different, and isn't related to guessindent (I disabled it to test)

Repro:

  1. :vim;function; %
  2. open qflist
  3. close it without doing anything
  4. :vim;target; %
  5. error happens
...cal/share/nvim/lazy/quicker.nvim/lua/quicker/display.lua:195: attempt to perform arithmetic on local 'offset'
 (a nil value)
stack traceback:
^I...cal/share/nvim/lazy/quicker.nvim/lua/quicker/display.lua:195: in function 'add_item_highlights_from_buf'
^I...cal/share/nvim/lazy/quicker.nvim/lua/quicker/display.lua:270: in function <...cal/share/nvim/lazy/quicker.n
vim/lua/quicker/display.lua:228>
^I[C]: in function 'xpcall'
^I...cal/share/nvim/lazy/quicker.nvim/lua/quicker/display.lua:128: in function <...cal/share/nvim/lazy/quicker.n
vim/lua/quicker/display.lua:116>

@Axlefublr
Copy link
Author

This is my plugin configuration:

	{
		'stevearc/quicker.nvim',
		-- lazy = true,
		---@module "quicker"
		---@type quicker.SetupOptions
		opts = {
			keys = {
				{
					'>',
					function() require('quicker').expand({ add_to_existing = true }) end,
					desc = 'Expand quickfix context',
				},
				{
					'<',
					function() require('quicker').collapse() end,
					desc = 'Collapse quickfix context',
				},
			},
		},
	},

I removed lazy = true, but the issue happened in exactly the same way, so it doesn't seem like it was the culprit.
I also did not do either expand or collapse at all, so this issue shouldn't be related to #9.
After this new test, the solution of this PR no longer works. Well, it removes that specific error, but there's a different error after.

@stevearc
Copy link
Owner

stevearc commented Aug 9, 2024

I'm still not able to reproduce the issue. Could you try with a minimal config like the one below

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "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",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
    "stevearc/quicker.nvim",
    ---@module "quicker"
    ---@type quicker.SetupOptions
    opts = {},
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

And, if possible, come up with a file you can source to get a repro, something like

vim.cmd("vim ;function; %")
vim.cmd("copen")
vim.defer_fn(function()
  vim.cmd("cclose")
  vim.defer_fn(function()
    vim.cmd("vim ;target; %")
  end, 1000)
end, 1000)

@Axlefublr
Copy link
Author

You mention :cclose, but it was never actually obvious to me — I have a mapping for q! that I use to close every possible window, including the qflist one.
So! The repro is the repro.lua you suggested (1 for 1, no changes to it at all)

  1. vim;function; %
  2. :copen
  3. :q!
  4. vim;target; %
  5. Error happens

Thank you for your patience and good suggestions for how to repro better, I wouldn't arrive at this without you I don't think.
I don't think you can do much about the user doing :q!, I assume you have some events to run on :cclose or the like, and they don't happen with :q!. So I don't expect you to fix it, I'll probably just specialcase my mapping to do :cclose if it's in a qf window.
However I would be very interested to hear any "inside info" about this, and why it works this way. Would probably be a good idea to include in the readme something like:
"you should be using the plugin's toggle() functionality or :cclose to close the qflist, regardless of whether you interacted with it or not; otherwise, you'll get errors"

@stevearc
Copy link
Owner

Great, I think I've found the root cause and fixed it in a more graceful way. Can you try out the latest version and LMK if you still have the issue?

@Axlefublr
Copy link
Author

omg it works!! thank you so much :D

@stevearc stevearc closed this Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants