Clang: Rename "Editor Updates" to "Document Annotations"

"Editor Updates" are not to the point since what we generate is for the
document.

Change-Id: I94ceeca5c85c7cf01cc659ca55320d07010c8617
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-11-27 15:15:28 +01:00
parent 1410bf3faf
commit ed4bfff644
7 changed files with 119 additions and 119 deletions

View File

@@ -66,40 +66,40 @@
namespace ClangBackEnd { namespace ClangBackEnd {
namespace { namespace {
const int delayedEditorUpdatesTimerInterval = 300; const int delayedDocumentAnnotationsTimerInterval = 300;
} }
ClangIpcServer::ClangIpcServer() ClangIpcServer::ClangIpcServer()
: translationUnits(projects, unsavedFiles) : translationUnits(projects, unsavedFiles)
{ {
const auto sendEditorUpdates const auto sendDocumentAnnotations
= [this] (const DiagnosticsChangedMessage &diagnosticsMessage, = [this] (const DiagnosticsChangedMessage &diagnosticsMessage,
const HighlightingChangedMessage &highlightingsMessage) { const HighlightingChangedMessage &highlightingsMessage) {
client()->diagnosticsChanged(diagnosticsMessage); client()->diagnosticsChanged(diagnosticsMessage);
client()->highlightingChanged(highlightingsMessage); client()->highlightingChanged(highlightingsMessage);
}; };
const auto sendDelayedEditorUpdates = [this] () { const auto sendDelayedDocumentAnnotations = [this] () {
try { try {
auto editorUpdatesSendState = translationUnits.sendDelayedEditorUpdates(); auto sendState = translationUnits.sendDocumentAnnotations();
if (editorUpdatesSendState == EditorUpdatesSendState::MaybeThereAreMoreEditorUpdates) if (sendState == DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations)
sendDelayedEditorUpdatesTimer.setInterval(0); sendDocumentAnnotationsTimer.setInterval(0);
else else
sendDelayedEditorUpdatesTimer.stop(); sendDocumentAnnotationsTimer.stop();
} catch (const std::exception &exception) { } catch (const std::exception &exception) {
qWarning() << "Error in ClangIpcServer::sendDelayedEditorUpdatesTimer:" << exception.what(); qWarning() << "Error in ClangIpcServer::sendDelayedDocumentAnnotationsTimer:" << exception.what();
} }
}; };
const auto onFileChanged = [this] (const Utf8String &filePath) { const auto onFileChanged = [this] (const Utf8String &filePath) {
startSendDelayedEditorUpdatesTimerIfFileIsNotATranslationUnit(filePath); startDocumentAnnotationsTimerIfFileIsNotATranslationUnit(filePath);
}; };
translationUnits.setSendDelayedEditorUpdatesCallback(sendEditorUpdates); translationUnits.setSendDocumentAnnotationsCallback(sendDocumentAnnotations);
QObject::connect(&sendDelayedEditorUpdatesTimer, QObject::connect(&sendDocumentAnnotationsTimer,
&QTimer::timeout, &QTimer::timeout,
sendDelayedEditorUpdates); sendDelayedDocumentAnnotations);
QObject::connect(translationUnits.clangFileSystemWatcher(), QObject::connect(translationUnits.clangFileSystemWatcher(),
&ClangFileSystemWatcher::fileChanged, &ClangFileSystemWatcher::fileChanged,
@@ -118,7 +118,7 @@ void ClangIpcServer::registerTranslationUnitsForEditor(const ClangBackEnd::Regis
try { try {
translationUnits.create(message.fileContainers()); translationUnits.create(message.fileContainers());
unsavedFiles.createOrUpdate(message.fileContainers()); unsavedFiles.createOrUpdate(message.fileContainers());
sendDelayedEditorUpdatesTimer.start(0); sendDocumentAnnotationsTimer.start(0);
} catch (const ProjectPartDoNotExistException &exception) { } catch (const ProjectPartDoNotExistException &exception) {
client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds())); client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds()));
} catch (const std::exception &exception) { } catch (const std::exception &exception) {
@@ -135,7 +135,7 @@ void ClangIpcServer::updateTranslationUnitsForEditor(const UpdateTranslationUnit
if (newerFileContainers.size() > 0) { if (newerFileContainers.size() > 0) {
translationUnits.update(newerFileContainers); translationUnits.update(newerFileContainers);
unsavedFiles.createOrUpdate(newerFileContainers); unsavedFiles.createOrUpdate(newerFileContainers);
sendDelayedEditorUpdatesTimer.start(delayedEditorUpdatesTimerInterval); sendDocumentAnnotationsTimer.start(delayedDocumentAnnotationsTimerInterval);
} }
} catch (const ProjectPartDoNotExistException &exception) { } catch (const ProjectPartDoNotExistException &exception) {
client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds())); client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds()));
@@ -193,7 +193,7 @@ void ClangIpcServer::registerUnsavedFilesForEditor(const RegisterUnsavedFilesFor
try { try {
unsavedFiles.createOrUpdate(message.fileContainers()); unsavedFiles.createOrUpdate(message.fileContainers());
translationUnits.updateTranslationUnitsWithChangedDependencies(message.fileContainers()); translationUnits.updateTranslationUnitsWithChangedDependencies(message.fileContainers());
sendDelayedEditorUpdatesTimer.start(delayedEditorUpdatesTimerInterval); sendDocumentAnnotationsTimer.start(delayedDocumentAnnotationsTimerInterval);
} catch (const ProjectPartDoNotExistException &exception) { } catch (const ProjectPartDoNotExistException &exception) {
client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds())); client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds()));
} catch (const std::exception &exception) { } catch (const std::exception &exception) {
@@ -292,10 +292,10 @@ const TranslationUnits &ClangIpcServer::translationUnitsForTestOnly() const
return translationUnits; return translationUnits;
} }
void ClangIpcServer::startSendDelayedEditorUpdatesTimerIfFileIsNotATranslationUnit(const Utf8String &filePath) void ClangIpcServer::startDocumentAnnotationsTimerIfFileIsNotATranslationUnit(const Utf8String &filePath)
{ {
if (!translationUnits.hasTranslationUnit(filePath)) if (!translationUnits.hasTranslationUnit(filePath))
sendDelayedEditorUpdatesTimer.start(0); sendDocumentAnnotationsTimer.start(0);
} }
} }

View File

@@ -67,13 +67,13 @@ public:
const TranslationUnits &translationUnitsForTestOnly() const; const TranslationUnits &translationUnitsForTestOnly() const;
private: private:
void startSendDelayedEditorUpdatesTimerIfFileIsNotATranslationUnit(const Utf8String &filePath); void startDocumentAnnotationsTimerIfFileIsNotATranslationUnit(const Utf8String &filePath);
private: private:
ProjectParts projects; ProjectParts projects;
UnsavedFiles unsavedFiles; UnsavedFiles unsavedFiles;
TranslationUnits translationUnits; TranslationUnits translationUnits;
QTimer sendDelayedEditorUpdatesTimer; QTimer sendDocumentAnnotationsTimer;
}; };
} // namespace ClangBackEnd } // namespace ClangBackEnd

View File

@@ -166,73 +166,73 @@ void TranslationUnits::updateTranslationUnitsWithChangedDependencies(const QVect
updateTranslationUnitsWithChangedDependency(fileContainer.filePath()); updateTranslationUnitsWithChangedDependency(fileContainer.filePath());
} }
EditorUpdatesSendState TranslationUnits::sendDelayedEditorUpdates() DocumentAnnotationsSendState TranslationUnits::sendDocumentAnnotations()
{ {
auto editorUpdatesSendState = sendDelayedEditorUpdatesForCurrentEditor(); auto documentAnnotationsSendState = sendDocumentAnnotationsForCurrentEditor();
if (editorUpdatesSendState == EditorUpdatesSendState::NoEditorUpdatesSend) if (documentAnnotationsSendState == DocumentAnnotationsSendState::NoDocumentAnnotationsSent)
editorUpdatesSendState = sendDelayedEditorUpdatesForVisibleEditors(); documentAnnotationsSendState = sendDocumentAnnotationsForVisibleEditors();
if (editorUpdatesSendState == EditorUpdatesSendState::NoEditorUpdatesSend) if (documentAnnotationsSendState == DocumentAnnotationsSendState::NoDocumentAnnotationsSent)
editorUpdatesSendState = sendDelayedEditorUpdatesForAll(); documentAnnotationsSendState = sendDocumentAnnotationsForAll();
return editorUpdatesSendState; return documentAnnotationsSendState;
} }
template<class Predicate> template<class Predicate>
EditorUpdatesSendState TranslationUnits::sendDelayedEditorUpdates(Predicate predicate) DocumentAnnotationsSendState TranslationUnits::sendDocumentAnnotations(Predicate predicate)
{ {
auto foundTranslationUnit = std::find_if(translationUnits_.begin(), auto foundTranslationUnit = std::find_if(translationUnits_.begin(),
translationUnits_.end(), translationUnits_.end(),
predicate); predicate);
if (foundTranslationUnit != translationUnits().end()) { if (foundTranslationUnit != translationUnits().end()) {
sendDelayedEditorUpdates(*foundTranslationUnit); sendDocumentAnnotations(*foundTranslationUnit);
return EditorUpdatesSendState::MaybeThereAreMoreEditorUpdates; return DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations;
} }
return EditorUpdatesSendState::NoEditorUpdatesSend; return DocumentAnnotationsSendState::NoDocumentAnnotationsSent;
} }
namespace { namespace {
bool translationUnitHasEditorDocumentUpdates(const TranslationUnit &translationUnit) bool translationUnitHasNewDocumentAnnotations(const TranslationUnit &translationUnit)
{ {
return translationUnit.hasNewDiagnostics() || translationUnit.hasNewHighlightingInformations(); return translationUnit.hasNewDiagnostics() || translationUnit.hasNewHighlightingInformations();
} }
} }
EditorUpdatesSendState TranslationUnits::sendDelayedEditorUpdatesForCurrentEditor() DocumentAnnotationsSendState TranslationUnits::sendDocumentAnnotationsForCurrentEditor()
{ {
auto hasEditorUpdatesForCurrentEditor = [] (const TranslationUnit &translationUnit) { auto hasDocumentAnnotationsForCurrentEditor = [] (const TranslationUnit &translationUnit) {
return translationUnit.isUsedByCurrentEditor() return translationUnit.isUsedByCurrentEditor()
&& translationUnitHasEditorDocumentUpdates(translationUnit); && translationUnitHasNewDocumentAnnotations(translationUnit);
}; };
return sendDelayedEditorUpdates(hasEditorUpdatesForCurrentEditor); return sendDocumentAnnotations(hasDocumentAnnotationsForCurrentEditor);
} }
EditorUpdatesSendState TranslationUnits::sendDelayedEditorUpdatesForVisibleEditors() DocumentAnnotationsSendState TranslationUnits::sendDocumentAnnotationsForVisibleEditors()
{ {
auto hasEditorUpdatesForVisibleEditor = [] (const TranslationUnit &translationUnit) { auto hasDocumentAnnotationsForVisibleEditor = [] (const TranslationUnit &translationUnit) {
return translationUnit.isVisibleInEditor() return translationUnit.isVisibleInEditor()
&& translationUnitHasEditorDocumentUpdates(translationUnit); && translationUnitHasNewDocumentAnnotations(translationUnit);
}; };
return sendDelayedEditorUpdates(hasEditorUpdatesForVisibleEditor); return sendDocumentAnnotations(hasDocumentAnnotationsForVisibleEditor);
} }
EditorUpdatesSendState TranslationUnits::sendDelayedEditorUpdatesForAll() DocumentAnnotationsSendState TranslationUnits::sendDocumentAnnotationsForAll()
{ {
auto hasEditorUpdates = [] (const TranslationUnit &translationUnit) { auto hasDocumentAnnotations = [] (const TranslationUnit &translationUnit) {
return translationUnitHasEditorDocumentUpdates(translationUnit); return translationUnitHasNewDocumentAnnotations(translationUnit);
}; };
return sendDelayedEditorUpdates(hasEditorUpdates); return sendDocumentAnnotations(hasDocumentAnnotations);
} }
void TranslationUnits::setSendDelayedEditorUpdatesCallback(DelayedEditorUpdatesCallback &&callback) void TranslationUnits::setSendDocumentAnnotationsCallback(SendDocumentAnnotationsCallback &&callback)
{ {
sendDelayedEditorUpdatesCallback = std::move(callback); sendDocumentAnnotationsCallback = std::move(callback);
} }
QVector<FileContainer> TranslationUnits::newerFileContainers(const QVector<FileContainer> &fileContainers) const QVector<FileContainer> TranslationUnits::newerFileContainers(const QVector<FileContainer> &fileContainers) const
@@ -354,9 +354,9 @@ void TranslationUnits::checkIfTranslationUnitsForFilePathsDoesExists(const QVect
} }
} }
void TranslationUnits::sendDelayedEditorUpdates(const TranslationUnit &translationUnit) void TranslationUnits::sendDocumentAnnotations(const TranslationUnit &translationUnit)
{ {
if (sendDelayedEditorUpdatesCallback) { if (sendDocumentAnnotationsCallback) {
const auto fileContainer = translationUnit.fileContainer(); const auto fileContainer = translationUnit.fileContainer();
DiagnosticsChangedMessage diagnosticsMessage(fileContainer, DiagnosticsChangedMessage diagnosticsMessage(fileContainer,
translationUnit.mainFileDiagnostics()); translationUnit.mainFileDiagnostics());
@@ -364,8 +364,8 @@ void TranslationUnits::sendDelayedEditorUpdates(const TranslationUnit &translati
translationUnit.highlightingInformations().toHighlightingMarksContainers(), translationUnit.highlightingInformations().toHighlightingMarksContainers(),
translationUnit.skippedSourceRanges().toSourceRangeContainers()); translationUnit.skippedSourceRanges().toSourceRangeContainers());
sendDelayedEditorUpdatesCallback(std::move(diagnosticsMessage), sendDocumentAnnotationsCallback(std::move(diagnosticsMessage),
std::move(highlightingsMessage)); std::move(highlightingsMessage));
} }
} }

View File

@@ -48,17 +48,18 @@ class UnsavedFiles;
class DiagnosticsChangedMessage; class DiagnosticsChangedMessage;
class HighlightingChangedMessage; class HighlightingChangedMessage;
enum class EditorUpdatesSendState enum class DocumentAnnotationsSendState
{ {
NoEditorUpdatesSend, NoDocumentAnnotationsSent,
MaybeThereAreMoreEditorUpdates, MaybeThereAreDocumentAnnotations,
}; };
class TranslationUnits class TranslationUnits
{ {
public: public:
using DelayedEditorUpdatesCallback = std::function<void (const DiagnosticsChangedMessage &, using SendDocumentAnnotationsCallback
const HighlightingChangedMessage &)>; = std::function<void (const DiagnosticsChangedMessage &,
const HighlightingChangedMessage &)>;
public: public:
TranslationUnits(ProjectParts &projectParts, UnsavedFiles &unsavedFiles); TranslationUnits(ProjectParts &projectParts, UnsavedFiles &unsavedFiles);
@@ -83,13 +84,12 @@ public:
void updateTranslationUnitsWithChangedDependency(const Utf8String &filePath); void updateTranslationUnitsWithChangedDependency(const Utf8String &filePath);
void updateTranslationUnitsWithChangedDependencies(const QVector<FileContainer> &fileContainers); void updateTranslationUnitsWithChangedDependencies(const QVector<FileContainer> &fileContainers);
EditorUpdatesSendState sendDelayedEditorUpdatesForCurrentEditor(); DocumentAnnotationsSendState sendDocumentAnnotationsForCurrentEditor();
EditorUpdatesSendState sendDelayedEditorUpdatesForVisibleEditors(); DocumentAnnotationsSendState sendDocumentAnnotationsForVisibleEditors();
EditorUpdatesSendState sendDelayedEditorUpdatesForAll(); DocumentAnnotationsSendState sendDocumentAnnotationsForAll();
DocumentAnnotationsSendState sendDocumentAnnotations();
EditorUpdatesSendState sendDelayedEditorUpdates(); void setSendDocumentAnnotationsCallback(SendDocumentAnnotationsCallback &&callback);
void setSendDelayedEditorUpdatesCallback(DelayedEditorUpdatesCallback &&callback);
QVector<FileContainer> newerFileContainers(const QVector<FileContainer> &fileContainers) const; QVector<FileContainer> newerFileContainers(const QVector<FileContainer> &fileContainers) const;
@@ -108,15 +108,15 @@ private:
void checkIfTranslationUnitsDoesNotExists(const QVector<FileContainer> &fileContainers) const; void checkIfTranslationUnitsDoesNotExists(const QVector<FileContainer> &fileContainers) const;
void checkIfTranslationUnitsForFilePathsDoesExists(const QVector<FileContainer> &fileContainers) const; void checkIfTranslationUnitsForFilePathsDoesExists(const QVector<FileContainer> &fileContainers) const;
void sendDelayedEditorUpdates(const TranslationUnit &translationUnit);
void removeTranslationUnits(const QVector<FileContainer> &fileContainers); void removeTranslationUnits(const QVector<FileContainer> &fileContainers);
template<class Predicate> template<class Predicate>
EditorUpdatesSendState sendDelayedEditorUpdates(Predicate predicate); DocumentAnnotationsSendState sendDocumentAnnotations(Predicate predicate);
void sendDocumentAnnotations(const TranslationUnit &translationUnit);
private: private:
ClangFileSystemWatcher fileSystemWatcher; ClangFileSystemWatcher fileSystemWatcher;
DelayedEditorUpdatesCallback sendDelayedEditorUpdatesCallback; SendDocumentAnnotationsCallback sendDocumentAnnotationsCallback;
std::vector<TranslationUnit> translationUnits_; std::vector<TranslationUnit> translationUnits_;
ProjectParts &projectParts; ProjectParts &projectParts;
UnsavedFiles &unsavedFiles_; UnsavedFiles &unsavedFiles_;

View File

@@ -27,27 +27,27 @@
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
** **
****************************************************************************/ ****************************************************************************/
#ifndef MOCKSENDEDITORUPDATESCALLBACK_H #ifndef MOCKSENDDOCUMENTANNOTATIONSCALLBACK_H
#define MOCKSENDEDITORUPDATESCALLBACK_H #define MOCKSENDDOCUMENTANNOTATIONSCALLBACK_H
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gmock/gmock-matchers.h> #include <gmock/gmock-matchers.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "gtest-qt-printing.h" #include "gtest-qt-printing.h"
class SendEditorUpdatesCallback class SendDocumentAnnotationsCallback
{ {
public: public:
virtual ~SendEditorUpdatesCallback() = default; virtual ~SendDocumentAnnotationsCallback() = default;
virtual void sendEditorUpdates() = 0; virtual void sendDocumentAnnotations() = 0;
}; };
class MockSendEditorUpdatesCallback : public SendEditorUpdatesCallback class MockSendDocumentAnnotationsCallback : public SendDocumentAnnotationsCallback
{ {
public: public:
MOCK_METHOD0(sendEditorUpdates, MOCK_METHOD0(sendDocumentAnnotations,
void()); void());
}; };
#endif // MOCKSENDEDITORUPDATESCALLBACK_H #endif // MOCKSENDDOCUMENTANNOTATIONSCALLBACK_H

View File

@@ -47,7 +47,7 @@
#include <clang-c/Index.h> #include <clang-c/Index.h>
#include "mocksendeditorupdatescallback.h" #include "mocksenddocumentannotationscallback.h"
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gmock/gmock-matchers.h> #include <gmock/gmock-matchers.h>
@@ -59,7 +59,7 @@ using ClangBackEnd::UnsavedFiles;
using ClangBackEnd::ProjectPart; using ClangBackEnd::ProjectPart;
using ClangBackEnd::DiagnosticsChangedMessage; using ClangBackEnd::DiagnosticsChangedMessage;
using ClangBackEnd::HighlightingChangedMessage; using ClangBackEnd::HighlightingChangedMessage;
using ClangBackEnd::EditorUpdatesSendState; using ClangBackEnd::DocumentAnnotationsSendState;
using testing::IsNull; using testing::IsNull;
using testing::NotNull; using testing::NotNull;
@@ -87,15 +87,15 @@ class TranslationUnits : public ::testing::Test
{ {
protected: protected:
void SetUp() override; void SetUp() override;
void sendAllEditorUpdates(); void sendAllDocumentAnnotations();
void sendAllEditorUpdatesForCurrentEditor(); void sendAllDocumentAnnotationsForCurrentEditor();
void sendAllEditorUpdatesForVisibleEditors(); void sendAllDocumentAnnotationsForVisibleEditors();
protected: protected:
ClangBackEnd::ProjectParts projects; ClangBackEnd::ProjectParts projects;
ClangBackEnd::UnsavedFiles unsavedFiles; ClangBackEnd::UnsavedFiles unsavedFiles;
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles}; ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
MockSendEditorUpdatesCallback mockSendEditorUpdatesCallback; MockSendDocumentAnnotationsCallback mockSendDocumentAnnotationsCallback;
const Utf8String filePath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp"); const Utf8String filePath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.cpp");
const Utf8String headerPath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.h"); const Utf8String headerPath = Utf8StringLiteral(TESTDATA_DIR"/translationunits.h");
const Utf8String nonExistingFilePath = Utf8StringLiteral("foo.cpp"); const Utf8String nonExistingFilePath = Utf8StringLiteral("foo.cpp");
@@ -374,55 +374,55 @@ TEST_F(TranslationUnits, IsNotVisibleEditorAfterBeingVisible)
ASSERT_FALSE(translationUnit.isVisibleInEditor()); ASSERT_FALSE(translationUnit.isVisibleInEditor());
} }
TEST_F(TranslationUnits, DoNotSendEditorUpdatesIfThereIsNothingToSend) TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsIfThereIsNothingToSend)
{ {
EXPECT_CALL(mockSendEditorUpdatesCallback, sendEditorUpdates()).Times(0); EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0);
sendAllEditorUpdates(); sendAllDocumentAnnotations();
} }
TEST_F(TranslationUnits, SendEditorUpdatessAfterTranslationUnitCreation) TEST_F(TranslationUnits, SendDocumentAnnotationsAfterTranslationUnitCreation)
{ {
translationUnits.create({fileContainer, headerContainer}); translationUnits.create({fileContainer, headerContainer});
EXPECT_CALL(mockSendEditorUpdatesCallback, sendEditorUpdates()).Times(2); EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(2);
sendAllEditorUpdates(); sendAllDocumentAnnotations();
} }
TEST_F(TranslationUnits, DoNotSendEditorUpdatesAfterGettingEditorUpdates) TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsAfterGettingDocumentAnnotations)
{ {
translationUnits.create({fileContainer, headerContainer}); translationUnits.create({fileContainer, headerContainer});
auto translationUnit = translationUnits.translationUnit(fileContainer); auto translationUnit = translationUnits.translationUnit(fileContainer);
translationUnit.diagnostics(); // Reset translationUnit.diagnostics(); // Reset
translationUnit.highlightingInformations(); // Reset translationUnit.highlightingInformations(); // Reset
EXPECT_CALL(mockSendEditorUpdatesCallback, sendEditorUpdates()).Times(1); EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(1);
sendAllEditorUpdates(); sendAllDocumentAnnotations();
} }
TEST_F(TranslationUnits, SendEditorUpdatesForCurrentEditor) TEST_F(TranslationUnits, SendDocumentAnnotationsForCurrentEditor)
{ {
translationUnits.create({fileContainer, headerContainer}); translationUnits.create({fileContainer, headerContainer});
auto translationUnit = translationUnits.translationUnit(fileContainer); auto translationUnit = translationUnits.translationUnit(fileContainer);
translationUnit.setIsUsedByCurrentEditor(true); translationUnit.setIsUsedByCurrentEditor(true);
EXPECT_CALL(mockSendEditorUpdatesCallback, sendEditorUpdates()).Times(1); EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(1);
sendAllEditorUpdatesForCurrentEditor(); sendAllDocumentAnnotationsForCurrentEditor();
} }
TEST_F(TranslationUnits, DoNotSendEditorUpdatesForCurrentEditorIfThereIsNoCurrentEditor) TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsForCurrentEditorIfThereIsNoCurrentEditor)
{ {
translationUnits.create({fileContainer, headerContainer}); translationUnits.create({fileContainer, headerContainer});
EXPECT_CALL(mockSendEditorUpdatesCallback, sendEditorUpdates()).Times(0); EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0);
sendAllEditorUpdatesForCurrentEditor(); sendAllDocumentAnnotationsForCurrentEditor();
} }
TEST_F(TranslationUnits, DoNotSendEditorUpdatesForCurrentEditorAfterGettingEditorUpdates) TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsForCurrentEditorAfterGettingDocumentAnnotations)
{ {
translationUnits.create({fileContainer, headerContainer}); translationUnits.create({fileContainer, headerContainer});
auto translationUnit = translationUnits.translationUnit(fileContainer); auto translationUnit = translationUnits.translationUnit(fileContainer);
@@ -430,21 +430,21 @@ TEST_F(TranslationUnits, DoNotSendEditorUpdatesForCurrentEditorAfterGettingEdito
translationUnit.diagnostics(); // Reset translationUnit.diagnostics(); // Reset
translationUnit.highlightingInformations(); // Reset translationUnit.highlightingInformations(); // Reset
EXPECT_CALL(mockSendEditorUpdatesCallback, sendEditorUpdates()).Times(0); EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0);
sendAllEditorUpdatesForCurrentEditor(); sendAllDocumentAnnotationsForCurrentEditor();
} }
TEST_F(TranslationUnits, DoNotSendEditorUpdatesForVisibleEditorIfThereAreNoVisibleEditors) TEST_F(TranslationUnits, DoNotSendDocumentAnnotationsForVisibleEditorIfThereAreNoVisibleEditors)
{ {
translationUnits.create({fileContainer, headerContainer}); translationUnits.create({fileContainer, headerContainer});
EXPECT_CALL(mockSendEditorUpdatesCallback, sendEditorUpdates()).Times(0); EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(0);
translationUnits.sendDelayedEditorUpdatesForVisibleEditors(); translationUnits.sendDocumentAnnotationsForVisibleEditors();
} }
TEST_F(TranslationUnits, SendEditorUpdatesForVisibleEditors) TEST_F(TranslationUnits, SendDocumentAnnotationsForVisibleEditors)
{ {
translationUnits.create({fileContainer, headerContainer}); translationUnits.create({fileContainer, headerContainer});
auto fileTranslationUnit = translationUnits.translationUnit(fileContainer); auto fileTranslationUnit = translationUnits.translationUnit(fileContainer);
@@ -452,12 +452,12 @@ TEST_F(TranslationUnits, SendEditorUpdatesForVisibleEditors)
auto headerTranslationUnit = translationUnits.translationUnit(headerContainer); auto headerTranslationUnit = translationUnits.translationUnit(headerContainer);
headerTranslationUnit.setIsVisibleInEditor(true); headerTranslationUnit.setIsVisibleInEditor(true);
EXPECT_CALL(mockSendEditorUpdatesCallback, sendEditorUpdates()).Times(2); EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(2);
sendAllEditorUpdatesForVisibleEditors(); sendAllDocumentAnnotationsForVisibleEditors();
} }
TEST_F(TranslationUnits, SendOnlyOneEditorUpdateForVisibleEditor) TEST_F(TranslationUnits, SendDocumentAnnotationsOnlyOnceForVisibleEditor)
{ {
translationUnits.create({fileContainer, headerContainer}); translationUnits.create({fileContainer, headerContainer});
auto fileTranslationUnit = translationUnits.translationUnit(fileContainer); auto fileTranslationUnit = translationUnits.translationUnit(fileContainer);
@@ -467,9 +467,9 @@ TEST_F(TranslationUnits, SendOnlyOneEditorUpdateForVisibleEditor)
headerTranslationUnit.diagnostics(); // Reset headerTranslationUnit.diagnostics(); // Reset
headerTranslationUnit.highlightingInformations(); // Reset headerTranslationUnit.highlightingInformations(); // Reset
EXPECT_CALL(mockSendEditorUpdatesCallback, sendEditorUpdates()).Times(1); EXPECT_CALL(mockSendDocumentAnnotationsCallback, sendDocumentAnnotations()).Times(1);
sendAllEditorUpdatesForVisibleEditors(); sendAllDocumentAnnotationsForVisibleEditors();
} }
void TranslationUnits::SetUp() void TranslationUnits::SetUp()
@@ -477,33 +477,33 @@ void TranslationUnits::SetUp()
projects.createOrUpdate({ClangBackEnd::ProjectPartContainer(projectPartId)}); projects.createOrUpdate({ClangBackEnd::ProjectPartContainer(projectPartId)});
auto callback = [&] (const DiagnosticsChangedMessage &, const HighlightingChangedMessage &) { auto callback = [&] (const DiagnosticsChangedMessage &, const HighlightingChangedMessage &) {
mockSendEditorUpdatesCallback.sendEditorUpdates(); mockSendDocumentAnnotationsCallback.sendDocumentAnnotations();
}; };
translationUnits.setSendDelayedEditorUpdatesCallback(callback); translationUnits.setSendDocumentAnnotationsCallback(callback);
} }
void TranslationUnits::sendAllEditorUpdates() void TranslationUnits::sendAllDocumentAnnotations()
{ {
auto editorUpdatesSendState = EditorUpdatesSendState::MaybeThereAreMoreEditorUpdates; auto sendState = DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations;
while (editorUpdatesSendState == EditorUpdatesSendState::MaybeThereAreMoreEditorUpdates) while (sendState == DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations)
editorUpdatesSendState = translationUnits.sendDelayedEditorUpdates(); sendState = translationUnits.sendDocumentAnnotations();
} }
void TranslationUnits::sendAllEditorUpdatesForCurrentEditor() void TranslationUnits::sendAllDocumentAnnotationsForCurrentEditor()
{ {
auto editorUpdatesSendState = EditorUpdatesSendState::MaybeThereAreMoreEditorUpdates; auto sendState = DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations;
while (editorUpdatesSendState == EditorUpdatesSendState::MaybeThereAreMoreEditorUpdates) while (sendState == DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations)
editorUpdatesSendState = translationUnits.sendDelayedEditorUpdatesForCurrentEditor(); sendState = translationUnits.sendDocumentAnnotationsForCurrentEditor();
} }
void TranslationUnits::sendAllEditorUpdatesForVisibleEditors() void TranslationUnits::sendAllDocumentAnnotationsForVisibleEditors()
{ {
auto editorUpdatesSendState = EditorUpdatesSendState::MaybeThereAreMoreEditorUpdates; auto sendState = DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations;
while (editorUpdatesSendState == EditorUpdatesSendState::MaybeThereAreMoreEditorUpdates) while (sendState == DocumentAnnotationsSendState::MaybeThereAreDocumentAnnotations)
editorUpdatesSendState = translationUnits.sendDelayedEditorUpdatesForVisibleEditors(); sendState = translationUnits.sendDocumentAnnotationsForVisibleEditors();
} }
} }

View File

@@ -68,6 +68,6 @@ HEADERS += \
spydummy.h \ spydummy.h \
matcher-diagnosticcontainer.h \ matcher-diagnosticcontainer.h \
chunksreportedmonitor.h \ chunksreportedmonitor.h \
mocksendeditorupdatescallback.h mocksenddocumentannotationscallback.h
OTHER_FILES += $$files(data/*) OTHER_FILES += $$files(data/*)