rust-lang / rust.vim

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

Undo history lost after undo when `let g:rustfmt_autosave = 1` #381

Open wilfredjonathanjames opened 4 years ago

wilfredjonathanjames commented 4 years ago

Steps to reproduce:

  1. Set let g:rustfmt_autosave = 1 in vimrc
  2. Make a change to a rust file in vim
  3. Undo the change (in this case u)
  4. Attempt to redo the change (in this case C-r)
  5. Notice that the change is not redone, and "Already at newest change" is displayed

Expected vs. actual behavior: Step 5 should not show "Already at newest change", and should redo the undone change.

rust.vim Global Variables:

let g:ftplugin_rust_source_path = v:null
let g:loaded_syntastic_rust_cargo_checker = 1
let g:loaded_syntastic_rust_filetype = v:null
let g:loaded_syntastic_rust_rustc_checker = 1
let g:rust_bang_comment_leader = v:null
let g:rust_cargo_avoid_whole_workspace = v:null
let g:rust_clip_command = 'pbcopy'
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 = 1
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_options = ''
let g:syntastic_extra_filetypes = ['rust']
let g:syntastic_rust_cargo_fname = ''
rustfmt 1.4.8-stable (afb1ee1c 2019-09-08)

rustc 1.39.0 (4560ea788 2019-11-04)

cargo 1.39.0 (1c6ec66d5 2019-09-30)

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov  6 2017 02:39:16)
macOS version
Included patches: 1-1272
Compiled by root@Traviss-Mac-713.local
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl             +cmdline_hist    -ebcdic          +fullscreen      +lispindent      +mouse_netterm   +path_extra      +scrollbind      +terminal        +visualextra     -xterm_clipboard
+arabic          +cmdline_info    +emacs_tags      -gettext         +listcmds        +mouse_sgr       +perl/dyn        +signs           +terminfo        +viminfo         -xterm_save
+autocmd         +comments        +eval            -hangul_input    +localmap        -mouse_sysmouse  +persistent_undo +smartindent     +termresponse    +vreplace        
+balloon_eval    +conceal         +ex_extra        +iconv           +lua/dyn         +mouse_urxvt     +postscript      +startuptime     +textobjects     +wildignore      
+browse          +cryptv          +extra_search    +insert_expand   +menu            +mouse_xterm     +printer         +statusline      +timers          +wildmenu        
++builtin_terms  +cscope          +farsi           +job             +mksession       +multi_byte      +profile         -sun_workshop    +title           +windows         
+byte_offset     +cursorbind      +file_in_path    +jumplist        +modify_fname    +multi_lang      +python/dyn      +syntax          +toolbar         +writebackup     
+channel         +cursorshape     +find_in_path    +keymap          +mouse           -mzscheme        +python3/dyn     +tag_binary      +transparency    -X11             
+cindent         +dialog_con_gui  +float           +lambda          +mouseshape      +netbeans_intg   +quickfix        +tag_old_static  +user_commands   -xfontset        
+clientserver    +diff            +folding         +langmap         +mouse_dec       +num64           +reltime         -tag_any_white   +vertsplit       +xim             
+clipboard       +digraphs        -footer          +libcall         -mouse_gpm       +odbeditor       +rightleft       -tcl             +virtualedit     -xpm             
+cmdline_compl   +dnd             +fork()          +linebreak       -mouse_jsbterm   +packages        +ruby/dyn        +termguicolors   +visual          -xsmp            
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe  -DMACOS_X -DMACOS_X_DARWIN  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: clang   -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon       -lm  -lncurses -liconv -framework AppKit   -fstack-protector  -L/System/Library/Perl/5.16/darwin-thread-multi-2level/CORE 
----
Info from Syntastic:
Syntastic version: 3.10.0-5 (Vim 800, Darwin, GUI)
Info for filetype: rust
Global mode: passive
Filetype rust is passive
The current file will not be checked automatically
Available checkers: cargo rustc
Currently enabled checker: cargo
NilsIrl commented 4 years ago

I think it may have to do with these lines: https://github.com/rust-lang/rust.vim/blob/2a6736852cbe64e2883adc70a427cb47cb3305bc/autoload/rustfmt.vim#L147-L148

This is also explains why I don't seem to have this issue with manually running :RustFmt.

NilsIrl commented 4 years ago

I think I misunderstood the problem this issue is pointing out. The problem I have is that when I undo after saving (and as a result autoformatting), it not only undoes the formatting but also undoes the changes before that.

Nadrieril commented 3 years ago

@NilsIrl I have the same issue. Removing the lines you mention does work, but then undoing the formatting moves the cursor to the end of the file which is quite annoying. It sounds complicated to avoid that.