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
documentRevision}});
}
void IpcCommunicator::requestDiagnosticsAndHighlighting(const FileContainer &fileContainer,
DocumentChangedCheck documentChangedCheck)
void IpcCommunicator::updateTranslationUnitWithRevisionCheck(const FileContainer &fileContainer)
{
if (m_sendMode == IgnoreSendRequests)
return;
if (documentChangedCheck == DocumentChangedCheck::RevisionCheck) {
if (documentHasChanged(fileContainer.filePath())) {
updateTranslationUnitsForEditor({fileContainer});
requestDiagnostics(fileContainer);
requestHighlighting(fileContainer);
setLastSentDocumentRevision(fileContainer.filePath(),
fileContainer.documentRevision());
}
} else {
requestDiagnostics(fileContainer);
requestHighlighting(fileContainer);
if (documentHasChanged(fileContainer.filePath())) {
updateTranslationUnitsForEditor({fileContainer});
setLastSentDocumentRevision(fileContainer.filePath(),
fileContainer.documentRevision());
}
}
......@@ -504,16 +496,16 @@ void IpcCommunicator::requestHighlighting(const FileContainer &fileContainer)
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 filePath = textDocument->filePath().toString();
const QString projectPartId = Utils::projectPartIdForFile(filePath);
requestDiagnosticsAndHighlighting(FileContainer(filePath,
projectPartId,
Utf8StringVector(),
textDocument->document()->revision()));
updateTranslationUnitWithRevisionCheck(FileContainer(filePath,
projectPartId,
Utf8StringVector(),
textDocument->document()->revision()));
}
void IpcCommunicator::updateChangeContentStartPosition(const QString &filePath, int position)
......
......@@ -118,8 +118,6 @@ public:
using FileContainers = QVector<ClangBackEnd::FileContainer>;
using ProjectPartContainers = QVector<ClangBackEnd::ProjectPartContainer>;
enum class DocumentChangedCheck { NoCheck, RevisionCheck };
public:
IpcCommunicator();
......@@ -130,6 +128,8 @@ public:
void unregisterProjectPartsForEditor(const QStringList &projectPartIds);
void registerUnsavedFilesForEditor(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,
quint32 line,
quint32 column,
......@@ -144,9 +144,8 @@ public:
void updateUnsavedFileFromCppEditorDocument(const QString &filePath);
void updateTranslationUnit(const QString &filePath, const QByteArray &contents, uint documentRevision);
void updateUnsavedFile(const QString &filePath, const QByteArray &contents, uint documentRevision);
void requestDiagnosticsAndHighlighting(const ClangBackEnd::FileContainer &fileContainer,
DocumentChangedCheck documentChangedCheck = DocumentChangedCheck::RevisionCheck);
void requestDiagnosticsAndHighlighting(Core::IDocument *document);
void updateTranslationUnitWithRevisionCheck(const ClangBackEnd::FileContainer &fileContainer);
void updateTranslationUnitWithRevisionCheck(Core::IDocument *document);
void updateChangeContentStartPosition(const QString &filePath, int position);
void registerFallbackProjectPart();
......@@ -167,8 +166,6 @@ private:
void registerCurrentCppEditorDocuments();
void registerCurrentCodeModelUiHeaders();
void requestHighlighting(const ClangBackEnd::FileContainer &fileContainer);
void requestDiagnostics(const ClangBackEnd::FileContainer &fileContainer);
void onBackendRestarted();
void onEditorAboutToClose(Core::IEditor *editor);
......
......@@ -93,7 +93,7 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor()
void ClangEditorDocumentProcessor::run()
{
requestDiagnosticsAndHighlighting();
updateTranslationUnitIfProjectPartExists();
// Run clang parser
disconnect(&m_parserWatcher, &QFutureWatcher<void>::finished,
......@@ -121,7 +121,9 @@ void ClangEditorDocumentProcessor::recalculateSemanticInfoDetached(bool force)
void ClangEditorDocumentProcessor::semanticRehighlight()
{
m_semanticHighlighter.updateFormatMapFromFontSettings();
requestDiagnosticsAndHighlighting(DocumentChangedCheck::NoCheck);
if (m_projectPart)
requestDocumentAnnotations(m_projectPart->id());
}
CppTools::SemanticInfo ClangEditorDocumentProcessor::recalculateSemanticInfo()
......@@ -217,9 +219,9 @@ TextEditor::QuickFixOperations ClangEditorDocumentProcessor::extraRefactoringOpe
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()
......@@ -243,8 +245,7 @@ void ClangEditorDocumentProcessor::updateProjectPartAndTranslationUnitForEditor(
const CppTools::ProjectPart::Ptr projectPart = m_parser->projectPart();
if (isProjectPartLoadedOrIsFallback(projectPart)) {
updateTranslationUnitForEditor(projectPart.data());
requestDiagnosticsAndHighlighting(projectPart.data());
registerTranslationUnitForEditor(projectPart.data());
m_projectPart = projectPart;
}
......@@ -258,54 +259,39 @@ void ClangEditorDocumentProcessor::onParserFinished()
updateProjectPartAndTranslationUnitForEditor();
}
void ClangEditorDocumentProcessor::updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart)
void ClangEditorDocumentProcessor::registerTranslationUnitForEditor(CppTools::ProjectPart *projectPart)
{
QTC_ASSERT(m_modelManagerSupport, return);
IpcCommunicator &ipcCommunicator = m_modelManagerSupport->ipcCommunicator();
if (m_projectPart) {
if (projectPart->id() != m_projectPart->id()) {
ipcCommunicator.unregisterTranslationUnitsForEditor({fileContainer()});
ipcCommunicator.registerTranslationUnitsForEditor({fileContainer(projectPart)});
ipcCommunicator.unregisterTranslationUnitsForEditor({fileContainerWithArguments()});
ipcCommunicator.registerTranslationUnitsForEditor({fileContainerWithArguments(projectPart)});
requestDocumentAnnotations(projectPart->id());
}
} 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()) {
IpcCommunicator &ipcCommunicator = m_modelManagerSupport->ipcCommunicator();
if (m_projectPart) {
const ClangBackEnd::FileContainer fileContainer = fileContainerWithDocumentContent(m_projectPart->id());
const ClangBackEnd::FileContainer fileContainer_ = fileContainer(projectPart);
ipcCommunicator.requestDiagnosticsAndHighlighting(fileContainer_);
m_modelManagerSupport->ipcCommunicator().updateTranslationUnitWithRevisionCheck(fileContainer);
}
}
IpcCommunicator::DocumentChangedCheck
toIpcCommunicatorDocumentChangedCheck(ClangEditorDocumentProcessor::DocumentChangedCheck condition)
void ClangEditorDocumentProcessor::requestDocumentAnnotations(const QString &projectpartId)
{
return condition == ClangEditorDocumentProcessor::DocumentChangedCheck::RevisionCheck
? 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 fileContainer = fileContainerWithDocumentContent(projectpartId);
const auto documentCheck = toIpcCommunicatorDocumentChangedCheck(documentChangedCheck);
ipcCommunicator.requestDiagnosticsAndHighlighting(fileContainer, documentCheck);
}
auto &ipcCommunicator = m_modelManagerSupport->ipcCommunicator();
ipcCommunicator.requestDiagnostics(fileContainer);
ipcCommunicator.requestHighlighting(fileContainer);
}
static CppTools::ProjectPart projectPartForLanguageOption(CppTools::ProjectPart *projectPart)
......@@ -331,7 +317,7 @@ static QStringList fileArguments(const QString &filePath, CppTools::ProjectPart
}
ClangBackEnd::FileContainer
ClangEditorDocumentProcessor::fileContainer(CppTools::ProjectPart *projectPart) const
ClangEditorDocumentProcessor::fileContainerWithArguments(CppTools::ProjectPart *projectPart) const
{
const auto projectPartId = projectPart
? Utf8String::fromString(projectPart->id())
......@@ -341,5 +327,15 @@ ClangEditorDocumentProcessor::fileContainer(CppTools::ProjectPart *projectPart)
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 ClangCodeModel
......@@ -83,12 +83,11 @@ public:
TextEditor::QuickFixOperations
extraRefactoringOperations(const TextEditor::AssistInterface &assistInterface) override;
ClangBackEnd::FileContainer fileContainer() const;
ClangBackEnd::FileContainer fileContainerWithArguments() const;
void clearDiagnosticsWithFixIts();
public:
enum class DocumentChangedCheck { NoCheck, RevisionCheck };
static ClangEditorDocumentProcessor *get(const QString &filePath);
private slots:
......@@ -96,10 +95,11 @@ private slots:
private:
void updateProjectPartAndTranslationUnitForEditor();
void updateTranslationUnitForEditor(CppTools::ProjectPart *projectPart);
void requestDiagnosticsAndHighlighting(CppTools::ProjectPart *projectPart);
void requestDiagnosticsAndHighlighting(DocumentChangedCheck documentChangedCheck = DocumentChangedCheck::RevisionCheck);
ClangBackEnd::FileContainer fileContainer(CppTools::ProjectPart *projectPart) const;
void registerTranslationUnitForEditor(CppTools::ProjectPart *projectPart);
void updateTranslationUnitIfProjectPartExists();
void requestDocumentAnnotations(const QString &projectpartId);
ClangBackEnd::FileContainer fileContainerWithArguments(CppTools::ProjectPart *projectPart) const;
ClangBackEnd::FileContainer fileContainerWithDocumentContent(const QString &projectpartId) const;
private:
ClangDiagnosticManager m_diagnosticManager;
......
......@@ -193,7 +193,7 @@ void ModelManagerSupportClang::onCppDocumentReloadFinishedOnTranslationUnit(bool
if (success) {
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(sender());
connectToTextDocumentContentsChangedForTranslationUnit(textDocument);
m_ipcCommunicator.requestDiagnosticsAndHighlighting(textDocument);
m_ipcCommunicator.updateTranslationUnitWithRevisionCheck(textDocument);
}
}
......@@ -342,7 +342,7 @@ void ModelManagerSupportClang::unregisterTranslationUnitsWithProjectParts(
{
const auto processors = clangProcessorsWithProjectParts(projectPartIds);
foreach (ClangEditorDocumentProcessor *processor, processors) {
m_ipcCommunicator.unregisterTranslationUnitsForEditor({processor->fileContainer()});
m_ipcCommunicator.unregisterTranslationUnitsForEditor({processor->fileContainerWithArguments()});
processor->clearProjectPart();
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