From c1dff744a016e109aa7c4e1b26149234d85466ad Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 7 Sep 2021 11:47:21 +0200 Subject: [PATCH] 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 --- src/plugins/languageclient/client.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index 264053a23dc..8fe98be9d47 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -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));