micangl / cmp-vimtex

Vimtex source for nvim-cmp.
MIT License
78 stars 5 forks source link

fixed error during lauch #12

Closed Waschbaar closed 8 months ago

Waschbaar commented 8 months ago

After setting up the autocmd, the function _start_parser will be called for the current buffer. There's no reason to call it again. And calling the function from init.lua leads to a problem to the code vim.loop.fs_stat(vim.b.vimtex.root) at line 69 in source.lua since b:vimtex can be nil at this point. Removing the redundant call to _start_parser resolves the issue.

micangl commented 8 months ago

The fact is that the parser needs to be called for files opened from the editor (for example with :vs) too. When the autocommand is set, the FileType should already have been called, so that the parser is started only once by the function you deleted.

But, if a file is opened subsequently, then the autocommand will be executed.

So, this seems to be a problem with the way you load the plugin (maybe some aggressive lazy-loading). You could take a look at Lervag's configuration.

Waschbaar commented 8 months ago

I have worked a bit more to isolate the problem. It turns out that I configured lazy.nvim to load cmp-vimtex only for tex filetype and this lazy loading caused the problem. I'm closing this pull request but I think it's an issue to be addressed since I don't want to load the plugin for anything other than tex files.

micangl commented 8 months ago

I'm closing this pull request but I think it's an issue to be addressed since I don't want to load the plugin for anything other than tex files.

I thoroughly agree with you but, unfortunately, I don't use lazy and I'm quite swamped at the moment.

In the future, when I have enough time, I'll try to fix it. In the meantime, maybe @lervag knows of a quick fix for this problem, as he uses lazy and made the original PR to fix the issue I mentioned.

lervag commented 8 months ago

I have worked a bit more to isolate the problem. It turns out that I configured lazy.nvim to load cmp-vimtex only for tex filetype and this lazy loading caused the problem. I'm closing this pull request but I think it's an issue to be addressed since I don't want to load the plugin for anything other than tex files.

I also agree that it should be possible to lazy load cmp-vimtex. On my end, it seems cmp-vimtex requires about 1 ms to load, which is not really a big problem; although notice that VimTeX itself takes only 0.48 ms. VimTeX can't be lazy loaded, because there's a feature that requires "global presence", but VimTeX is lazy by design since the code will not be sourced unless necessary.

In the future, when I have enough time, I'll try to fix it. In the meantime, maybe @lervag knows of a quick fix for this problem, as he uses lazy and made the original PR to fix the issue I mentioned.

I can take a look, but I won't promise anything. I don't have much time these days.

micangl commented 8 months ago

@Waschbaar I have merged lervag's fix in the fix_12 branch. Could you check if the fix is working for you?

NOTE: Make sure to specify the correct branch with your plugin manager.

Waschbaar commented 8 months ago

It works for me.