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

.tf filetype detection seems broken in more recent Vim/NeoVim versions? #179

Closed
smheidrich opened this issue Mar 10, 2023 · 3 comments
Closed

Comments

@smheidrich
Copy link

smheidrich commented Mar 10, 2023

I'm running NeoVim 0.7.2 with this plugin installed via vim-plug, but when I open a .tf file, the filetype is just empty. It works fine for .hcl files.

Curiously, if I comment out this line where you disable Vim's native .ft filetype detection, it works. But that seems to be because recent versions of Vim are able to recognize .tf files as Terraform, so with this line removed, Vim's native detection kicks in and sets the filetype:

:autocmd filetypedetect BufRead,BufNewFile *.tf
--- Autocommands ---
filetypedetect  BufReadPost
    *.tf      call dist#ft#FTtf()

So that can't be the underlying issue (although it would probably make sense to have a condition there to let Vim handle this for recent versions, because then users who want to be able to detect both file types denoted by .tf can do so).

Based on Vim's own autocmd being in group filetypedetect, I tried adding filetypedetect as the group for the four autocmds setup by vim-terraform, and that made it detect the filetype correctly as well. But there is probably a reason why you don't have filetypedetect as the group there, so let me know what you think.

@dimbleby
Copy link
Contributor

dimbleby commented Mar 10, 2023

filetype detection is executed from https://github.com/vim/vim/blob/be19d78c3d44221cbc38fbb5bac19302345c1def/runtime/filetype.vim#L2745, which is already inside a group: it is correct not to add another group in our own file.

https://github.com/vim/vim/blob/938ae280c79b8cdb0fca60336ec4c090ecd8bb5a/runtime/doc/filetype.txt#L198-L199

Note that there is no "augroup" command, this has already been done
when sourcing your file.

#133 was a bit similar, the reporter in that was using a plugin manager that messed with the runtime path and not following the associated instructions correctly.

Perhaps you're doing something similar?

@smheidrich
Copy link
Author

I see, thanks for the explanation and the links!

I haven't figured out exactly what's causing this yet but as you explained this plugin is doing everything correctly, so I'll close the ticket.

@smheidrich
Copy link
Author

smheidrich commented Mar 10, 2023

All right, for anyone who has the same issue in the future, the source of the bug in my case was another plugin's (vimoutliner) ftdetect script leaving the augroup filetypedetect context at the end of its execution. I've opened an issue with them here: vimoutliner/vimoutliner#185

I'm sure this is not the only plugin that does this, so again for anyone who has the same issue, it probably makes sense to go into your Vim plugin folder and run rg 'augroup' $(find . -path '*/ftdetect/*.vim') to see if you have any ftdetect scripts that (wrongly) close the augroup.

What pointed me towards this being a potential cause was this comment in Vim's filetype.vim, where it is noted that any of the ftdetect scripts it ran could have ended the augroup context.

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

2 participants