Coc.nvim: Incorrect document context after apply textEdit

Created on 7 Jul 2020  路  2Comments  路  Source: neoclide/coc.nvim

Describe the bug

Incorrect document context after apply textEdit.

Reproduce the bug

coc-settings.json:

{
  "languageserver": {
    "rust": {
      "command": "rust-analyzer",
      "filetypes": ["rust"],
      "rootPatterns": ["Cargo.toml", ".git/"],
      "progressOnInitialization": true
    }
  }
}

main.rs:

fn main() {
    abc();
}

Put cursor on abc, fire codeAction to choose Add function, will result

fn main() {
    abc();
}
fn abc() {
    todo!()
}

This result is wrong.

Tracking issue

The textEdit from LS:

{
  newText: '\n\nfn abc() {\n    todo!()\n}',
  range: { end: { character: 1, line: 2 }, start: { character: 1, line: 2 } }
}

After TextDocument.applyEdits, applied is:

fn main() {
    abc();
}

fn abc() {
    todo!()
}

buffer lines after this.buffer.setLines

[
  'fn main() {',
  '    abc();',
  '}',
  '',
  'fn abc() {',
  '    todo!()',
  '}'
]
bug

All 2 comments

I came this error with rust-analyzer and https://github.com/rodrigore/coc-tailwind-intellisense, after some tracking, I found TextDocument.applyEdits will result correct content, but document content is wrong.

After this commit, all files formatted by coc-prettier are getting an extra \n

Was this page helpful?
0 / 5 - 0 ratings