Open ecogest opened 3 years ago
Thanks for your report! Just to verify, your version of Neovim is after this PR, right? https://github.com/neovim/neovim/pull/15295
Assuming so, this is probably a bug with https://github.com/wbthomason/packer.nvim/blob/257d6d30e4bd4ab8f5d2a40d73a9f1a4a65779fc/lua/packer/load.lua#L110-L114 or https://github.com/wbthomason/packer.nvim/blob/257d6d30e4bd4ab8f5d2a40d73a9f1a4a65779fc/lua/packer/load.lua#L41-L45
I suspect the former snippet more because you say that you can reproduce this issue with or without files in after/
. To eliminate the second candidate, would you mind sharing your compiled file? (the files which that block sources are listed in the compiled output)
The last time we changed something in the first candidate seems to have been #533. I am surprised that you're not seeing the double-load in scriptnames
, too.
Thanks for your reply ! I reproduced the issue with the minimum number of plugins :
Bottom line : vim test.js
, echo b:count
-> 2
On the contrary if I do not use ft = {'javascript'} (use {'pangloss/vim-javascript'}
):
vim test.js
, echo b:count
-> 1
And for the first question yes, I am using the HEAD version, I updated it before posting this issue. (Built from source on 2021-10-12 at 14:05:11).
Thanks! This is thoroughly bizarre. I actually get b:count = 3
when I try to reproduce this, which is even weirder. It looks like I get b:count = 2
without any ft
loading, so I'm still seeing the same issue as you, but with a confounding factor of some other source executing my after/ftplugin
files.
Ok, I might know what's going on, if not how to fix it:
Neovim itself sources filetype
and after/filetype
files when you load a file with a detectable filetype, as expected. packer
additionally triggers FileType
for the relevant filetype when loading a plugin by ft
because that plugin may have its own ftplugin
or after/ftplugin
files. However, this causes the double-sourcing that you're seeing, which I suppose hasn't been reported before because ftplugin
is chronically underused by most people.
As to fixing this: packadd
hypothetically doesn't source ftplugin
files, though I'll need to check that the docs match actual behavior here. That means that packer
still needs to source a plugin's ftplugin
files if they exist.
The solution here is probably to stop blindly triggering FileType
and instead, at compile time, check if a plugin has anything in ftplugin
, etc. and manually source these paths. The downside to that approach is that if a plugin adds ftplugin
files in an update between compiles, they won't be found, causing misbehavior and pointing to yet another reason that I really need to find time to refactor packer
to auto-recompile.
nvim --version
:Features: +acl +iconv +tui
vim test.cc
,echo b:count
Actual behaviour
Counted twice (
b:count
equals 2). Hence the file in ftplugin has been loaded twice. Note: when I run:scriptnames
, I don't see it loaded twice though...Expected behaviour
The file should be loaded once. For example, if you use
use {'alepez/vim-gtest'}
(without ft = 'cpp'), it is working correctly (~/.config/nvim/ftplugin/after/cpp.vim
loaded only once,b:count
equals 1).Due to this issue, the options I set in after/ftplugin, get overwritten for some filetypes (I use a guard so that it is not loaded twice). I don't really understand how, but some other ftplugin files, which should be loaded before, manage then to overwrite my own in the
after
folder...packer files
packer log file
Post the contents of ~/.cache/nvim/packer.nvim.log here : emptythanks anyway
Thank you so much for packer, I find it awesome 😉 !