Incorrect document context after apply textEdit.
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.
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!()',
'}'
]
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