Skip to content

Conversation

mhinz
Copy link
Contributor

@mhinz mhinz commented Apr 28, 2019

  • :set filetype forces a filetype.
  • :setfiletype only sets a filetype if it didn't already happen earlier due to
    the same event.

Current versions of Vim and Neovim have a $VIMRUNTIME/filetype.vim that sets
the rust filetype for all files with an .rs extension.

This plugin did that with set filetype=rust as well. But now, with the
filetype getting set twice, ftplugin/rust/* was sourced twice as well.

This got fixed in #301 by changing
set filetype=rust to setfiletype rust.

But that fix introduced a regression for all older Vim versions. There is still
a lot of Vim 7.4 around and Debian stable still provides Nvim 0.1.7, both being
very old versions.

The $VIMRUNTIME/filetype.vim of these old versions set the filetype to
hercules for all .rs files via setfiletype hercules.

Now, usually (it also depends on how plugins gets sourced) filetype.vim gets
sourced before any ftdetect/* files from plugins. And since autocmds are
processed in order, Vim would first do setfiletype hercules and so any
subsequent setfiletype rust fails.

The obvious solution: Force the rust filetype for all .rs extensions unless
the filetype is already set to rust.

So, we have the filetype setting working again for older versions and also avoid
setting the filetype twice.

Fixes #306
Fixes #318

- `:set filetype` forces a filetype.
- `:setfiletype` only sets a filetype if it didn't already happen earlier due to
the same event.

Current versions of Vim and Neovim have a `$VIMRUNTIME/filetype.vim` that sets
the `rust` filetype for all files with an `.rs` extension.

This plugin did that with `set filetype=rust` as well. But now, with the
filetype getting set twice, `ftplugin/rust/*` was sourced twice as well.

This got fixed in #301 by changing
`set filetype=rust` to `setfiletype rust`.

But that fix introduced a regression for all older Vim versions. There is still
a lot of Vim 7.4 around and Debian stable still provides Nvim 0.1.7, both being
very old versions.

The `$VIMRUNTIME/filetype.vim` of these old versions set the filetype to
`hercules` for all `.rs` files via `setfiletype hercules`.

Now, usually (it also depends on how plugins gets sourced) `filetype.vim` gets
sourced _before_ any `ftdetect/*` files from plugins. And since autocmds are
processed in order, Vim would first do `setfiletype hercules` and so any
subsequent `setfiletype rust` fails.

The obvious solution: Force the `rust` filetype for all `.rs` extensions unless
the filetype is already set to `rust`.

So, we have the filetype setting working again for older versions and also avoid
setting the filetype twice.

Fixes #306
Fixes #318
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @chris-morgan (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@da-x da-x merged commit 53f40ec into rust-lang:master May 19, 2019
@da-x
Copy link
Member

da-x commented May 19, 2019

Thanks! It reminds me we should have some automated regression testing. At least the basic plugin functionality should work.

@mhinz mhinz deleted the filetype branch May 25, 2019 14:58
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.

Plugin appears not to get loaded by neovim Automatic syntax highlighting with .rs files does not work
4 participants