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

Fix: Ensure filetype is set for Go templates #3146

Merged
merged 1 commit into from
Mar 28, 2021

Conversation

PaulDugdale
Copy link
Contributor

*.tmpl is already detected and a filetype is already set here:
https://github.com/vim/vim/blob/e0e3917554327f2524066f89fbbef9c83c1535da/runtime/filetype.vim#L744

Using setfiletype prevents this from being overridden, and the filetype is left as "template" and not set to "gohtmltmpl" as intended.

Screenshot 2021-01-26 at 15 07 18

*.tmpl is already detected in vim/runtime/filetype.vim
Using `setfiletype` prevents overriding
@bhcleek
Copy link
Collaborator

bhcleek commented Feb 10, 2021

I'm not sure we should override what Vim is doing with the filetype. 🤔

@PaulDugdale
Copy link
Contributor Author

Thanks! Here's some more info...

With the vim-go plugin installed, I expect the syntax and indentation to work correctly on Go text/html template files.
This isn't the case, the standard Vim html syntax/indentation will be used.

The problem is that there is already a template filetype in vim, that is a simple wrapper around the html filetype.

Because of this, and the fact thatsetfiletype is used, the gotexttmpl and gohtmltmpl filetypes will never be used unless they are forced in your .vimrc

This used to work until this change

@bhcleek
Copy link
Collaborator

bhcleek commented Feb 25, 2021

My concern is that there may be a lot of people that do edit html template files and that use .tmpl as an extension for those files. Since vim-go sets the template filetype based on a wildcard pattern (as opposed to a specific file name like go.sum uses), I'm reluctant to unconditionally override.

I think I'd prefer a solution that changes vim-go to use setfiletype with a different extension (e.g. *.go.tmpl, *.gotmpl, etc.) or that users that really want this put the au BufRead,BufNewFile *.tmpl set filetype gohtmltmpl in their own vimrc file.

@PaulDugdale
Copy link
Contributor Author

I understand the concerns, but I respectfully disagree...

The .tmpl has been given "official" blessing in both the Golang examples, and the Golang team maintained VSCode extension, so I think it's better to use .tmpl than an alternate extension.
I also think that leaving it in it's current state will break syntax/indentation for more users than changing it would. It's a very common extension inside of Go, and a very unusual one outside of it.

@bhcleek bhcleek added this to the vim-go 1.25 milestone Mar 28, 2021
@bhcleek bhcleek merged commit 65c0079 into fatih:master Mar 28, 2021
bhcleek added a commit that referenced this pull request Mar 28, 2021
@bhcleek
Copy link
Collaborator

bhcleek commented Mar 28, 2021

Since the default filetype for .tmpl files is template and since it seems to be a subset of what vim-go uses for the the .tmpl, this change is appears to be purely additive and reasonably safe. I'm not super keen on doing this unconditionally, but let's see if anyone complains.

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

Successfully merging this pull request may close these issues.

2 participants