Core: add aboutToSave and saved signal to IDocument

We need reliable signals that gets emitted when documents are saved to
inform the language server about the document state change.

Change-Id: I0a1e8a5317ae6984ff17d878952c74f69765e3f9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2023-06-13 15:00:15 +02:00
parent 16bfc82ef0
commit 95609551a1
26 changed files with 134 additions and 65 deletions

View File

@@ -277,10 +277,14 @@ public:
{
QObject::disconnect(contentsChangedConnection);
QObject::disconnect(filePathChangedConnection);
QObject::disconnect(aboutToSaveConnection);
QObject::disconnect(savedConnection);
delete document;
}
QMetaObject::Connection contentsChangedConnection;
QMetaObject::Connection filePathChangedConnection;
QMetaObject::Connection aboutToSaveConnection;
QMetaObject::Connection savedConnection;
QTextDocument *document = nullptr;
};
QMap<TextEditor::TextDocument *, OpenedDocument> m_openedDocument;
@@ -648,6 +652,22 @@ void Client::openDocument(TextEditor::TextDocument *document)
if (isSupportedDocument(document))
openDocument(document);
});
d->m_openedDocument[document].savedConnection
= connect(document,
&TextDocument::saved,
this,
[this, document](const FilePath &saveFilePath) {
if (saveFilePath == document->filePath())
documentContentsSaved(document);
});
d->m_openedDocument[document].aboutToSaveConnection
= connect(document,
&TextDocument::aboutToSave,
this,
[this, document](const FilePath &saveFilePath) {
if (saveFilePath == document->filePath())
documentWillSave(document);
});
if (!d->m_documentVersions.contains(filePath))
d->m_documentVersions[filePath] = 0;
d->sendOpenNotification(filePath, document->mimeType(), document->plainText(),