coc-rust-analyzer: Auto save check (cargo) wrongly modified my code

What’s the output of :CocInfo

## versions

vim version: NVIM v0.8.3
node version: v19.6.0
coc.nvim version: 0.0.82-b7375d5f 2023-01-30 05:09:03 +0800
coc.nvim directory: /home/jin/.local/share/nvim/lazy/coc.nvim
term: xterm-256color
platform: linux

What’s the output of :CocCommand rust-analyzer.serverVersion

version:0.3.1386-standalone

What’s your coc-rust-analyzer version? You can get it from :CocList extensions

version:0.72.0

I just input :w to save my file, then cargo check run. It change my file wrongly.

I didn’t know why? My coc-setting.json here is:

{
  "codeLens.enable": true,
  "colors.enable": true,
  "diagnostic.virtualText": true,
  "links.highlight": true,
  "list.alignColumns": true,
  "list.floatPreview": true,
  "snippet.highlight": true,
  "coc.preferences.enableLinkedEditing": true,
  "coc.preferences.extensionUpdateCheck": "daily",
  "coc.preferences.silentAutoupdate": true,
  "Lua.diagnostics.globals": ["vim"],
  "sumneko-lua.enableNvimLuaDev": true,
  "Lua.runtime.version": "LuaJIT",
  "coc.preferences.formatOnSave": true,
  "explorer.icon.enableNerdfont": true,
  "languageserver": {},
  "cSpell.userWords": [
    "Autoupdate",
    "Nvim",
    "gonic",
    "prac",
    "sumneko",
    "vite"
  ]
}

Peek 2023-02-03 21-25

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 27 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I worked around this by removing set foldmethod=expr from my vimrc and replacing it with these autocommands:

    " Work around https://github.com/fannheyward/coc-rust-analyzer/issues/1113
    autocmd FileType * setlocal foldmethod=expr
    autocmd FileType rust setlocal foldmethod=indent

Reproduced with nvim 0.8.3, but not nvim 0.9.0 nightly. https://github.com/neoclide/coc.nvim/issues/4511

Another solution by now: change notification.statusLineProgress to true, don’t use floating notification window for progress.

Still woking on this.

foldexpr=nvim_treesitter#foldexpr()

Maybe nvim-treesitter related?

Nice find @gibfahn, I also have foldmethod=expr with foldexpr=nvim_treesitter#foldexpr().

Setting foldmethod=manual serves as a workaround to prevent the second line from being modified.

+1, as far as I can tell what happens is that when coc is running cargo build to compile, it writes the name of the current module in the second line of the current file, it seems like the progress bar / list of modules is written to the second line whenever you write a file.

I’ve been seeing this for maybe a week or two, not sure which update caused it.