-
Notifications
You must be signed in to change notification settings - Fork 306
Automatic syntax highlighting with .rs files does not work #306
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
Comments
I can’t reproduce this on Vim 8.1.1 on Windows, probably for the reasons mentioned below. This smells like another ftdetect rule butting in first, thereby triggering exactly the deliberate and intended difference between Please run this to determine what the filetype actually is on a .rs file, and where it was last set:
Working from distant memories of such truly ancient versions of Vim worked out of the box, I expect the answer will be hercules from $VIMRUNTIME/filetype.vim. (For I observe even now that my own Vim has it set to rust from $VIMRUNTIME/filetype.vim rather than the rust.vim ftdetect.vim, suggesting that it’s currently basically only working because Vim already knows about Rust.) I shan’t look into it now, but we may need to do some autocmd group rejiggering or something to gain higher priority than it (if that’s possible), without clobbering it altogether (because |
Oh, and about the |
@chris-morgan The output of
|
- `: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
Uh oh!
There was an error while loading. Please reload this page.
rust.vim version:
commit 12f549f
Steps to reproduce:
On CentOS 7, install vim 7.4
Then, install rust.vim using vim-plug
~/.vimrc
file:After saved
~/.vimrc
, run:PlugInstall
in vim or$ vim +PlugInstall +qall
on terminal.Expected vs. actual behavior:
Expected:

When I opened rust source file with .rs extension, for example
main.rs
, then vim automatically highlights Rust syntax.(And this is the actual behavior until commit 329fa78.)
Actual:

With commit 12f549f, vim automatically highlights syntax but it is not for Rust.
When I run
:set syntax=rust
manually, then Rust syntax highlight works.I cannot get additional debug information because

:RustInfo
failed with E492 error.The text was updated successfully, but these errors were encountered: