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

Error in neovim #18

Closed
baodrate opened this issue Oct 11, 2023 · 9 comments
Closed

Error in neovim #18

baodrate opened this issue Oct 11, 2023 · 9 comments

Comments

@baodrate
Copy link

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
@itchyny
Copy link
Contributor

itchyny commented Oct 17, 2023

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

@vito-c
Copy link
Owner

vito-c commented Oct 17, 2023

I'm going to back out the previous PR

@Freed-Wu
Copy link
Contributor

Similar problem like raimon49/requirements.txt.vim#38. What is your minimum vimrc to reproduce?

@vito-c
Copy link
Owner

vito-c commented Oct 17, 2023

@itchyny does the latest master work for you now?

@itchyny
Copy link
Contributor

itchyny commented Oct 17, 2023

Yes, it works after reverting.

@Freed-Wu
Copy link
Contributor

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

@vito-c
Copy link
Owner

vito-c commented Jan 26, 2024

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

@baodrate
Copy link
Author

baodrate commented May 1, 2024

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:

function! s:DetectJQ()
if did_filetype() && &filetype !=# 'conf'
return
endif
call jq#shebang()
endfunction
au BufNewFile,BufRead *.jq,.jqrc*,jqrc set filetype=jq
au BufNewFile,BufRead * call s:DetectJQ()

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",
	}
})

@vito-c
Copy link
Owner

vito-c commented May 2, 2024

@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 vito-c closed this as completed May 2, 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

No branches or pull requests

4 participants