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

Add Option to Override Filetypes #14

Closed
1 task done
l-zeuch opened this issue Jan 31, 2022 · 5 comments · Fixed by #32
Closed
1 task done

Add Option to Override Filetypes #14

l-zeuch opened this issue Jan 31, 2022 · 5 comments · Fixed by #32
Labels
type/bug Something isn't working type/enhancement New feature or request
Milestone

Comments

@l-zeuch
Copy link
Owner

l-zeuch commented Jan 31, 2022

Expected Behaviour

When entering NVim with a *.go.tmpl file, it is expected that the plugin changes the filetype to yagpdbcc, thus granting syntax highlighting.

Actual Behaviour

Instead, the filetype remains on gohtmltmpl, which seems to be set by (Neo)vim itself.

Steps to Reproduce

(Make sure the plugin is loaded already or loads on-demand)

$ nvim demo.go.tmpl
:set verbose ft?

See ft=gohtmltmpl instead of ft=yagpdbcc.

Additional Context

$ nvim --version
NVIM v0.6.1
Build type: Release
LuaJIT 2.0.5
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

I'm not entirely sure where to begin troubleshooting -- I suspect the double extension is throwing our code off.

Code of Conduct

  • I agree to follow this project's Code of Conduct.
@l-zeuch l-zeuch added the type/bug Something isn't working label Jan 31, 2022
@l-zeuch
Copy link
Owner Author

l-zeuch commented Jan 31, 2022

Update: Apparently I have a competing plugin installed, which sets the filetype:

https://github.com/fatih/vim-go/blob/430bc227654abc3eb5e27a9052a857344ca08cdc/ftdetect/gofiletype.vim#L10

I'll investigate further with that plugin disabled.

@LRitzdorf
Copy link
Collaborator

I get a filetype of template, with no plugin interference.

Initial thoughts: our plugin bails out if any filetype has already been set. We could qualify that behavior to take over anyway if the extension is .go.tmpl (maybe dependent upon a variable that the user would set in their init.vim?)

@l-zeuch
Copy link
Owner Author

l-zeuch commented Feb 1, 2022

I get a filetype of template, with no plugin interference.

Okay, this tells us that we did something wrong with regards to the detection of filetypes. I suspect that the following code snippet does not work as we expect it to.

au! BufWrite,BufNewFile *.go.tmpl setfiletype yagpdbcc

As far as I aware, the issue lies within the double extension. vim-go circumvents this issue by triggering on just *.tmpl.
Perhaps it is worthwhile to do so as well?

Initial thoughts: our plugin bails out if any filetype has already been set. We could qualify that behavior to take over anyway if the extension is .go.tmpl (maybe dependent upon a variable that the user would set in their init.vim?)

I agree, such a configuration variable could be useful. However, there are a plethora of other plugins out there, and as far as I am aware, none of them do something similar. Thus I am currently kind of reluctant to implement such a configuration, simply because it seems to go against the general consensus.

@l-zeuch l-zeuch added type/enhancement New feature or request type/bug Something isn't working and removed type/bug Something isn't working labels Feb 1, 2022
@l-zeuch l-zeuch changed the title [Bug]: Plugin not triggering on *.go.tmpl file extensions Add Option to Override Filetypes Feb 1, 2022
@LRitzdorf
Copy link
Collaborator

Hm, interesting point about consensus there. I'm aware of other plugins (vim-airline, for example) that change their behavior based on variables. I do agree that using this to change whether we claim a specific filetype as our own is unorthodox, though.

Relatedly, what happens if we claim an extension that other plugins also claim? If they're loaded first, our plugin will bail out (as we've established), but what determines that loading order? We want to make sure we have reliable behavior, of course.

@l-zeuch
Copy link
Owner Author

l-zeuch commented Feb 2, 2022

Relatedly, what happens if we claim an extension that other plugins also claim? If they're loaded first, our plugin will bail out (as we've established), but what determines that loading order? We want to make sure we have reliable behavior, of course.

Honestly, not quite sure about that. My first guess would be the order they're added to the runtime path, with the last one taking precedence. I'd have to investigate.

l-zeuch added a commit that referenced this issue Mar 18, 2022
This commit adds a configuration variable to override a detected filetype
for certain extensions which are also used in the context of writing yagpdb
custom commands.

Closes #14
@LRitzdorf LRitzdorf linked a pull request Mar 18, 2022 that will close this issue
2 tasks
l-zeuch added a commit that referenced this issue Mar 18, 2022
* ftdetect: add override capabilities

This commit adds a configuration variable to override a detected filetype
for certain extensions which are also used in the context of writing yagpdb
custom commands.

Closes #14

* editorconfig: set max text width

All files except markdown files should not exceed 80 characters per line, for legacy
/specification reasons. Markdown files should not exceed 120 characters.

* all: consistent file naming

There was one inconsistency with regards to the file naming within this
repository -- we named files/folders with yagpdbcc, however this file
was named yagpdb. This commit fixes that.

* ftdetect: fix spacing issues, clarify usage in README

* ftdetect: remove an improper `did_load_filetypes` check

Co-authored-by: Lucas Ritzdorf <42657792+LRitzdorf@users.noreply.github.com>
@l-zeuch l-zeuch modified the milestones: Backlog, Done May 29, 2022
@l-zeuch l-zeuch modified the milestones: Done, Backlog Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working type/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants