Skip to content

Automatic rustfmt erases my files sometimes. #260

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

Closed
dpc opened this issue Sep 8, 2018 · 7 comments
Closed

Automatic rustfmt erases my files sometimes. #260

dpc opened this issue Sep 8, 2018 · 7 comments

Comments

@dpc
Copy link

dpc commented Sep 8, 2018

  • rust.vim version: Current one, I use vim-plug and do :PlugUpdate often.

Steps to reproduce:

I think it started happening when I converted my project to use a workspace. The current state is: crev-dev/cargo-crev@d9fbf06

Expected vs. actual behavior:

Typically my vim consistently reformats a file on every save.

Now, for whatever reason, it stops working in the middle of the session for some files (for which it worked fine just a second ago) and from that time it just keeps erasing them every time I write the buffer. :/

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_because_of_config = v:null
let g:rustfmt_autosave_if_config_present = 1
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 = v:null
rustfmt 0.99.4-nightly (1c40881 2018-08-27)

rustc 1.30.0-nightly (fc81e3624 2018-09-07)

cargo 1.29.0-nightly (0ec7281b9 2018-08-20)


NVIM v0.3.1
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: /nix/store/wkfafgwgs1na5f808wybs8l6v8yjrvqz-gcc-wrapper-7.3.0/bin/gcc -Wconversion -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/source/build/config -I/build/source/src -I/nix/store/3jzza70h4xlcl65py98y0ddq3sr3nv6z-libuv-1.21.0/include -I/nix/store/wqmabb91mn7c8l0cbagbi7n6b78r2k6g-libmsgpack-2.1.5/include -I/nix/store/qwlgay0pdgllmdwif144771z8y0anx3j-unibilium-2.0.0/include -I/nix/store/caygb8bjk106ja8fddlx2zw5fbzzz8g2-libtermkey-0.20/include -I/nix/store/r54qm8js4ndph7mqwm61fgpd54niwbxi-neovim-libvterm-2017-11-05/include -I/nix/store/k8fcymm135rp923s2w8w5z7wzr2kdcvi-jemalloc-5.0.1/include -I/nix/store/z10kkr081zb02kyjw8ybf2s9zll49cvx-glibc-2.27-dev/include -I/build/source/build/src/nvim/auto -I/build/source/build/include
Compiled by nixbld

Features: +acl +iconv +jemalloc +tui 
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/nix/store/19sgqgn1vpc8c7828hhf0lmpaqx9yb8m-neovim-unwrapped-0.3.1/share/nvim"

Run :checkhealth for more info
@da-x
Copy link
Member

da-x commented Sep 8, 2018

Tried to reproduce with rustfmt 0.99.4-nightly, nvim 3.1, and crev-dev/cargo-crev@d9fbf06 to no avail. Just to clear out ambiguity regarding 'erased' - are the files actually being removed from the directory, or the buffers in which they are edited get emptied?

@dpc
Copy link
Author

dpc commented Sep 8, 2018

@da-x Thanks for checking. I will try to spend some time and dissect it.

The file is there, just empty.

I can do uu for two undoes, get the old content, but when I :w the file consistently keep being rewritten as empty.

@dpc
Copy link
Author

dpc commented Sep 8, 2018

After I've commented out call neomake#configure#automake('w') it stopped happening. When I used autocmd! BufWritePost,BufEnter *.rs Neomake cargo instead the problem is not happening.

I guess I'll log an issue against neomake.

@blueyed
Copy link

blueyed commented Sep 9, 2018

For reference: it also happens with the manual Neomake autocommand.
I've left some hints for debugging at neomake/neomake#2080 (comment).

@dpc
Copy link
Author

dpc commented Sep 9, 2018

Following instructions from neomake/neomake#2080

when doing :debug w:

function <SNR>20_SynSet                                                                                                         
line 26: endif                                                                                                                  
>                                                                                                                               
function <SNR>20_SynSet                                                                                                         
line 26: End of function                                                                                                        
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 43: if s:got_fmt_error                                                                                                     
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 47: endif                                                                                                                  
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 48: elseif g:rustfmt_fail_silently == 0 && a:fail_silently == 0                                                            
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 82: if a:tmpname ==# ''                                                                                                    
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 83: if l:has_lcd                                                                                                           
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 85: else                                                                                                                   
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 86: execute 'chdir! '.l:prev_cd                                                                                            
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 87: endif                                                                                                                  
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 88: endif                                                                                                                  
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 90: loadview                                                                                                               
>                                                                                                                               
function rustfmt#PreWrite[12]..<SNR>120_RunRustfmt                                                                              
line 90: End of function                                                                                                        
>                                                                                                                               
function rustfmt#PreWrite                                                                                                       
line 12: End of function                                                                                                        
>                                                                                                                               
BufWritePre Auto commands for "<buffer=3>"                                                                                      
cmd: call rustfmt#PreWrite()                                                                                                    
"crev-data/src/tests.rs" 0L, 0C written                                                                                         
BufWritePost Auto commands for "*"                                                                                              
cmd: set nottimeout           

The last output is the one after which the file became 0-sized.

I was doing strace at the same time, and it looks like the pid of rustfmt received empty input:

[pid 25699] execve("/home/dpc/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustfmt", ["rustfmt", "--emit=stdout"], 0x
e687e0 /* 101 vars */ <unfinished ...>
(...)
[pid 25699] read(0, "", 8192)           = 0

dpc added a commit to dpc/rust.vim that referenced this issue Sep 9, 2018
All credit to @blueyed .

This fixes rust-lang#260

The investigation is in the corresponding Neomake issue:
neomake/neomake#2080

This is also related to: rust-lang#259
dpc added a commit to dpc/rust.vim that referenced this issue Sep 9, 2018
All credit to `@blueyed`.

This fixes rust-lang#260

The investigation is in the corresponding Neomake issue:
neomake/neomake#2080

This is also related to: rust-lang#259
dpc added a commit to dpc/rust.vim that referenced this issue Sep 9, 2018
All credit to `@blueyed`.

This fixes rust-lang#260

The investigation is in the corresponding Neomake issue:
neomake/neomake#2080

This is also related to: rust-lang#259
da-x added a commit that referenced this issue Sep 9, 2018
Similarly to what other reformatters plugins do, we should use a
combination of setline() and line deletion command to carefully
replace the lines of the buffer(). There's issue #236 that seems
to not regress in this fix - the problem with '1,$d _' is that it
deleted the entire buffer. We should only delete for line numbers
that beyond the newly applied buffer content.

This has a side effect of handling #260 and #259, as expand('%')
is not relied upon.
@da-x
Copy link
Member

da-x commented Oct 14, 2018

@dpc is this issue still relevant? Thanks

@dpc
Copy link
Author

dpc commented Oct 14, 2018

No. It's fixed Neomake.

@dpc dpc closed this as completed Oct 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants