Skip to content

Code Action apply broken #5448

@A4-Tacks

Description

@A4-Tacks

Result from CocInfo

## versions

vim version: VIM - Vi IMproved 9.1 9011734
node version: v23.9.0
coc.nvim version: 0.0.82-b0a699d 2025-09-22 17:34:21 +0800
coc.nvim directory: /home/lrne/.vim/plugged/coc.nvim
term: dumb
platform: linux

## Log of coc.nvim

2025-10-15T23:00:23.134 INFO (pid:21117) [plugin] - coc.nvim initialized with node: v23.9.0 after 419
2025-10-15T23:00:23.138 INFO (pid:21117) [services] - LanguageClient Rust Analyzer Language Server state change: stopped => starting
2025-10-15T23:00:23.153 INFO (pid:21117) [language-client-index] - Language server "rust-analyzer" started with 21136
2025-10-15T23:00:23.285 INFO (pid:21117) [services] - LanguageClient Rust Analyzer Language Server state change: starting => running
2025-10-15T23:00:23.299 INFO (pid:21117) [services] - service rust-analyzer started
2025-10-15T23:00:52.927 INFO (pid:21117) [attach] - receive notification: codeAction [ 'cursor' ]
2025-10-15T23:00:58.050 INFO (pid:21117) [attach] - receive notification: codeAction [ 'cursor' ]

Describe the bug

Text may be broken when using code actions

And applyEdits did not take effect, possibly due to other edits

Reproduce the bug

We will close your issue when you don't provide minimal vimrc and we can't
reproduce it

  • Create file mini.vim with:

    colorscheme habamax
    
    set nu
    set laststatus=2
    set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
    set statusline^=%(%1*[%{coc#status()}%{get(b:,'coc_current_function','')}]%*\ %)
    
    call plug#begin('~/.vim/plugged')
    Plug 'neoclide/coc.nvim'
    call plug#end()
    
    inoremap <silent><expr> <cr>
                \   coc#pum#visible() ? coc#pum#confirm()
                \ : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
    inoremap <silent><expr> <tab> coc#pum#visible()
                \   ? coc#pum#next(0)
                \   : coc#refresh()
    nmap <F3> <Plug>(coc-codeaction-cursor)
    xmap <F3> <Plug>(coc-codeaction-selected)
    nmap <C-k> <Plug>(coc-diagnostic-prev)
    nmap <C-j> <Plug>(coc-diagnostic-next)
    
    augroup coc_user
      autocmd!
      " Update statusline
      autocmd User CocStatusChange redrawstatus
    augroup end
  • Create file src/main.rs with:

    fn main() {
        match Some(2) {
            None => {
                bar(
                    2
                )
            },
        }
    }
  • Start vim with command: vim -Nu mini.vim src/main.rs

    1. Wait rust-analyzer finish index
    2. Cursor on Some(2), use <F3> select Fill match arms
    3. Use u to undo and use k move the cursor back to Some(2)
    4. Try several times step 2.

    Expect:

    fn main() {
        match Some(2) {
            None => {
                    bar(
                        2
                    )
                },
            Some(_) => todo!(),
        }
    }

    And expect applyEdits to select _ and todo!()

    Buggy:

    fn main() {
        match Some(2) {
            None => {
                    bar(
                        2
                    )
                Some(_) => todo!(),
            }
            Some(_) => todo!(),
        }

    The cursor is located at line 6 after )
    and a other bug from After code-action similar <c-o> fannheyward/coc-rust-analyzer#1328

Extra info

rust-analyzer 1.91.0-nightly (040a98a 2025-08-20)
coc-rust-analyzer 0.85.0

possibly due to other edits

If it is the following example, it works normally and the applyEdits is also normal:

fn main() {
    match Some(2) {
        None => { bar( 2 ) },
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions