Rustfmt is extremely slow in large files when using nvim-lsp

Ouverte
#438 7 commentaires 6 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
neovim, rust
Domaine
tooling

Piste de recherche

Start by reproducing the delay with the listed Neovim, rust-analyzer, and rustfmt setup, comparing :RustFmt with the language server enabled and disabled. The issue names no relevant source files or tests, so trace the formatting entry point and its interaction with nvim-lsp. Done means formatting a large Rust file completes without freezing the editor; the report has had no comment for 835 days.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

  • rust.vim version: 87c745d (latest master) installed through vim-plug
  • OS: macOS 10.15.7
  • Terminal: alacritty 0.7.2 (5ac8060)

Steps to reproduce:

  • Install nvim from the tip of master (must be an 0.5 version)

  • Install rustup

  • Run rustup toolchain install nightly-2021-03-01

  • Run rustup component add rustfmt --toolchain nightly-2021-03-01

  • Install rust-analyzer (I'm on rust-analyzer 2021-02-15, installed via Nix unstable)

  • Put the following minimal config in ~/.config/nvim/init.vim:

    set shell=/bin/bash
    
    " Install vim-plug if it isn't already
    if empty(glob('~/.local/share/nvim/site/autoload/plug.vim'))
      silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
        \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
      au VimEnter * PlugInstall --sync | source $MYVIMRC
    endif
    
    call plug#begin('~/.local/share/nvim/plugged')
    Plug 'neovim/nvim-lspconfig'
    Plug 'rust-lang/rust.vim'
    call plug#end()
    
    lua <<EOF
    require'lspconfig'.rust_analyzer.setup({})
    EOF
    
    let g:rustfmt_command = 'rustup run nightly-2021-03-01 rustfmt'
    let g:rustfmt_autosave = 1
    
  • Make sure ~/.local/share/nvim/site/autoload and ~/.local/share/nvim/plugged are empty or do not exist

  • Open nvim once to allow the plugins to install, then close it

  • Create a crate that contains a very long Rust file (in my case, the file is over 3000 lines long - the problem appears with shorter files but is less noticeable), and open that long file

  • Verify the language server is running by (e.g.) putting the cursor over a documented type name and running :lua vim.lsp.buf.hover() (documentation info should appear)

  • Insert some extra blank lines in the file, so that rustfmt will remove them when run

  • Run :w

Expected vs. actual behavior:

  • Expected: the file saves quickly, with no noticeable delay, and the contents of the file are automatically formatted using rustfmt
  • Actual: The file is formatted correctly, but takes more than 10 seconds to save, during which time the editor is completely frozen

Please note a few things:

  • The issue also appears when running :RustFmt manually
  • Saving the file becomes almost instantaneous if auto-formatting is disabled (but :RustFmt still hangs just as much)
  • Saving the file and formatting it also becomes almost instantaneous (with auto-formatting enabled) if the language server is disabled (remove the Lua section in the config above), so it appears to be the interaction between the two things that's the problem.
  • cargo +nightly-2021-03-01 fmt only takes about a second, at most, to run from outside nvim
  • There has been some mention before of shells such as fish (which is my login shell) causing delays, and I do see additional delays if I remove set shell=/bin/bash from that config, but please note that that line means fish shouldn't be involved here. Changing my login shell to bash or zsh does not fix the problem.

I'm happy to do any debugging or profiling you'd like me to, but you'll have to let me know what to run in order to do that, because my knowledge of vim really isn't extensive enough for me to know how to do that myself. Thanks!

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 = 1
let g:rustfmt_autosave_if_config_present = v:null
let g:rustfmt_command = 'rustup run nightly-2021-03-01 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 1.4.36-nightly (7de6968e 2021-02-07)

rustc 1.51.0-nightly (1d0d76f8d 2021-01-24)

cargo 1.51.0-nightly (783bc43c6 2021-01-20)


NVIM v0.5.0-dev+c1fbc2ddf
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210301-91403-1qxibkt/build/config -I/tmp/neovim-20210301-91403-1qxibkt/src -I/usr/local/include -I/usr/local/opt/luv/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/usr/local/opt/gettext/include -I/tmp/neovim-20210301-91403-1qxibkt/build/src/nvim/auto -I/tmp/neovim-20210301-91403-1qxibkt/build/include
Compiled by [email protected]

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

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/HEAD-c1fbc2d_1/share/nvim"

Run :checkhealth for more info
Langage dominant
Vim Script
Étoiles
4.2k
Forks
323
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de rust-lang/rust.vim

Toutes les issues de rust-lang/rust.vim

Issues similaires

Plus d'issues DevTools

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.