jq.vim
jq.vim copied to clipboard
Error in neovim
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
@vito-c (CC @Freed-Wu) I'm facing this issue, too. Please do not expect autoload scripts in ftdetect scripts.
I'm going to back out the previous PR
Similar problem like https://github.com/raimon49/requirements.txt.vim/issues/38. What is your minimum vimrc to reproduce?
@itchyny does the latest master work for you now?
Yes, it works after reverting.
Hey, can anyone provide a minimum vimrc to reproduce the bug? I cannot trigger this bug.
@itchyny @baod-rate do you happen to have a simplified version of the file you were using?
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",
}
})
@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.