Skip to content

Automatic syntax highlighting with .rs files does not work #306

Closed

Description

@yeonsookimdev

rust.vim version:
commit 12f549f

Steps to reproduce:

On CentOS 7, install vim 7.4

# yum install vim-enhance vim-common

Then, install rust.vim using vim-plug

$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

~/.vimrc file:

call plug#begin('~/.vim/plugged')
Plug 'rust-lang/rust.vim', { 'tag' : '12f549f9e4939bca53c8a87e6921a36fb143af9a' }
call plug#end()

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.)
    image

  • Actual:
    With commit 12f549f, vim automatically highlights syntax but it is not for Rust.
    image
    When I run :set syntax=rust manually, then Rust syntax highlight works.

I cannot get additional debug information because :RustInfo failed with E492 error.
image

Activity

  1. changed the title [-]Automatic syntax highlighting with .rs files does not work from 12f549f[/-] [+]Automatic syntax highlighting with .rs files does not work[/+] on Feb 8, 2019
  2. chris-morgan commented on Feb 8, 2019

    @chris-morgan
    Member

    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 setfiletype rust and set filetype=rust.

    Please run this to determine what the filetype actually is on a .rs file, and where it was last set:

    :verbose set filetype?
    

    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 set filetype=rust is still definitely the wrong thing to do, even if this may now explain why it was that way). I’ll think about it more some other time, probably at least a few days hence. If suitable augroup fiddling isn’t possible, maybe we just clobber it iff filetype=hercules.

  3. chris-morgan commented on Feb 8, 2019

    @chris-morgan
    Member

    Oh, and about the :RustInfo: that’s from ftplugin/rust.vim, so it’s only available once you load a Rust file.

  4. yeonsookimdev commented on Feb 11, 2019

    @yeonsookimdev
    Author

    Please run this to determine what the filetype actually is on a .rs file, and where it was last set:

    :verbose set filetype?
    

    @chris-morgan The output of :verbose set filetype? with main.rs is:

      filetype=hercules
            Last set from /usr/share/vim/vim74/filetype.vim
    Press ENTER or type command to continue
    
    
  5. added a commit that references this issue on May 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions