Commit a12a8c95 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Request diagnostics/highlighting only if needed

Most of the time, the updated diagnostics/highlightings will be send by
the backend on translation unit update.

The other use case is changing the font settings (e.g. color), here we
need to request the highlightings explicitly.

Change-Id: I17a574eaf972c8bef12900241e7b33fe6ffd9dbd
Reviewed-by: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
parent 514a96c7
...@@ -470,23 +470,15 @@ void IpcCommunicator::updateUnsavedFile(const QString &filePath, const QByteArra ...@@ -470,23 +470,15 @@ void IpcCommunicator::updateUnsavedFile(const QString &filePath, const QByteArra
documentRevision}}); documentRevision}});
} }
void IpcCommunicator::requestDiagnosticsAndHighlighting(const FileContainer &fileContainer, void IpcCommunicator::updateTranslationUnitWithRevisionCheck(const FileContainer &fileContainer)
DocumentChangedCheck documentChangedCheck)
{ {
if (m_sendMode == IgnoreSendRequests) if (m_sendMode == IgnoreSendRequests)
return; return;
if (documentChangedCheck == DocumentChangedCheck::RevisionCheck) { if (documentHasChanged(fileContainer.filePath())) {
if (documentHasChanged(fileContainer.filePath())) { updateTranslationUnitsForEditor({fileContainer});
updateTranslationUnitsForEditor({fileContainer}); setLastSentDocumentRevision(fileContainer.filePath(),
requestDiagnostics(fileContainer); fileContainer.documentRevision());
requestHighlighting(fileContainer);
setLastSentDocumentRevision(fileContainer.filePath(),
fileContainer.documentRevision());
}
} else {
requestDiagnostics(fileContainer);
requestHighlighting(fileContainer);
} }
} }
...@@ -504,16 +496,16 @@ void IpcCommunicator::requestHighlighting(const FileContainer &fileContainer) ...@@ -504,16 +496,16 @@ void IpcCommunicator::requestHighlighting(const FileContainer &fileContainer)
m_ipcSender->requestHighlighting(message); m_ipcSender->requestHighlighting(message);
} }
void IpcCommunicator::requestDiagnosticsAndHighlighting(Core::IDocument *document) void IpcCommunicator::updateTranslationUnitWithRevisionCheck(Core::IDocument *document)
{ {
const auto textDocument = qobject_cast<TextDocument*>(document); const auto textDocument = qobject_cast<TextDocument*>(document);
const auto filePath = textDocument->filePath().toString(); const auto filePath = textDocument->filePath().toString();
const QString projectPartId = Utils::projectPartIdForFile(filePath); const QString projectPartId = Utils::projectPartIdForFile(filePath);
requestDiagnosticsAndHighlighting(FileContainer(filePath, updateTranslationUnitWithRevisionCheck(FileContainer(filePath,
projectPartId, projectPartId,
Utf8StringVector(), Utf8StringVector(),
textDocument->document()->revision())); textDocument->document()->revision()));
} }
void IpcCommunicator::updateChangeContentStartPosition(const QString &filePath, int position) void IpcCommunicator::updateChangeContentStartPosition(const QString &filePath, int position)
......
...@@ -118,8 +118,6 @@ public: ...@@ -118,8 +118,6 @@ public:
using FileContainers = QVector<ClangBackEnd::FileContainer>; using FileContainers = QVector<ClangBackEnd::FileContainer>;
using ProjectPartContainers = QVector<ClangBackEnd::ProjectPartContainer>; using ProjectPartContainers = QVector<ClangBackEnd::ProjectPartContainer>;
enum class DocumentChangedCheck { NoCheck, RevisionCheck };
public: public:
IpcCommunicator(); IpcCommunicator();
...@@ -130,6 +128,8 @@ public: ...@@ -130,6 +128,8 @@ public:
void unregisterProjectPartsForEditor(const QStringList &projectPartIds); void unregisterProjectPartsForEditor(const QStringList &projectPartIds);
void registerUnsavedFilesForEditor(const FileContainers &fileContainers); void registerUnsavedFilesForEditor(const FileContainers &fileContainers);
void unregisterUnsavedFilesForEditor(const FileContainers &fileContainers); void unregisterUnsavedFilesForEditor(const FileContainers &fileContainers);
void requestDiagnostics(const ClangBackEnd::FileContainer &fileContainer);
void requestHighlighting(const ClangBackEnd::FileContainer &fileContainer);
void completeCode(ClangCompletionAssistProcessor *assistProcessor, const QString &filePath, void completeCode(ClangCompletionAssistProcessor *assistProcessor, const QString &filePath,
quint32 line, quint32 line,
quint32 column, quint32 column,
...@@ -144,9 +144,8 @@ public: ...@@ -144,9 +144,8 @@ public:
void updateUnsavedFileFromCppEditorDocument(const QString &filePath); void updateUnsavedFileFromCppEditorDocument(const QString &filePath);
void updateTranslationUnit(const QString &filePath, const QByteArray &contents, uint documentRevision); void updateTranslationUnit(const QString &filePath, const QByteArray &contents, uint documentRevision);
void updateUnsavedFile(const QString &filePath, const QByteArray &contents, uint documentRevision); void updateUnsavedFile(const QString &filePath, const QByteArray &contents, uint documentRevision);
void requestDiagnosticsAndHighlighting(const ClangBackEnd::FileContainer &fileContainer, void updateTranslationUnitWithRevisionCheck(const ClangBackEnd::FileContainer &fileContainer);
DocumentChangedCheck documentChangedCheck = DocumentChangedCheck::RevisionCheck); void updateTranslationUnitWithRevisionCheck(Core::IDocument *document);
void requestDiagnosticsAndHighlighting(Core::IDocument *document);
void updateChangeContentStartPosition(const QString &filePath, int position); void updateChangeContentStartPosition(const QString &filePath, int position);
void registerFallbackProjectPart(); void registerFallbackProjectPart();
...@@ -167,8 +166,6 @@ private: ...@@ -167,8 +166,6 @@ private:
void registerCurrentCppEditorDocuments(); void registerCurrentCppEditorDocuments();
void registerCurrentCodeModelUiHeaders(); void registerCurrentCodeModelUiHeaders();
void requestHighlighting(const ClangBackEnd::FileContainer &fileContainer);
void requestDiagnostics(const ClangBackEnd::FileContainer &fileContainer);
void onBackendRestarted(); void onBackendRestarted();
void onEditorAboutToClose(Core::IEditor *editor); void onEditorAboutToClose(Core::IEditor *editor);
......
...@@ -93,7 +93,7 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor() ...@@ -93,7 +93,7 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor()
void ClangEditorDocumentProcessor::run() void ClangEditorDocumentProcessor::run()
{ {
requestDiagnosticsAndHighlighting(); updateTranslationUnitIfProjectPartExists();
// Run clang parser // Run clang parser
disconnect(&m_parserWatcher, &QFutureWatcher<void>::finished, disconnect(&m_parserWatcher, &QFutureWatcher<void>::finished,
...@@ -121,7 +121,9 @@ void ClangEditorDocumentProcessor::recalculateSemanticInfoDetached(bool force) ...@@ -121,7 +121,9 @@ void ClangEditorDocumentProcessor::recalculateSemanticInfoDetached(bool force)
void ClangEditorDocumentProcessor::semanticRehighlight() void ClangEditorDocumentProcessor::semanticRehighlight()
{ {
m_semanticHighlighter.updateFormatMapFromFontSettings(); m_semanticHighlighter.updateFormatMapFromFontSettings();
requestDiagnosticsAndHighlighting(DocumentChangedCheck::NoCheck);
if (m_projectPart)
requestDocumentAnnotations(m_projectPart->id());
} }
CppTools::SemanticInfo ClangEditorDocumentProcessor::recalculateSemanticInfo() CppTools::SemanticInfo ClangEditorDocumentProcessor::recalculateSemanticInfo()
...@@ -217,9 +219,9 @@ TextEditor::QuickFixOperations ClangEditorDocumentProcessor::extraRefactoringOpe ...@@ -217,9 +219,9 @@ TextEditor::QuickFixOperations ClangEditorDocumentProcessor::extraRefactoringOpe
return extractor.extract(assistInterface.fileName(), currentLine(assistInterface)); return extractor.extract(assistInterface.fileName(), currentLine(assistInterface));
} }
ClangBackEnd::FileContainer ClangEditorDocumentProcessor::fileContainer() const ClangBackEnd::FileContainer ClangEditorDocumentProcessor::fileContainerWithArguments() const
{ {
return fileContainer(m_projectPart.data()); return fileContainerWithArguments(m_projectPart.data());
} }
void ClangEditorDocumentProcessor::clearDiagnosticsWithFixIts() void ClangEditorDocumentProcessor::clearDiagnosticsWithFixIts()
...@@ -243,8 +245,7 @@ void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor( ...@@ -243,8 +245,7 @@ void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor(
const CppTools::ProjectPart::Ptr projectPart = m_parser->projectPart(); const CppTools::ProjectPart::Ptr projectPart = m_parser->projectPart();
if (isProjectPartLoadedOrIsFallback(projectPart)) { if (isProjectPartLoadedOrIsFallback(projectPart)) {
updateTranslationUnitForEditor(projectPart.data()); registerTranslationUnitForEditor(projectPart.data());
requestDiagnosticsAndHighlighting(projectPart.data());
m_projectPart = projectPart; m_projectPart = projectPart;
} }
...@@ -258,54 +259,39 @@ void ClangEditorDocumentProcessor::onParserFinished() ...@@ -258,54 +259,39 @@ void ClangEditorDocumentProcessor::onParserFinished()
updateProjectPartAndTranslationUnitForEditor(); updateProjectPartAndTranslationUnitForEditor();
} }
void ClangEditorDocumentProcessor::updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart) void ClangEditorDocumentProcessor::registerTranslationUnitForEditor(CppTools::ProjectPart *projectPart)
{ {
QTC_ASSERT(m_modelManagerSupport, return); QTC_ASSERT(m_modelManagerSupport, return);
IpcCommunicator &ipcCommunicator = m_modelManagerSupport->ipcCommunicator(); IpcCommunicator &ipcCommunicator = m_modelManagerSupport->ipcCommunicator();
if (m_projectPart) { if (m_projectPart) {
if (projectPart->id() != m_projectPart->id()) { if (projectPart->id() != m_projectPart->id()) {
ipcCommunicator.unregisterTranslationUnitsForEditor({fileContainer()}); ipcCommunicator.unregisterTranslationUnitsForEditor({fileContainerWithArguments()});
ipcCommunicator.registerTranslationUnitsForEditor({fileContainer(projectPart)}); ipcCommunicator.registerTranslationUnitsForEditor({fileContainerWithArguments(projectPart)});
requestDocumentAnnotations(projectPart->id());
} }
} else { } else {
ipcCommunicator.registerTranslationUnitsForEditor({{fileContainer(projectPart)}}); ipcCommunicator.registerTranslationUnitsForEditor({{fileContainerWithArguments(projectPart)}});
requestDocumentAnnotations(projectPart->id());
} }
} }
void ClangEditorDocumentProcessor::requestDiagnosticsAndHighlighting(CppTools::ProjectPart *projectPart) void ClangEditorDocumentProcessor::updateTranslationUnitIfProjectPartExists()
{ {
if (!m_projectPart || projectPart->id() != m_projectPart->id()) { if (m_projectPart) {
IpcCommunicator &ipcCommunicator = m_modelManagerSupport->ipcCommunicator(); const ClangBackEnd::FileContainer fileContainer = fileContainerWithDocumentContent(m_projectPart->id());
const ClangBackEnd::FileContainer fileContainer_ = fileContainer(projectPart); m_modelManagerSupport->ipcCommunicator().updateTranslationUnitWithRevisionCheck(fileContainer);
ipcCommunicator.requestDiagnosticsAndHighlighting(fileContainer_);
} }
} }
IpcCommunicator::DocumentChangedCheck void ClangEditorDocumentProcessor::requestDocumentAnnotations(const QString &projectpartId)
toIpcCommunicatorDocumentChangedCheck(ClangEditorDocumentProcessor::DocumentChangedCheck condition)
{ {
return condition == ClangEditorDocumentProcessor::DocumentChangedCheck::RevisionCheck const auto fileContainer = fileContainerWithDocumentContent(projectpartId);
? IpcCommunicator::DocumentChangedCheck::RevisionCheck
: IpcCommunicator::DocumentChangedCheck::NoCheck;
}
void ClangEditorDocumentProcessor::requestDiagnosticsAndHighlighting(DocumentChangedCheck documentChangedCheck)
{
if (m_projectPart) {
auto &ipcCommunicator = m_modelManagerSupport->ipcCommunicator();
const ClangBackEnd::FileContainer fileContainer(filePath(),
m_projectPart->id(),
baseTextDocument()->plainText(),
true,
revision());
const auto documentCheck = toIpcCommunicatorDocumentChangedCheck(documentChangedCheck); auto &ipcCommunicator = m_modelManagerSupport->ipcCommunicator();
ipcCommunicator.requestDiagnostics(fileContainer);
ipcCommunicator.requestDiagnosticsAndHighlighting(fileContainer, documentCheck); ipcCommunicator.requestHighlighting(fileContainer);
}
} }
static CppTools::ProjectPart projectPartForLanguageOption(CppTools::ProjectPart *projectPart) static CppTools::ProjectPart projectPartForLanguageOption(CppTools::ProjectPart *projectPart)
...@@ -331,7 +317,7 @@ static QStringList fileArguments(const QString &filePath, CppTools::ProjectPart ...@@ -331,7 +317,7 @@ static QStringList fileArguments(const QString &filePath, CppTools::ProjectPart
} }
ClangBackEnd::FileContainer ClangBackEnd::FileContainer
ClangEditorDocumentProcessor::fileContainer(CppTools::ProjectPart *projectPart) const ClangEditorDocumentProcessor::fileContainerWithArguments(CppTools::ProjectPart *projectPart) const
{ {
const auto projectPartId = projectPart const auto projectPartId = projectPart
? Utf8String::fromString(projectPart->id()) ? Utf8String::fromString(projectPart->id())
...@@ -341,5 +327,15 @@ ClangEditorDocumentProcessor::fileContainer(CppTools::ProjectPart *projectPart) ...@@ -341,5 +327,15 @@ ClangEditorDocumentProcessor::fileContainer(CppTools::ProjectPart *projectPart)
return {filePath(), projectPartId, Utf8StringVector(theFileArguments), revision()}; return {filePath(), projectPartId, Utf8StringVector(theFileArguments), revision()};
} }
ClangBackEnd::FileContainer
ClangEditorDocumentProcessor::fileContainerWithDocumentContent(const QString &projectpartId) const
{
return ClangBackEnd::FileContainer(filePath(),
projectpartId,
baseTextDocument()->plainText(),
true,
revision());
}
} // namespace Internal } // namespace Internal
} // namespace ClangCodeModel } // namespace ClangCodeModel
...@@ -83,12 +83,11 @@ public: ...@@ -83,12 +83,11 @@ public:
TextEditor::QuickFixOperations TextEditor::QuickFixOperations
extraRefactoringOperations(const TextEditor::AssistInterface &assistInterface) override; extraRefactoringOperations(const TextEditor::AssistInterface &assistInterface) override;
ClangBackEnd::FileContainer fileContainer() const; ClangBackEnd::FileContainer fileContainerWithArguments() const;
void clearDiagnosticsWithFixIts(); void clearDiagnosticsWithFixIts();
public: public:
enum class DocumentChangedCheck { NoCheck, RevisionCheck };
static ClangEditorDocumentProcessor *get(const QString &filePath); static ClangEditorDocumentProcessor *get(const QString &filePath);
private slots: private slots:
...@@ -96,10 +95,11 @@ private slots: ...@@ -96,10 +95,11 @@ private slots:
private: private:
void updateProjectPartAndTranslationUnitForEditor(); void updateProjectPartAndTranslationUnitForEditor();
void updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart); void registerTranslationUnitForEditor(CppTools::ProjectPart *projectPart);
void requestDiagnosticsAndHighlighting(CppTools::ProjectPart *projectPart); void updateTranslationUnitIfProjectPartExists();
void requestDiagnosticsAndHighlighting(DocumentChangedCheck documentChangedCheck = DocumentChangedCheck::RevisionCheck); void requestDocumentAnnotations(const QString &projectpartId);
ClangBackEnd::FileContainer fileContainer(CppTools::ProjectPart *projectPart) const; ClangBackEnd::FileContainer fileContainerWithArguments(CppTools::ProjectPart *projectPart) const;
ClangBackEnd::FileContainer fileContainerWithDocumentContent(const QString &projectpartId) const;
private: private:
ClangDiagnosticManager m_diagnosticManager; ClangDiagnosticManager m_diagnosticManager;
......
...@@ -193,7 +193,7 @@ void ModelManagerSupportClang::onCppDocumentReloadFinishedOnTranslationUnit(bool ...@@ -193,7 +193,7 @@ void ModelManagerSupportClang::onCppDocumentReloadFinishedOnTranslationUnit(bool
if (success) { if (success) {
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender()); TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
connectToTextDocumentContentsChangedForTranslationUnit(textDocument); connectToTextDocumentContentsChangedForTranslationUnit(textDocument);
m_ipcCommunicator.requestDiagnosticsAndHighlighting(textDocument); m_ipcCommunicator.updateTranslationUnitWithRevisionCheck(textDocument);
} }
} }
...@@ -342,7 +342,7 @@ void ModelManagerSupportClang::unregisterTranslationUnitsWithProjectParts( ...@@ -342,7 +342,7 @@ void ModelManagerSupportClang::unregisterTranslationUnitsWithProjectParts(
{ {
const auto processors = clangProcessorsWithProjectParts(projectPartIds); const auto processors = clangProcessorsWithProjectParts(projectPartIds);
foreach (ClangEditorDocumentProcessor *processor, processors) { foreach (ClangEditorDocumentProcessor *processor, processors) {
m_ipcCommunicator.unregisterTranslationUnitsForEditor({processor->fileContainer()}); m_ipcCommunicator.unregisterTranslationUnitsForEditor({processor->fileContainerWithArguments()});
processor->clearProjectPart(); processor->clearProjectPart();
processor->run(); processor->run();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment