Closed ghentschke closed 8 months ago
It seems to be a race condition on LSP4E formatDocument
org.eclipse.lsp4e.DocumentContentSynchronizer.formatDocument(DocumentContentSynchronizer.java:296)
It 's triggered by splitting the \r\n
line ending during string replacement in the editors document. See https://github.com/eclipse-cdt/cdt-lsp/issues/239#issuecomment-1913091960
This happens also when formatting the code via context menu: Source -> Format or via Ctrl + Shift + F (under Windows) and then saving the file.
After some investigation, I found out, that this will be triggered when the newText
string in the TextEdit
response from clangd ends with a \r
character:
[TextEdit [
range = Range [
start = Position [
line = 1
character = 0
]
end = Position [
line = 3
character = 20
]
]
newText = "#include "config.h"\r\n#include <Cmk1.hpp>\r\n#include <iostream>\r"
]]
This leads to editor document inconsistency when the \r\n
line ending is used (typically on windows machines). That's why the problem occurs on windows machines only.
I assume that during the document.replace
operation, a separation of the \r\n
line ending by the replacement string leads to an invalid document state.
Fixed by LSP4E PR #903
When inserting a new
#include
in the LSP based C/C++ Editor and saving this file, the editor can become blank, if the format-on-save option is enabled:Steps to reproduce: There must be at least one local and one system header include. E.g.:
Insert a local header:
#include "..."
after the system header:#include <...>
(in<>
):and save the file with format-on-save (Format source code) enabled. (see Preferences -> C/C++ -> Editor (LSP) -> SaveActions -> Format source code).
Stack trace: