jq.vim icon indicating copy to clipboard operation
jq.vim copied to clipboard

Error in neovim

Open baodrate opened this issue 2 years ago • 6 comments

the merge of PR #17 causes an error in neovim (at least v0.9):

Error detected while processing BufReadPost Autocommands for "*"..function <SNR>9_DetectJQ:
line    4:
E117: Unknown function: jq#shebang

baodrate avatar Oct 11 '23 00:10 baodrate

@vito-c (CC @Freed-Wu) I'm facing this issue, too. Please do not expect autoload scripts in ftdetect scripts.

itchyny avatar Oct 17 '23 01:10 itchyny

I'm going to back out the previous PR

vito-c avatar Oct 17 '23 04:10 vito-c

Similar problem like https://github.com/raimon49/requirements.txt.vim/issues/38. What is your minimum vimrc to reproduce?

Freed-Wu avatar Oct 17 '23 06:10 Freed-Wu

@itchyny does the latest master work for you now?

vito-c avatar Oct 17 '23 16:10 vito-c

Yes, it works after reverting.

itchyny avatar Oct 17 '23 22:10 itchyny

Hey, can anyone provide a minimum vimrc to reproduce the bug? I cannot trigger this bug.

Freed-Wu avatar Oct 19 '23 05:10 Freed-Wu

@itchyny @baod-rate do you happen to have a simplified version of the file you were using?

vito-c avatar Jan 26 '24 18:01 vito-c

I believe the issue (at least, my issue) is when using lazy.nvim's lazy setting (see the section: Startup Sequence). Although I imagine this impacts other methods of lazy-loading as well. jq.vim's ftdetect is sourced in the "handlers" step of lazy's init sequence, regardless of the plugin's lazy setting. this means that call jq#shebang() is executed while opening any file:

https://github.com/vito-c/jq.vim/blob/e09bc06f8dee6ae4a5bdbc4c062ac394636c54dc/ftdetect/jq.vim#L1-L9

even though autoload/jq.vim is not (yet) in the runtimepath.

I only thing to do here to fix this is perhaps noting that users should avoid lazy=true with jq.vim when using lazy.nvim (and other plugin managers). But perhaps it's best to avoid autoload functions in the ftdetect script altogether, especially since the autocmd loads and executes the function on any buffer anyways.

edit: for the record, a minimal init.lua to reproduce this error:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  -- bootstrap lazy.nvim
  -- stylua: ignore
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)

require("lazy").setup({
	{
		"vito-c/jq.vim",
		lazy = true,
		tag = "v1.0.3",
		ft = "jq",
	}
})

baodrate avatar May 01 '24 16:05 baodrate

@baod-rate that is a nice summary of the issue and I think it explains why having the autoload in ftdetect script would cause an error. Thank you for reporting your findings. I have also added support for the jq filetype in vim. So this plugin will get any latest additions but after the next release of vim there the support should be built in. I'm not sure how often neovim pulls in vim changes but I imagine the changes will show up there soon as well.

vito-c avatar May 02 '24 16:05 vito-c