LanguageClient: Increment document version on every content change

Prevents applying results from outdated documents. Specifically
notifications and codeactions for documents that have been cleared on
the contents change handler but get a result before sending the actual
did change notification.

Change-Id: I640088d7cb2464dd4edd832319314bb04eab1df3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2021-09-07 11:47:21 +02:00
parent 4504570447
commit c1dff744a0

View File

@@ -721,6 +721,7 @@ void Client::documentContentsChanged(TextEditor::TextDocument *document,
m_openedDocument[document] = document->plainText();
}
++m_documentVersions[document->filePath()];
using namespace TextEditor;
for (BaseTextEditor *editor : BaseTextEditor::textEditorsForDocument(document)) {
if (TextEditorWidget *widget = editor->editorWidget()) {
@@ -1187,7 +1188,7 @@ void Client::sendPostponedDocumentUpdates()
const auto uri = DocumentUri::fromFilePath(filePath);
m_highlights[uri].clear();
VersionedTextDocumentIdentifier docId(uri);
docId.setVersion(++m_documentVersions[filePath]);
docId.setVersion(m_documentVersions[filePath]);
DidChangeTextDocumentParams params;
params.setTextDocument(docId);
params.setContentChanges(m_documentsToUpdate.take(document));