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

Abierto
#438 7 comentarios 6 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
neovim, rust
Área
tooling

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

  • 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
Lenguaje dominante
Vim Script
Estrellas
4.2k
Forks
323
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rust-lang/rust.vim

Todos los issues de rust-lang/rust.vim

Issues similares

Más issues de DevTools

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.