6017: Don't return any TextEdit if formatting is unchanged r=jonas-schievink a=cuviper

I found that `textDocument/formatting` was always returning a full
`TextEdit` replacement, even when there are no changes, which caused Vim
(w/ vim-lsp) to always indicate a modified buffer after formatting. We
can easily compare whether there were changes and return `null` if not,
so the client knows there's nothing to do.

Co-authored-by: Josh Stone <cuviper@gmail.com>
This commit is contained in:
bors[bot]
2020-09-17 13:08:09 +00:00
committed by GitHub
2 changed files with 45 additions and 4 deletions

View File

@@ -748,10 +748,15 @@ pub(crate) fn handle_formatting(
}
}
Ok(Some(vec![lsp_types::TextEdit {
range: Range::new(Position::new(0, 0), end_position),
new_text: captured_stdout,
}]))
if *file == captured_stdout {
// The document is already formatted correctly -- no edits needed.
Ok(None)
} else {
Ok(Some(vec![lsp_types::TextEdit {
range: Range::new(Position::new(0, 0), end_position),
new_text: captured_stdout,
}]))
}
}
fn handle_fixes(