rust-lang / rust.vim

Vim configuration for Rust.
Apache License 2.0
3.91k stars 297 forks source link

Tags in tagbar are messed up #353

Open AaronM04 opened 5 years ago

AaronM04 commented 5 years ago

Steps to reproduce:

  1. Open up a Rust file
  2. Toggle the tagbar with :Tagbar

Expected vs. actual behavior:

Expected: methods grouped by struct/trait, with no duplicates. Also I expected fields to be listed with public/private indicators.

Actual: methods and top-level functions are mixed together, and each appears twice. No fields are visible for the structs.

Paste debugging info from the Rust Vim plugin via one of the following commands: :RustInfo, :RustInfoToClipboard, or :RustInfoToFile <filename>.

rust.vim Global Variables:
let g:ftplugin_rust_source_path = v:null
let g:loaded_syntastic_rust_cargo_checker = v:null
let g:loaded_syntastic_rust_filetype = v:null
let g:loaded_syntastic_rust_rustc_checker = v:null
let g:rust_bang_comment_leader = v:null
let g:rust_cargo_avoid_whole_workspace = v:null
let g:rust_clip_command = v:null
let g:rust_conceal = v:null
let g:rust_conceal_mod_path = v:null
let g:rust_conceal_pub = v:null
let g:rust_fold = v:null
let g:rust_last_args = v:null
let b:rust_last_args = []
let g:rust_last_rustc_args = v:null
let b:rust_last_rustc_args = []
let g:rust_original_delimitMate_excluded_regions = v:null
let g:rust_playpen_url = v:null
let g:rust_prev_delimitMate_quotes = v:null
let g:rust_recent_nearest_cargo_tol = v:null
let g:rust_recent_root_cargo_toml = v:null
let g:rust_recommended_style = v:null
let g:rust_set_conceallevel = v:null
let g:rust_set_conceallevel=1 = v:null
let g:rust_set_foldmethod = v:null
let g:rust_set_foldmethod=1 = v:null
let g:rust_shortener_url = v:null
let g:rustc_makeprg_no_percent = v:null
let g:rustc_path = v:null
let g:rustfmt_autosave = 0
let g:rustfmt_autosave_if_config_present = v:null
let g:rustfmt_command = 'rustfmt'
let g:rustfmt_emit_files = 1
let g:rustfmt_fail_silently = 0
let g:rustfmt_emit_files = 1
let g:rustfmt_fail_silently = 0
let g:rustfmt_options = ''
let g:syntastic_extra_filetypes = ['rust']
let g:syntastic_rust_cargo_fname = v:null
rustfmt 1.3.0-stable (d334502 2019-06-09)
rustc 1.37.0 (eae3437df 2019-08-13)
cargo 1.37.0 (9edd08916 2019-08-02)

VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 23 2019 11:45:44)
Included patches: 1-1912
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Huge version without GUI.  Features included (+) or not (-):
+acl               -dnd               +localmap          +profile           +timers
+arabic            -ebcdic            +lua/dyn           +python/dyn        +title
+autocmd           +emacs_tags        +menu              +python3/dyn       -toolbar
+autochdir         +eval              +mksession         +quickfix          +user_commands
-autoservername    +ex_extra          +modify_fname      +reltime           +vartabs
-balloon_eval      +extra_search      +mouse             +rightleft         +vertsplit
+balloon_eval_term -farsi             -mouseshape        +ruby/dyn          +virtualedit
-browse            +file_in_path      +mouse_dec         +scrollbind        +visual
++builtin_terms    +find_in_path      +mouse_gpm         +signs             +visualextra
+byte_offset       +float             -mouse_jsbterm     +smartindent       +viminfo
+channel           +folding           +mouse_netterm     -sound             +vreplace
+cindent           -footer            +mouse_sgr         +spell             +wildignore
-clientserver      +fork()            -mouse_sysmouse    +startuptime       +wildmenu
-clipboard         +gettext           +mouse_urxvt       +statusline        +windows
+cmdline_compl     -hangul_input      +mouse_xterm       -sun_workshop      +writebackup
+cmdline_hist      +iconv             +multi_byte        +syntax            -X11
+cmdline_info      +insert_expand     +multi_lang        +tag_binary        -xfontset
+comments          +job               -mzscheme          -tag_old_static    -xim
+conceal           +jumplist          +netbeans_intg     -tag_any_white     -xpm
+cryptv            +keymap            +num64             -tcl               -xsmp
+cscope            +lambda            +packages          +termguicolors     -xterm_clipboard
+cursorbind        +langmap           +path_extra        +terminal          -xterm_save
+cursorshape       +libcall           +perl/dyn          +terminfo
+dialog_con        +linebreak         +persistent_undo   +termresponse
+diff              +lispindent        +postscript        +textobjects
+digraphs          +listcmds          +printer           +textprop
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim81"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--enable-new-dtags -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld  -Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -L/usr/local/lib -Wl,--as-needed -o vim        -lm  -lselinux   -lncurses -lacl -lattr -lgpm -ldl   -Wl,--enable-new-dtags -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector-strong -L/usr/local/lib  -L/usr/lib64/perl5/CORE -lperl -lpthread -lresolv -ldl -lm -lcrypt -lutil -lc
AaronM04 commented 5 years ago

I believe this is not a Tagbar bug because the command line arguments Tagbar calls ctags with lists a file inside rust.vim: ctags -f - --format=2 --excmd=pattern --fields=nksSaf --extra= --file-scope=yes --sort=no --append=no --options=/home/x/.vim/bundle/rust.vim/ctags/rust.ctags --language-force=rust --rust-kinds=Tfgsmcti /tmp/vxydnhY/8.rs

Suppose /tmp/vxydnhY/8.rs contains this:

#[derive(Debug)]
struct A {
    x: i64,
    y: f32,
}

impl A {
    fn get_x(&self) -> i64 {
        x
    }

    fn get_y(&self) -> f32 {
        y
    }
}

fn main() {
    let a = A { x: 3, y: 5 };
    println!("a is {:?}", a);
}

The output of the ctags command above would be this:

A   /tmp/vxydnhY/8.rs   /^struct A {$/;"    s   line:2
A   /tmp/vxydnhY/8.rs   /^struct A {$/;"    s   line:2
A   /tmp/vxydnhY/8.rs   /^impl A {$/;"  i   line:7
A   /tmp/vxydnhY/8.rs   /^impl A {$/;"  i   line:7
get_x   /tmp/vxydnhY/8.rs   /^    fn get_x(&self) -> i64 {$/;"  f   line:8
get_x   /tmp/vxydnhY/8.rs   /^    fn get_x(&self) -> i64 {$/;"  f   line:8
get_y   /tmp/vxydnhY/8.rs   /^    fn get_y(&self) -> f32 {$/;"  f   line:12
get_y   /tmp/vxydnhY/8.rs   /^    fn get_y(&self) -> f32 {$/;"  f   line:12
main    /tmp/vxydnhY/8.rs   /^fn main() {$/;"   f   line:17
main    /tmp/vxydnhY/8.rs   /^fn main() {$/;"   f   line:17

For comparison, Tagbar's Go support looks good. Tagbar runs a command like this to get the tags:

gotags -sort -silent test.go

Contents of the above file:

package main

import "fmt"

type A struct {
    x int64
    y float32
}

func (a *A) getX() int64 {
    return a.x
}

func (a *A) getY() float32 {
    return a.y
}

func main() {
    a := A{x: 3, y: 5}
    fmt.Printf("a.x is %d\n", a.getX())
    fmt.Printf("a.y is %f\n", a.getY())
}

The output of the gotags command above would be this:

!_TAG_FILE_FORMAT   2
!_TAG_FILE_SORTED   1   /0=unsorted, 1=sorted/
!_TAG_PROGRAM_AUTHOR    Joel Stemmer    /stemmertech@gmail.com/
!_TAG_PROGRAM_NAME  gotags
!_TAG_PROGRAM_URL   https://github.com/jstemmer/gotags
!_TAG_PROGRAM_VERSION   1.4.1   /go1.11.4/
A   test.go 5;" t   access:public   line:5  type:struct
fmt test.go 3;" i   line:3
getX    test.go 10;"    m   access:private  ctype:A line:10 signature:()    type:int64
getY    test.go 14;"    m   access:private  ctype:A line:14 signature:()    type:float32
main    test.go 18;"    f   access:private  line:18 signature:()
main    test.go 1;" p   line:1
x   test.go 6;" w   access:private  ctype:A line:6  type:int64
y   test.go 7;" w   access:private  ctype:A line:7  type:float32