From 250c8d662b43f97d485e9833e9a3df2daa2c1d63 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Tue, 13 Oct 2015 15:56:41 +0200 Subject: [PATCH] Clang: Add UpdateTranslationUnitsForEditorMessage If an editor is changing all translation units independent of their project part they must be updated too. So we introduce a new message to update all translation units with the same file path. Change-Id: I70d0ea2bbca9fa880111ff7219573e54f3277026 Reviewed-by: Nikolai Kosjar --- .../clangbackendipc/clangbackendipc-lib.pri | 6 +- .../clangbackendipc/clangbackendipc_global.h | 1 - src/libs/clangbackendipc/cmbmessages.cpp | 5 + src/libs/clangbackendipc/ipcclientinterface.h | 1 + .../clangbackendipc/ipcserverinterface.cpp | 4 + src/libs/clangbackendipc/ipcserverinterface.h | 1 + src/libs/clangbackendipc/ipcserverproxy.cpp | 6 ++ src/libs/clangbackendipc/ipcserverproxy.h | 1 + ...updatetranslationunitsforeditormessage.cpp | 99 +++++++++++++++++++ .../updatetranslationunitsforeditormessage.h | 69 +++++++++++++ .../clangbackendipcintegration.cpp | 72 ++++++++++---- .../clangbackendipcintegration.h | 5 + .../clangcompletionassistprocessor.cpp | 31 +++--- .../clangcompletionassistprocessor.h | 2 +- .../clangcompletionassistprovider.cpp | 25 ++--- src/plugins/clangcodemodel/clangutils.cpp | 9 ++ src/plugins/clangcodemodel/clangutils.h | 1 + .../test/clangcodecompletion_test.cpp | 16 ++- src/plugins/cpptools/editordocumenthandle.cpp | 4 +- src/plugins/cpptools/editordocumenthandle.h | 5 +- .../ipcsource/clangbackendclangipc-source.pri | 6 +- .../clangbackend/ipcsource/clangipcserver.cpp | 37 +++++-- .../clangbackend/ipcsource/clangipcserver.h | 3 + .../translationunitalreadyexistsexception.cpp | 65 ++++++++++++ .../translationunitalreadyexistsexception.h | 61 ++++++++++++ .../translationunitdoesnotexistexception.cpp | 8 +- .../translationunitdoesnotexistexception.h | 2 +- .../ipcsource/translationunits.cpp | 71 ++++++++++++- .../clangbackend/ipcsource/translationunits.h | 12 ++- tests/unit/echoserver/echoipcserver.cpp | 6 ++ tests/unit/echoserver/echoipcserver.h | 1 + tests/unit/unittest/clangipcservertest.cpp | 56 +++++++++-- .../unittest/clientserverinprocesstest.cpp | 12 +++ tests/unit/unittest/codecompletiontest.cpp | 14 +-- tests/unit/unittest/mockipcserver.h | 2 + .../unittest/readandwritemessageblocktest.cpp | 6 ++ tests/unit/unittest/translationunitstest.cpp | 54 +++++++--- 37 files changed, 673 insertions(+), 106 deletions(-) create mode 100644 src/libs/clangbackendipc/updatetranslationunitsforeditormessage.cpp create mode 100644 src/libs/clangbackendipc/updatetranslationunitsforeditormessage.h create mode 100644 src/tools/clangbackend/ipcsource/translationunitalreadyexistsexception.cpp create mode 100644 src/tools/clangbackend/ipcsource/translationunitalreadyexistsexception.h diff --git a/src/libs/clangbackendipc/clangbackendipc-lib.pri b/src/libs/clangbackendipc/clangbackendipc-lib.pri index 1e350bc8d6b..cc11840a043 100644 --- a/src/libs/clangbackendipc/clangbackendipc-lib.pri +++ b/src/libs/clangbackendipc/clangbackendipc-lib.pri @@ -45,7 +45,8 @@ SOURCES += $$PWD/ipcserverinterface.cpp \ $$PWD/fixitcontainer.cpp \ $$PWD/requestdiagnosticsmessage.cpp \ $$PWD/registerunsavedfilesforeditormessage.cpp \ - $$PWD/unregisterunsavedfilesforeditormessage.cpp + $$PWD/unregisterunsavedfilesforeditormessage.cpp \ + $$PWD/updatetranslationunitsforeditormessage.cpp HEADERS += \ $$PWD/ipcserverinterface.h \ @@ -85,6 +86,7 @@ HEADERS += \ $$PWD/fixitcontainer.h \ $$PWD/requestdiagnosticsmessage.h \ $$PWD/registerunsavedfilesforeditormessage.h \ - $$PWD/unregisterunsavedfilesforeditormessage.h + $$PWD/unregisterunsavedfilesforeditormessage.h \ + $$PWD/updatetranslationunitsforeditormessage.h contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols diff --git a/src/libs/clangbackendipc/clangbackendipc_global.h b/src/libs/clangbackendipc/clangbackendipc_global.h index 5856e23221c..544a5b15ac1 100644 --- a/src/libs/clangbackendipc/clangbackendipc_global.h +++ b/src/libs/clangbackendipc/clangbackendipc_global.h @@ -44,7 +44,6 @@ #endif namespace ClangBackEnd { -CMBIPC_EXPORT void registerTypes(); enum class DiagnosticSeverity // one to one mapping of the clang enum numbers { diff --git a/src/libs/clangbackendipc/cmbmessages.cpp b/src/libs/clangbackendipc/cmbmessages.cpp index a921731b671..fcdc5ba9fd3 100644 --- a/src/libs/clangbackendipc/cmbmessages.cpp +++ b/src/libs/clangbackendipc/cmbmessages.cpp @@ -48,6 +48,7 @@ #include "sourcerangecontainer.h" #include "translationunitdoesnotexistmessage.h" #include "unregisterunsavedfilesforeditormessage.h" +#include "updatetranslationunitsforeditormessage.h" #include @@ -137,6 +138,10 @@ void Messages::registerMessages() qRegisterMetaType(); qRegisterMetaTypeStreamOperators(); QMetaType::registerComparators(); + + qRegisterMetaType(); + qRegisterMetaTypeStreamOperators(); + QMetaType::registerComparators(); } } // namespace ClangBackEnd diff --git a/src/libs/clangbackendipc/ipcclientinterface.h b/src/libs/clangbackendipc/ipcclientinterface.h index e7079fd3b9f..32d17e4c60d 100644 --- a/src/libs/clangbackendipc/ipcclientinterface.h +++ b/src/libs/clangbackendipc/ipcclientinterface.h @@ -37,6 +37,7 @@ namespace ClangBackEnd { class IpcServerInterface; class RegisterTranslationUnitForEditorMessage; +class UpdateTranslationUnitsForEditorMessage; class RegisterProjectPartsForEditorMessage; class UnregisterTranslationUnitsForEditorMessage; class UnregisterProjectPartsForEditorMessage; diff --git a/src/libs/clangbackendipc/ipcserverinterface.cpp b/src/libs/clangbackendipc/ipcserverinterface.cpp index 6e0c3ded626..92ba85a6de7 100644 --- a/src/libs/clangbackendipc/ipcserverinterface.cpp +++ b/src/libs/clangbackendipc/ipcserverinterface.cpp @@ -38,6 +38,7 @@ #include "registerunsavedfilesforeditormessage.h" #include "requestdiagnosticsmessage.h" #include "unregisterunsavedfilesforeditormessage.h" +#include "updatetranslationunitsforeditormessage.h" #include #include @@ -48,6 +49,7 @@ void IpcServerInterface::dispatch(const QVariant &message) { static const int endMessageType = QMetaType::type("ClangBackEnd::EndMessage"); static const int registerTranslationUnitsForEditorMessageType = QMetaType::type("ClangBackEnd::RegisterTranslationUnitForEditorMessage"); + static const int updateTranslationUnitsForEditorMessageType = QMetaType::type("ClangBackEnd::UpdateTranslationUnitsForEditorMessage"); static const int unregisterTranslationUnitsForEditorMessageType = QMetaType::type("ClangBackEnd::UnregisterTranslationUnitsForEditorMessage"); static const int registerProjectPartsForEditorMessageType = QMetaType::type("ClangBackEnd::RegisterProjectPartsForEditorMessage"); static const int unregisterProjectPartsForEditorMessageType = QMetaType::type("ClangBackEnd::UnregisterProjectPartsForEditorMessage"); @@ -62,6 +64,8 @@ void IpcServerInterface::dispatch(const QVariant &message) end(); else if (type == registerTranslationUnitsForEditorMessageType) registerTranslationUnitsForEditor(message.value()); + else if (type == updateTranslationUnitsForEditorMessageType) + updateTranslationUnitsForEditor(message.value()); else if (type == unregisterTranslationUnitsForEditorMessageType) unregisterTranslationUnitsForEditor(message.value()); else if (type == registerProjectPartsForEditorMessageType) diff --git a/src/libs/clangbackendipc/ipcserverinterface.h b/src/libs/clangbackendipc/ipcserverinterface.h index 511d65a6cb3..0682970412c 100644 --- a/src/libs/clangbackendipc/ipcserverinterface.h +++ b/src/libs/clangbackendipc/ipcserverinterface.h @@ -46,6 +46,7 @@ public: virtual void end() = 0; virtual void registerTranslationUnitsForEditor(const RegisterTranslationUnitForEditorMessage &message) = 0; + virtual void updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message) = 0; virtual void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) = 0; virtual void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) = 0; virtual void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) = 0; diff --git a/src/libs/clangbackendipc/ipcserverproxy.cpp b/src/libs/clangbackendipc/ipcserverproxy.cpp index febe3e788dd..a1d9d978be5 100644 --- a/src/libs/clangbackendipc/ipcserverproxy.cpp +++ b/src/libs/clangbackendipc/ipcserverproxy.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -78,6 +79,11 @@ void IpcServerProxy::registerTranslationUnitsForEditor(const RegisterTranslation writeMessageBlock.write(QVariant::fromValue(message)); } +void IpcServerProxy::updateTranslationUnitsForEditor(const ClangBackEnd::UpdateTranslationUnitsForEditorMessage &message) +{ + writeMessageBlock.write(QVariant::fromValue(message)); +} + void IpcServerProxy::unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) { writeMessageBlock.write(QVariant::fromValue(message)); diff --git a/src/libs/clangbackendipc/ipcserverproxy.h b/src/libs/clangbackendipc/ipcserverproxy.h index 9bb2902ad45..a3f52ff128c 100644 --- a/src/libs/clangbackendipc/ipcserverproxy.h +++ b/src/libs/clangbackendipc/ipcserverproxy.h @@ -57,6 +57,7 @@ public: void end() override; void registerTranslationUnitsForEditor(const RegisterTranslationUnitForEditorMessage &message) override; + void updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message) override; void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override; void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) override; void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override; diff --git a/src/libs/clangbackendipc/updatetranslationunitsforeditormessage.cpp b/src/libs/clangbackendipc/updatetranslationunitsforeditormessage.cpp new file mode 100644 index 00000000000..939bdc2f467 --- /dev/null +++ b/src/libs/clangbackendipc/updatetranslationunitsforeditormessage.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "updatetranslationunitsforeditormessage.h" + +#include "container_common.h" + +#include +#include + +#include + +namespace ClangBackEnd { + +UpdateTranslationUnitsForEditorMessage::UpdateTranslationUnitsForEditorMessage(const QVector &fileContainers) + : fileContainers_(fileContainers) +{ +} + +const QVector &UpdateTranslationUnitsForEditorMessage::fileContainers() const +{ + return fileContainers_; +} + +QDataStream &operator<<(QDataStream &out, const UpdateTranslationUnitsForEditorMessage &message) +{ + out << message.fileContainers_; + + return out; +} + +QDataStream &operator>>(QDataStream &in, UpdateTranslationUnitsForEditorMessage &message) +{ + in >> message.fileContainers_; + + return in; +} + +bool operator==(const UpdateTranslationUnitsForEditorMessage &first, const UpdateTranslationUnitsForEditorMessage &second) +{ + return first.fileContainers_ == second.fileContainers_; +} + +bool operator<(const UpdateTranslationUnitsForEditorMessage &first, const UpdateTranslationUnitsForEditorMessage &second) +{ + return compareContainer(first.fileContainers_, second.fileContainers_); +} + +QDebug operator<<(QDebug debug, const UpdateTranslationUnitsForEditorMessage &message) +{ + debug.nospace() << "UpdateTranslationUnitsForEditorMessage("; + + for (const FileContainer &fileContainer : message.fileContainers()) + debug.nospace() << fileContainer<< ", "; + + debug.nospace() << ")"; + + return debug; +} + +void PrintTo(const UpdateTranslationUnitsForEditorMessage &message, ::std::ostream* os) +{ + *os << "UpdateTranslationUnitsForEditorMessage("; + + for (const FileContainer &fileContainer : message.fileContainers()) + PrintTo(fileContainer, os); + + *os << ")"; +} + +} // namespace ClangBackEnd + diff --git a/src/libs/clangbackendipc/updatetranslationunitsforeditormessage.h b/src/libs/clangbackendipc/updatetranslationunitsforeditormessage.h new file mode 100644 index 00000000000..634c8dac4be --- /dev/null +++ b/src/libs/clangbackendipc/updatetranslationunitsforeditormessage.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://www.qt.io/licensing. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_UPDATEFILEFOREDITOR_H +#define CLANGBACKEND_UPDATEFILEFOREDITOR_H + +#include "filecontainer.h" + +#include +#include + +namespace ClangBackEnd { + +class CMBIPC_EXPORT UpdateTranslationUnitsForEditorMessage +{ + friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UpdateTranslationUnitsForEditorMessage &message); + friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UpdateTranslationUnitsForEditorMessage &message); + friend CMBIPC_EXPORT bool operator==(const UpdateTranslationUnitsForEditorMessage &first, const UpdateTranslationUnitsForEditorMessage &second); + friend CMBIPC_EXPORT bool operator<(const UpdateTranslationUnitsForEditorMessage &first, const UpdateTranslationUnitsForEditorMessage &second); + friend void PrintTo(const UpdateTranslationUnitsForEditorMessage &message, ::std::ostream* os); +public: + UpdateTranslationUnitsForEditorMessage() = default; + UpdateTranslationUnitsForEditorMessage(const QVector &fileContainers); + + const QVector &fileContainers() const; + +private: + QVector fileContainers_; +}; + +CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UpdateTranslationUnitsForEditorMessage &message); +CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UpdateTranslationUnitsForEditorMessage &message); +CMBIPC_EXPORT bool operator==(const UpdateTranslationUnitsForEditorMessage &first, const UpdateTranslationUnitsForEditorMessage &second); +CMBIPC_EXPORT bool operator<(const UpdateTranslationUnitsForEditorMessage &first, const UpdateTranslationUnitsForEditorMessage &second); + +CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UpdateTranslationUnitsForEditorMessage &message); +void PrintTo(const UpdateTranslationUnitsForEditorMessage &message, ::std::ostream* os); +} // namespace ClangBackEnd + +Q_DECLARE_METATYPE(ClangBackEnd::UpdateTranslationUnitsForEditorMessage) + +#endif // CLANGBACKEND_UPDATEFILEFOREDITOR_H diff --git a/src/plugins/clangcodemodel/clangbackendipcintegration.cpp b/src/plugins/clangcodemodel/clangbackendipcintegration.cpp index 05c487d130e..ec335f39c6b 100644 --- a/src/plugins/clangcodemodel/clangbackendipcintegration.cpp +++ b/src/plugins/clangcodemodel/clangbackendipcintegration.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include @@ -194,6 +195,7 @@ public: void end() override; void registerTranslationUnitsForEditor(const ClangBackEnd::RegisterTranslationUnitForEditorMessage &message) override; + void updateTranslationUnitsForEditor(const ClangBackEnd::UpdateTranslationUnitsForEditorMessage &message) override; void unregisterTranslationUnitsForEditor(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &message) override; void registerProjectPartsForEditor(const ClangBackEnd::RegisterProjectPartsForEditorMessage &message) override; void unregisterProjectPartsForEditor(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &message) override; @@ -218,6 +220,12 @@ void IpcSender::registerTranslationUnitsForEditor(const RegisterTranslationUnitF m_connection.serverProxy().registerTranslationUnitsForEditor(message); } +void IpcSender::updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message) +{ + QTC_CHECK(m_connection.isConnected()); + m_connection.serverProxy().updateTranslationUnitsForEditor(message); +} + void IpcSender::unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) { QTC_CHECK(m_connection.isConnected()); @@ -368,6 +376,16 @@ void IpcCommunicator::registerProjectsParts(const QListfilePath().toString(); + const QString projectPartId = Utils::projectPartIdForFile(filePath); + + registerTranslationUnitsForEditor({{Utf8String(filePath), + Utf8String(projectPartId), + uint(document->document()->revision())}}); +} + void IpcCommunicator::updateTranslationUnitFromCppEditorDocument(const QString &filePath) { const auto document = CppTools::CppModelManager::instance()->cppEditorDocument(filePath); @@ -388,34 +406,33 @@ CppTools::CppEditorDocumentHandle *cppDocument(const QString &filePath) return CppTools::CppModelManager::instance()->cppEditorDocument(filePath); } -bool documentHasChanged(const QString &filePath, const QString &projectPartId) +bool documentHasChanged(const QString &filePath) { auto *document = cppDocument(filePath); if (document) - return document->sendTracker(projectPartId).shouldSendRevision(document->revision()); + return document->sendTracker().shouldSendRevision(document->revision()); return true; } void setLastSentDocumentRevision(const QString &filePath, - const QString &projectPartId, uint revision) { auto *document = cppDocument(filePath); if (document) - document->sendTracker(projectPartId).setLastSentRevision(int(revision)); + document->sendTracker().setLastSentRevision(int(revision)); } } -void IpcCommunicator::updateTranslationUnit(const QString &filePath, - const QByteArray &contents, - uint documentRevision) +void IpcCommunicator::registerTranslationUnit(const QString &filePath, + const QByteArray &contents, + uint documentRevision) { const QString projectPartId = Utils::projectPartIdForFile(filePath); - if (documentHasChanged(filePath, projectPartId)) { + if (documentHasChanged(filePath)) { const bool hasUnsavedContent = true; registerTranslationUnitsForEditor({{filePath, @@ -424,18 +441,30 @@ void IpcCommunicator::updateTranslationUnit(const QString &filePath, hasUnsavedContent, documentRevision}}); - setLastSentDocumentRevision(filePath, projectPartId, documentRevision); + setLastSentDocumentRevision(filePath, documentRevision); } } +void IpcCommunicator::updateTranslationUnit(const QString &filePath, + const QByteArray &contents, + uint documentRevision) +{ + const bool hasUnsavedContent = true; + + updateTranslationUnitsForEditor({{filePath, + Utf8String(), + Utf8String::fromByteArray(contents), + hasUnsavedContent, + documentRevision}}); +} + void IpcCommunicator::updateUnsavedFile(const QString &filePath, const QByteArray &contents, uint documentRevision) { - const QString projectPartId = Utils::projectPartIdForFile(filePath); const bool hasUnsavedContent = true; // TODO: Send new only if changed registerUnsavedFilesForEditor({{filePath, - projectPartId, + Utf8String(), Utf8String::fromByteArray(contents), hasUnsavedContent, documentRevision}}); @@ -446,15 +475,14 @@ void IpcCommunicator::requestDiagnostics(const FileContainer &fileContainer) if (m_sendMode == IgnoreSendRequests) return; - if (documentHasChanged(fileContainer.filePath(), fileContainer.projectPartId())) { - registerTranslationUnitsForEditor({fileContainer}); + if (documentHasChanged(fileContainer.filePath())) { + updateTranslationUnitsForEditor({fileContainer}); const RequestDiagnosticsMessage message(fileContainer); qCDebug(log) << ">>>" << message; m_ipcSender->requestDiagnostics(message); setLastSentDocumentRevision(fileContainer.filePath(), - fileContainer.projectPartId(), fileContainer.documentRevision()); } } @@ -474,10 +502,8 @@ void IpcCommunicator::updateChangeContentStartPosition(const QString &filePath, { auto *document = cppDocument(filePath); - if (document) { - const QString projectPartId = Utils::projectPartIdForFile(filePath); - document->sendTracker(projectPartId).applyContentChange(position); - } + if (document) + document->sendTracker().applyContentChange(position); } void IpcCommunicator::updateTranslationUnitIfNotCurrentDocument(Core::IDocument *document) @@ -551,6 +577,16 @@ void IpcCommunicator::registerTranslationUnitsForEditor(const FileContainers &fi m_ipcSender->registerTranslationUnitsForEditor(message); } +void IpcCommunicator::updateTranslationUnitsForEditor(const IpcCommunicator::FileContainers &fileContainers) +{ + if (m_sendMode == IgnoreSendRequests) + return; + + const UpdateTranslationUnitsForEditorMessage message(fileContainers); + qCDebug(log) << ">>>" << message; + m_ipcSender->updateTranslationUnitsForEditor(message); +} + void IpcCommunicator::unregisterTranslationUnitsForEditor(const FileContainers &fileContainers) { if (m_sendMode == IgnoreSendRequests) diff --git a/src/plugins/clangcodemodel/clangbackendipcintegration.h b/src/plugins/clangcodemodel/clangbackendipcintegration.h index 28354c9aff5..eb08e7aaa9e 100644 --- a/src/plugins/clangcodemodel/clangbackendipcintegration.h +++ b/src/plugins/clangcodemodel/clangbackendipcintegration.h @@ -53,6 +53,7 @@ class DiagnosticsChangedMessage; namespace TextEditor { class TextEditorWidget; +class TextDocument; } namespace ClangCodeModel { @@ -96,6 +97,7 @@ public: virtual void end() = 0; virtual void registerTranslationUnitsForEditor(const ClangBackEnd::RegisterTranslationUnitForEditorMessage &message) = 0; + virtual void updateTranslationUnitsForEditor(const ClangBackEnd::UpdateTranslationUnitsForEditorMessage &message) = 0; virtual void unregisterTranslationUnitsForEditor(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &message) = 0; virtual void registerProjectPartsForEditor(const ClangBackEnd::RegisterProjectPartsForEditorMessage &message) = 0; virtual void unregisterProjectPartsForEditor(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &message) = 0; @@ -118,6 +120,7 @@ public: IpcCommunicator(); void registerTranslationUnitsForEditor(const FileContainers &fileContainers); + void updateTranslationUnitsForEditor(const FileContainers &fileContainers); void unregisterTranslationUnitsForEditor(const FileContainers &fileContainers); void registerProjectPartsForEditor(const ProjectPartContainers &projectPartContainers); void unregisterProjectPartsForEditor(const QStringList &projectPartIds); @@ -130,6 +133,8 @@ public: void registerProjectsParts(const QList projectParts); + void registerTranslationUnit(TextEditor::TextDocument *document); + void registerTranslationUnit(const QString &filePath, const QByteArray &contents, uint documentRevision); void updateTranslationUnitIfNotCurrentDocument(Core::IDocument *document); void updateTranslationUnit(Core::IDocument *document); void updateUnsavedFile(Core::IDocument *document); diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp index de810d83bfb..70dab8f5586 100644 --- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp +++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.cpp @@ -670,18 +670,17 @@ ClangCompletionAssistProcessor::unsavedFileContent(const QByteArray &customFileC return info; } -void ClangCompletionAssistProcessor::sendFileContent(const QString &projectPartId, - const QByteArray &customFileContent) +void ClangCompletionAssistProcessor::sendFileContent(const QByteArray &customFileContent) { // TODO: Revert custom modification after the completions const UnsavedFileContentInfo info = unsavedFileContent(customFileContent); IpcCommunicator &ipcCommunicator = m_interface->ipcCommunicator(); - ipcCommunicator.registerTranslationUnitsForEditor({{m_interface->fileName(), - projectPartId, - Utf8String::fromByteArray(info.unsavedContent), - info.isDocumentModified, - uint(m_interface->textDocument()->revision())}}); + ipcCommunicator.updateTranslationUnitsForEditor({{m_interface->fileName(), + Utf8String(), + Utf8String::fromByteArray(info.unsavedContent), + info.isDocumentModified, + uint(m_interface->textDocument()->revision())}}); } namespace { CppTools::CppEditorDocumentHandle *cppDocument(const QString &filePath) @@ -690,14 +689,13 @@ CppTools::CppEditorDocumentHandle *cppDocument(const QString &filePath) } bool shouldSendDocumentForCompletion(const QString &filePath, - const QString &projectPartId, int completionPosition) { auto *document = cppDocument(filePath); if (document) { - auto &sendTracker = document->sendTracker(projectPartId); - return sendTracker.shouldSendRevisionWithCompletionPosition(document->revision(), + auto &sendTracker = document->sendTracker(); + return sendTracker.shouldSendRevisionWithCompletionPosition(int(document->revision()), completionPosition); } @@ -705,14 +703,13 @@ bool shouldSendDocumentForCompletion(const QString &filePath, } void setLastCompletionPositionAndDocumentRevision(const QString &filePath, - const QString &projectPartId, int completionPosition) { auto *document = cppDocument(filePath); if (document) { - document->sendTracker(projectPartId).setLastCompletionPosition(completionPosition); - document->sendTracker(projectPartId).setLastSentRevision(document->revision()); + document->sendTracker().setLastCompletionPosition(completionPosition); + document->sendTracker().setLastSentRevision(document->revision()); } } @@ -737,13 +734,13 @@ void ClangCompletionAssistProcessor::sendCompletionRequest(int position, ++column; const QString filePath = m_interface->fileName(); - const QString projectPartId = projectPartIdForEditorDocument(filePath); - if (shouldSendDocumentForCompletion(filePath, projectPartId, position)) { - sendFileContent(projectPartId, customFileContent); - setLastCompletionPositionAndDocumentRevision(filePath, projectPartId, position); + if (shouldSendDocumentForCompletion(filePath, position)) { + sendFileContent(customFileContent); + setLastCompletionPositionAndDocumentRevision(filePath, position); } + const QString projectPartId = projectPartIdForEditorDocument(filePath); m_interface->ipcCommunicator().completeCode(this, filePath, uint(line), diff --git a/src/plugins/clangcodemodel/clangcompletionassistprocessor.h b/src/plugins/clangcodemodel/clangcompletionassistprocessor.h index c76987c8f04..4cecf8a31ed 100644 --- a/src/plugins/clangcodemodel/clangcompletionassistprocessor.h +++ b/src/plugins/clangcodemodel/clangcompletionassistprocessor.h @@ -83,7 +83,7 @@ private: }; UnsavedFileContentInfo unsavedFileContent(const QByteArray &customFileContent) const; - void sendFileContent(const QString &projectPartId, const QByteArray &customFileContent); + void sendFileContent(const QByteArray &customFileContent); void sendCompletionRequest(int position, const QByteArray &customFileContent); void handleAvailableCompletions(const CodeCompletions &completions); diff --git a/src/plugins/clangcodemodel/clangcompletionassistprovider.cpp b/src/plugins/clangcodemodel/clangcompletionassistprovider.cpp index eb0f5797ec1..4aa358ab081 100644 --- a/src/plugins/clangcodemodel/clangcompletionassistprovider.cpp +++ b/src/plugins/clangcodemodel/clangcompletionassistprovider.cpp @@ -31,6 +31,7 @@ #include "clangcompletionassistprovider.h" #include "clangcompletionassistprocessor.h" +#include "clangeditordocumentprocessor.h" #include "clangutils.h" #include "pchmanager.h" @@ -70,18 +71,20 @@ TextEditor::AssistInterface *ClangCompletionAssistProvider::createAssistInterfac int position, TextEditor::AssistReason reason) const { - const CppTools::ProjectPart::Ptr projectPart = Utils::projectPartForFile(filePath); - QTC_ASSERT(!projectPart.isNull(), return 0); + const CppTools::ProjectPart::Ptr projectPart = Utils::projectPartForFileBasedOnProcessor(filePath); + if (projectPart) { + const PchInfo::Ptr pchInfo = PchManager::instance()->pchInfo(projectPart); + return new ClangCompletionAssistInterface(m_ipcCommunicator, + textEditorWidget, + position, + filePath, + reason, + projectPart->headerPaths, + pchInfo, + projectPart->languageFeatures); + } - const PchInfo::Ptr pchInfo = PchManager::instance()->pchInfo(projectPart); - return new ClangCompletionAssistInterface(m_ipcCommunicator, - textEditorWidget, - position, - filePath, - reason, - projectPart->headerPaths, - pchInfo, - projectPart->languageFeatures); + return 0; } } // namespace Internal diff --git a/src/plugins/clangcodemodel/clangutils.cpp b/src/plugins/clangcodemodel/clangutils.cpp index 716e5a63607..d2c41fbce3d 100644 --- a/src/plugins/clangcodemodel/clangutils.cpp +++ b/src/plugins/clangcodemodel/clangutils.cpp @@ -30,6 +30,8 @@ #include "clangutils.h" +#include "clangeditordocumentprocessor.h" + #include #include @@ -264,6 +266,13 @@ ProjectPart::Ptr projectPartForFile(const QString &filePath) return ProjectPart::Ptr(); } +ProjectPart::Ptr projectPartForFileBasedOnProcessor(const QString &filePath) +{ + if (const auto processor = ClangEditorDocumentProcessor::get(filePath)) + return processor->projectPart(); + return ProjectPart::Ptr(); +} + bool isProjectPartValid(const ProjectPart::Ptr projectPart) { if (projectPart) diff --git a/src/plugins/clangcodemodel/clangutils.h b/src/plugins/clangcodemodel/clangutils.h index fdee8af6f8b..79cc8687342 100644 --- a/src/plugins/clangcodemodel/clangutils.h +++ b/src/plugins/clangcodemodel/clangutils.h @@ -54,6 +54,7 @@ QStringList createClangOptions(const CppTools::ProjectPart::Ptr &pPart, QStringList createPCHInclusionOptions(const QString &pchFile); CppTools::ProjectPart::Ptr projectPartForFile(const QString &filePath); +CppTools::ProjectPart::Ptr projectPartForFileBasedOnProcessor(const QString &filePath); bool isProjectPartValid(const CppTools::ProjectPart::Ptr projectPart); QString projectPartIdForFile(const QString &filePath); diff --git a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp index 46046d6d72c..9b938edaf86 100644 --- a/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp +++ b/src/plugins/clangcodemodel/test/clangcodecompletion_test.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include @@ -319,8 +320,16 @@ QString toString(const RegisterTranslationUnitForEditorMessage &message) ts << "RegisterTranslationUnitForEditorMessage\n" << toString(message.fileContainers()); return out; +} - return QLatin1String("RegisterTranslationUnitForEditorMessage\n"); +QString toString(const UpdateTranslationUnitsForEditorMessage &message) +{ + QString out; + QTextStream ts(&out); + + ts << "UpdateTranslationUnitForEditorMessage\n" + << toString(message.fileContainers()); + return out; } QString toString(const UnregisterTranslationUnitsForEditorMessage &) @@ -356,8 +365,6 @@ QString toString(const RegisterUnsavedFilesForEditorMessage &message) ts << "RegisterUnsavedFilesForEditorMessage\n" << toString(message.fileContainers()); return out; - - return QLatin1String("RegisterUnsavedFilesForEditorMessage\n"); } QString toString(const UnregisterUnsavedFilesForEditorMessage &) @@ -384,6 +391,9 @@ public: void registerTranslationUnitsForEditor(const RegisterTranslationUnitForEditorMessage &message) override { senderLog.append(toString(message)); } + void updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message) override + { senderLog.append(toString(message)); } + void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override { senderLog.append(toString(message)); } diff --git a/src/plugins/cpptools/editordocumenthandle.cpp b/src/plugins/cpptools/editordocumenthandle.cpp index 07d91a0b8fe..311db4648f9 100644 --- a/src/plugins/cpptools/editordocumenthandle.cpp +++ b/src/plugins/cpptools/editordocumenthandle.cpp @@ -58,9 +58,9 @@ void CppEditorDocumentHandle::setNeedsRefresh(bool needsRefresh) m_needsRefresh = needsRefresh; } -SendDocumentTracker &CppEditorDocumentHandle::sendTracker(const QString &projectPartId) +SendDocumentTracker &CppEditorDocumentHandle::sendTracker() { - return m_documentRevisionManagements[projectPartId]; + return m_sendTracker; } } // namespace CppTools diff --git a/src/plugins/cpptools/editordocumenthandle.h b/src/plugins/cpptools/editordocumenthandle.h index e4343bce3b7..99c6342204d 100644 --- a/src/plugins/cpptools/editordocumenthandle.h +++ b/src/plugins/cpptools/editordocumenthandle.h @@ -34,7 +34,6 @@ #include "cpptools_global.h" #include "senddocumenttracker.h" -#include #include namespace CppTools { @@ -59,10 +58,10 @@ public: virtual void resetProcessor() = 0; - SendDocumentTracker &sendTracker(const QString &projectPartId); + SendDocumentTracker &sendTracker(); private: - QMap m_documentRevisionManagements; + SendDocumentTracker m_sendTracker; bool m_needsRefresh; }; diff --git a/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri b/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri index 4dc65b332f1..e0e49498e3a 100644 --- a/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri +++ b/src/tools/clangbackend/ipcsource/clangbackendclangipc-source.pri @@ -23,7 +23,8 @@ HEADERS += $$PWD/clangipcserver.h \ $$PWD/sourcerange.h \ $$PWD/fixit.h \ $$PWD/diagnosticsetiterator.h \ - $$PWD/clangfilesystemwatcher.h + $$PWD/clangfilesystemwatcher.h \ + $$PWD/translationunitalreadyexistsexception.h SOURCES += $$PWD/clangipcserver.cpp \ $$PWD/codecompleter.cpp \ @@ -47,4 +48,5 @@ SOURCES += $$PWD/clangipcserver.cpp \ $$PWD/sourcelocation.cpp \ $$PWD/sourcerange.cpp \ $$PWD/fixit.cpp \ - $$PWD/clangfilesystemwatcher.cpp + $$PWD/clangfilesystemwatcher.cpp \ + $$PWD/translationunitalreadyexistsexception.cpp diff --git a/src/tools/clangbackend/ipcsource/clangipcserver.cpp b/src/tools/clangbackend/ipcsource/clangipcserver.cpp index cabbf76816e..8aaf7588f58 100644 --- a/src/tools/clangbackend/ipcsource/clangipcserver.cpp +++ b/src/tools/clangbackend/ipcsource/clangipcserver.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -103,12 +104,9 @@ void ClangIpcServer::registerTranslationUnitsForEditor(const ClangBackEnd::Regis TIME_SCOPE_DURATION("ClangIpcServer::registerTranslationUnitsForEditor"); try { - const auto newerFileContainers = translationUnits.newerFileContainers(message.fileContainers()); - if (newerFileContainers.size() > 0) { - unsavedFiles.createOrUpdate(newerFileContainers); - translationUnits.createOrUpdate(newerFileContainers); - sendDiagnosticsTimer.start(sendDiagnosticsTimerInterval); - } + translationUnits.create(message.fileContainers()); + unsavedFiles.createOrUpdate(message.fileContainers()); + sendDiagnosticsTimer.start(sendDiagnosticsTimerInterval); } catch (const ProjectPartDoNotExistException &exception) { client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds())); } catch (const std::exception &exception) { @@ -116,13 +114,33 @@ void ClangIpcServer::registerTranslationUnitsForEditor(const ClangBackEnd::Regis } } +void ClangIpcServer::updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message) +{ + TIME_SCOPE_DURATION("ClangIpcServer::updateTranslationUnitsForEditor"); + + try { + const auto newerFileContainers = translationUnits.newerFileContainers(message.fileContainers()); + if (newerFileContainers.size() > 0) { + translationUnits.update(newerFileContainers); + unsavedFiles.createOrUpdate(newerFileContainers); + sendDiagnosticsTimer.start(sendDiagnosticsTimerInterval); + } + } catch (const ProjectPartDoNotExistException &exception) { + client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds())); + } catch (const TranslationUnitDoesNotExistException &exception) { + client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistMessage(exception.fileContainer())); + } catch (const std::exception &exception) { + qWarning() << "Error in ClangIpcServer::updateTranslationUnitsForEditor:" << exception.what(); + } +} + void ClangIpcServer::unregisterTranslationUnitsForEditor(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &message) { TIME_SCOPE_DURATION("ClangIpcServer::unregisterTranslationUnitsForEditor"); try { - unsavedFiles.remove(message.fileContainers()); translationUnits.remove(message.fileContainers()); + unsavedFiles.remove(message.fileContainers()); } catch (const TranslationUnitDoesNotExistException &exception) { client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistMessage(exception.fileContainer())); } catch (const ProjectPartDoNotExistException &exception) { @@ -225,6 +243,11 @@ void ClangIpcServer::requestDiagnostics(const RequestDiagnosticsMessage &message } } +const TranslationUnits &ClangIpcServer::translationUnitsForTestOnly() const +{ + return translationUnits; +} + void ClangIpcServer::startSendDiagnosticTimerIfFileIsNotATranslationUnit(const Utf8String &filePath) { if (!translationUnits.hasTranslationUnit(filePath)) diff --git a/src/tools/clangbackend/ipcsource/clangipcserver.h b/src/tools/clangbackend/ipcsource/clangipcserver.h index 8b300933ddd..d4e5c6442ac 100644 --- a/src/tools/clangbackend/ipcsource/clangipcserver.h +++ b/src/tools/clangbackend/ipcsource/clangipcserver.h @@ -53,6 +53,7 @@ public: void end() override; void registerTranslationUnitsForEditor(const RegisterTranslationUnitForEditorMessage &message) override; + void updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message) override; void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override; void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) override; void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override; @@ -61,6 +62,8 @@ public: void completeCode(const CompleteCodeMessage &message) override; void requestDiagnostics(const RequestDiagnosticsMessage &message) override; + const TranslationUnits &translationUnitsForTestOnly() const; + private: void startSendDiagnosticTimerIfFileIsNotATranslationUnit(const Utf8String &filePath); diff --git a/src/tools/clangbackend/ipcsource/translationunitalreadyexistsexception.cpp b/src/tools/clangbackend/ipcsource/translationunitalreadyexistsexception.cpp new file mode 100644 index 00000000000..a92c4c1781e --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunitalreadyexistsexception.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "translationunitalreadyexistsexception.h" + +namespace ClangBackEnd { + +TranslationUnitAlreadyExistsException::TranslationUnitAlreadyExistsException(const FileContainer &fileContainer) + : fileContainer_(fileContainer) +{ +} + +TranslationUnitAlreadyExistsException::TranslationUnitAlreadyExistsException(const Utf8String &filePath, + const Utf8String &projectPartId) + : fileContainer_(filePath, projectPartId) +{ +} + +const FileContainer &TranslationUnitAlreadyExistsException::fileContainer() const +{ + return fileContainer_; +} + +const char *TranslationUnitAlreadyExistsException::what() const Q_DECL_NOEXCEPT +{ + if (what_.isEmpty()) { + what_ += Utf8StringLiteral("Translation unit '") + + fileContainer_.filePath() + + Utf8StringLiteral("' with the project part id '") + + fileContainer_.projectPartId() + + Utf8StringLiteral("' already exists!"); + } + + return what_.constData(); +} + +} // namespace ClangBackEnd + diff --git a/src/tools/clangbackend/ipcsource/translationunitalreadyexistsexception.h b/src/tools/clangbackend/ipcsource/translationunitalreadyexistsexception.h new file mode 100644 index 00000000000..3afaccb5ee4 --- /dev/null +++ b/src/tools/clangbackend/ipcsource/translationunitalreadyexistsexception.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CLANGBACKEND_TRANSLATIONUNITALREADYEXISTS_H +#define CLANGBACKEND_TRANSLATIONUNITALREADYEXISTS_H + +#include + +namespace ClangBackEnd { + +class TranslationUnitAlreadyExistsException : public std::exception +{ +public: + TranslationUnitAlreadyExistsException(const FileContainer &fileContainer); + TranslationUnitAlreadyExistsException(const Utf8String &filePath, const Utf8String &projectPartId); + + const FileContainer &fileContainer() const; + + const char *what() const Q_DECL_NOEXCEPT override; + +#if defined(__GNUC__) && !defined(__clang__) +# if !__GNUC_PREREQ(4,8) + ~TranslationUnitAlreadyExistsException() noexcept {} +# endif +#endif + +private: + FileContainer fileContainer_; + mutable Utf8String what_; +}; + +} // namespace ClangBackEnd + +#endif // CLANGBACKEND_TRANSLATIONUNITALREADYEXISTS_H diff --git a/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.cpp b/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.cpp index e06bb85f3ff..678b894314c 100644 --- a/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.cpp +++ b/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.cpp @@ -37,7 +37,7 @@ TranslationUnitDoesNotExistException::TranslationUnitDoesNotExistException(const { } -TranslationUnitDoesNotExistException::TranslationUnitDoesNotExistException(const Utf8String filePath, const Utf8String projectPartId) +TranslationUnitDoesNotExistException::TranslationUnitDoesNotExistException(const Utf8String &filePath, const Utf8String &projectPartId) : fileContainer_(filePath, projectPartId) { } @@ -50,11 +50,11 @@ const FileContainer &TranslationUnitDoesNotExistException::fileContainer() const const char *TranslationUnitDoesNotExistException::what() const Q_DECL_NOEXCEPT { if (what_.isEmpty()) - what_ += Utf8StringLiteral("Parse error for file ") + what_ += Utf8StringLiteral("Translation unit '") + fileContainer_.filePath() - + Utf8StringLiteral(" in project ") + + Utf8StringLiteral("' with the project part id '") + fileContainer_.projectPartId() - + Utf8StringLiteral("!"); + + Utf8StringLiteral("' does not exits!"); return what_.constData(); } diff --git a/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.h b/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.h index c4b539bc923..29942c48295 100644 --- a/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.h +++ b/src/tools/clangbackend/ipcsource/translationunitdoesnotexistexception.h @@ -39,7 +39,7 @@ class TranslationUnitDoesNotExistException : public std::exception { public: TranslationUnitDoesNotExistException(const FileContainer &fileContainer); - TranslationUnitDoesNotExistException(const Utf8String filePath, const Utf8String projectPartId); + TranslationUnitDoesNotExistException(const Utf8String &filePath, const Utf8String &projectPartId); const FileContainer &fileContainer() const; diff --git a/src/tools/clangbackend/ipcsource/translationunits.cpp b/src/tools/clangbackend/ipcsource/translationunits.cpp index 18649a1fe0e..b0790ac5738 100644 --- a/src/tools/clangbackend/ipcsource/translationunits.cpp +++ b/src/tools/clangbackend/ipcsource/translationunits.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -57,10 +58,22 @@ TranslationUnits::TranslationUnits(ProjectParts &projects, UnsavedFiles &unsaved { } -void TranslationUnits::createOrUpdate(const QVector &fileContainers) +void TranslationUnits::create(const QVector &fileContainers) { + checkIfTranslationUnitsDoesNotExists(fileContainers); + for (const FileContainer &fileContainer : fileContainers) { - createOrUpdateTranslationUnit(fileContainer); + createTranslationUnit(fileContainer); + updateTranslationUnitsWithChangedDependency(fileContainer.filePath()); + } +} + +void TranslationUnits::update(const QVector &fileContainers) +{ + checkIfTranslationUnitsForFilePathsDoesExists(fileContainers); + + for (const FileContainer &fileContainer : fileContainers) { + updateTranslationUnit(fileContainer); updateTranslationUnitsWithChangedDependency(fileContainer.filePath()); } } @@ -180,7 +193,7 @@ const ClangFileSystemWatcher *TranslationUnits::clangFileSystemWatcher() const return &fileSystemWatcher; } -void TranslationUnits::createOrUpdateTranslationUnit(const FileContainer &fileContainer) +void TranslationUnits::createTranslationUnit(const FileContainer &fileContainer) { TranslationUnit::FileExistsCheck checkIfFileExists = fileContainer.hasUnsavedFileContent() ? TranslationUnit::DoNotCheckIfFileExists : TranslationUnit::CheckIfFileExists; auto findIterator = findTranslationUnit(fileContainer); @@ -190,22 +203,54 @@ void TranslationUnits::createOrUpdateTranslationUnit(const FileContainer &fileCo *this, checkIfFileExists)); translationUnits_.back().setDocumentRevision(fileContainer.documentRevision()); - } else { - findIterator->setDocumentRevision(fileContainer.documentRevision()); } } +void TranslationUnits::updateTranslationUnit(const FileContainer &fileContainer) +{ + auto findIterator = findAllTranslationUnitWithFilePath(fileContainer.filePath()); + if (findIterator != translationUnits_.end()) + findIterator->setDocumentRevision(fileContainer.documentRevision()); +} + std::vector::iterator TranslationUnits::findTranslationUnit(const FileContainer &fileContainer) { return std::find(translationUnits_.begin(), translationUnits_.end(), fileContainer); } +std::vector::iterator TranslationUnits::findAllTranslationUnitWithFilePath(const Utf8String &filePath) +{ + auto filePathCompare = [&filePath] (const TranslationUnit &translationUnit) { + return translationUnit.filePath() == filePath; + }; + + return std::find_if(translationUnits_.begin(), translationUnits_.end(), filePathCompare); +} + std::vector::const_iterator TranslationUnits::findTranslationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const { FileContainer fileContainer(filePath, projectPartId); return std::find(translationUnits_.begin(), translationUnits_.end(), fileContainer); } +bool TranslationUnits::hasTranslationUnit(const FileContainer &fileContainer) const +{ + auto findIterator = std::find(translationUnits_.begin(), translationUnits_.end(), fileContainer); + + return findIterator != translationUnits_.end(); +} + +bool TranslationUnits::hasTranslationUnitWithFilePath(const Utf8String &filePath) const +{ + auto filePathCompare = [&filePath] (const TranslationUnit &translationUnit) { + return translationUnit.filePath() == filePath; + }; + + auto findIterator = std::find_if(translationUnits_.begin(), translationUnits_.end(), filePathCompare); + + return findIterator != translationUnits_.end(); +} + void TranslationUnits::checkIfProjectPartExists(const Utf8String &projectFileName) const { projectParts.project(projectFileName); @@ -225,6 +270,22 @@ void TranslationUnits::checkIfProjectPartsExists(const QVector &f } +void TranslationUnits::checkIfTranslationUnitsDoesNotExists(const QVector &fileContainers) const +{ + for (const FileContainer &fileContainer : fileContainers) { + if (hasTranslationUnit(fileContainer)) + throw TranslationUnitAlreadyExistsException(fileContainer); + } +} + +void TranslationUnits::checkIfTranslationUnitsForFilePathsDoesExists(const QVector &fileContainers) const +{ + for (const FileContainer &fileContainer : fileContainers) { + if (!hasTranslationUnitWithFilePath(fileContainer.filePath())) + throw TranslationUnitDoesNotExistException(fileContainer); + } +} + void TranslationUnits::sendDiagnosticChangedMessage(const TranslationUnit &translationUnit) { if (sendDiagnosticsChangedCallback) { diff --git a/src/tools/clangbackend/ipcsource/translationunits.h b/src/tools/clangbackend/ipcsource/translationunits.h index 1b84a564985..58433b85666 100644 --- a/src/tools/clangbackend/ipcsource/translationunits.h +++ b/src/tools/clangbackend/ipcsource/translationunits.h @@ -58,7 +58,8 @@ class TranslationUnits public: TranslationUnits(ProjectParts &projectParts, UnsavedFiles &unsavedFiles); - void createOrUpdate(const QVector &fileContainers); + void create(const QVector &fileContainers); + void update(const QVector &fileContainers); void remove(const QVector &fileContainers); const TranslationUnit &translationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const; @@ -83,11 +84,18 @@ public: const ClangFileSystemWatcher *clangFileSystemWatcher() const; private: - void createOrUpdateTranslationUnit(const FileContainer &fileContainer); + void createTranslationUnit(const FileContainer &fileContainer); + void updateTranslationUnit(const FileContainer &fileContainer); std::vector::iterator findTranslationUnit(const FileContainer &fileContainer); + std::vector::iterator findAllTranslationUnitWithFilePath(const Utf8String &filePath); std::vector::const_iterator findTranslationUnit(const Utf8String &filePath, const Utf8String &projectPartId) const; + bool hasTranslationUnit(const FileContainer &fileContainer) const; + bool hasTranslationUnitWithFilePath(const Utf8String &filePath) const; void checkIfProjectPartExists(const Utf8String &projectFileName) const; void checkIfProjectPartsExists(const QVector &fileContainers) const; + void checkIfTranslationUnitsDoesNotExists(const QVector &fileContainers) const; + void checkIfTranslationUnitsForFilePathsDoesExists(const QVector &fileContainers) const; + void sendDiagnosticChangedMessage(const TranslationUnit &translationUnit); void removeTranslationUnits(const QVector &fileContainers); diff --git a/tests/unit/echoserver/echoipcserver.cpp b/tests/unit/echoserver/echoipcserver.cpp index ad84f5186fb..c9dbfb42e88 100644 --- a/tests/unit/echoserver/echoipcserver.cpp +++ b/tests/unit/echoserver/echoipcserver.cpp @@ -42,6 +42,7 @@ #include "registerunsavedfilesforeditormessage.h" #include "requestdiagnosticsmessage.h" #include "unregisterunsavedfilesforeditormessage.h" +#include "updatetranslationunitsforeditormessage.h" #include #include @@ -65,6 +66,11 @@ void EchoIpcServer::registerTranslationUnitsForEditor(const RegisterTranslationU echoMessage(QVariant::fromValue(message)); } +void EchoIpcServer::updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message) +{ + echoMessage(QVariant::fromValue(message)); +} + void EchoIpcServer::unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) { echoMessage(QVariant::fromValue(message)); diff --git a/tests/unit/echoserver/echoipcserver.h b/tests/unit/echoserver/echoipcserver.h index 40320042196..cb3c55d2bb4 100644 --- a/tests/unit/echoserver/echoipcserver.h +++ b/tests/unit/echoserver/echoipcserver.h @@ -41,6 +41,7 @@ public: void dispatch(const QVariant &message) override; void end() override; void registerTranslationUnitsForEditor(const RegisterTranslationUnitForEditorMessage &message) override; + void updateTranslationUnitsForEditor(const UpdateTranslationUnitsForEditorMessage &message) override; void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override; void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) override; void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override; diff --git a/tests/unit/unittest/clangipcservertest.cpp b/tests/unit/unittest/clangipcservertest.cpp index a3d44d2392c..93182ab8d92 100644 --- a/tests/unit/unittest/clangipcservertest.cpp +++ b/tests/unit/unittest/clangipcservertest.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -59,6 +60,7 @@ using testing::Property; using testing::Contains; using testing::Not; using testing::Eq; +using testing::PrintToString; namespace { @@ -73,6 +75,41 @@ using ClangBackEnd::FileContainer; using ClangBackEnd::ProjectPartContainer; using ClangBackEnd::TranslationUnitDoesNotExistMessage; using ClangBackEnd::ProjectPartsDoNotExistMessage; +using ClangBackEnd::UpdateTranslationUnitsForEditorMessage; + +MATCHER_P3(HasDirtyTranslationUnit, filePath, projectPartId, documentRevision, + std::string(negation ? "isn't" : "is") + + " translation unit with file path "+ PrintToString(filePath) + + " and project " + PrintToString(projectPartId) + + " and document revision " + PrintToString(documentRevision) + ) +{ + auto &&translationUnits = arg.translationUnitsForTestOnly(); + try { + auto translationUnit = translationUnits.translationUnit(filePath, projectPartId); + + if (translationUnit.documentRevision() == documentRevision) { + if (translationUnit.hasNewDiagnostics()) { + if (translationUnit.isNeedingReparse()) + return true; + + *result_listener << "isNeedingReparse is false"; + return false; + } + + *result_listener << "hasNewDiagnostics is false"; + return false; + } + + *result_listener << "revision number is " << PrintToString(translationUnit.documentRevision()); + return false; + + } catch (...) { + *result_listener << "has no translation unit"; + return false; + } +} + class ClangIpcServer : public ::testing::Test { @@ -107,7 +144,7 @@ void ClangIpcServer::SetUp() void ClangIpcServer::registerFiles() { RegisterTranslationUnitForEditorMessage message({FileContainer(functionTestFilePath, projectPartId, unsavedContent(unsavedTestFilePath), true), - FileContainer(variableTestFilePath, projectPartId)}); + FileContainer(variableTestFilePath, projectPartId)}); clangServer.registerTranslationUnitsForEditor(message); } @@ -222,7 +259,7 @@ TEST_F(ClangIpcServer, GetCodeCompletionForUnsavedFile) TEST_F(ClangIpcServer, GetNoCodeCompletionAfterRemovingUnsavedFile) { - clangServer.registerTranslationUnitsForEditor(RegisterTranslationUnitForEditorMessage({FileContainer(functionTestFilePath, projectPartId, 74)})); + clangServer.updateTranslationUnitsForEditor(UpdateTranslationUnitsForEditorMessage({FileContainer(functionTestFilePath, projectPartId, 74)})); CompleteCodeMessage completeCodeMessage(functionTestFilePath, 20, 1, @@ -239,11 +276,11 @@ TEST_F(ClangIpcServer, GetNoCodeCompletionAfterRemovingUnsavedFile) TEST_F(ClangIpcServer, GetNewCodeCompletionAfterUpdatingUnsavedFile) { - clangServer.registerTranslationUnitsForEditor(RegisterTranslationUnitForEditorMessage({FileContainer(functionTestFilePath, - projectPartId, - unsavedContent(updatedUnsavedTestFilePath), - true, - 74)})); + clangServer.updateTranslationUnitsForEditor(UpdateTranslationUnitsForEditorMessage({{functionTestFilePath, + projectPartId, + unsavedContent(updatedUnsavedTestFilePath), + true, + 74}})); CompleteCodeMessage completeCodeMessage(functionTestFilePath, 20, 1, @@ -367,4 +404,9 @@ TEST_F(ClangIpcServer, TicketNumberIsForwarded) clangServer.completeCode(completeCodeMessage); } + +TEST_F(ClangIpcServer, TranslationUnitIsDirtyAfterCreation) +{ + ASSERT_THAT(clangServer, HasDirtyTranslationUnit(functionTestFilePath, projectPartId, 0)); +} } diff --git a/tests/unit/unittest/clientserverinprocesstest.cpp b/tests/unit/unittest/clientserverinprocesstest.cpp index 1f6ec204005..87632e2c069 100644 --- a/tests/unit/unittest/clientserverinprocesstest.cpp +++ b/tests/unit/unittest/clientserverinprocesstest.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -128,6 +129,17 @@ TEST_F(ClientServerInProcess, SendRegisterTranslationUnitForEditorMessage) scheduleServerMessages(); } +TEST_F(ClientServerInProcess, SendUpdateTranslationUnitsForEditorMessage) +{ + ClangBackEnd::UpdateTranslationUnitsForEditorMessage message({fileContainer}); + + EXPECT_CALL(mockIpcServer, updateTranslationUnitsForEditor(message)) + .Times(1); + + serverProxy.updateTranslationUnitsForEditor(message); + scheduleServerMessages(); +} + TEST_F(ClientServerInProcess, SendUnregisterTranslationUnitsForEditorMessage) { ClangBackEnd::UnregisterTranslationUnitsForEditorMessage message({fileContainer}); diff --git a/tests/unit/unittest/codecompletiontest.cpp b/tests/unit/unittest/codecompletiontest.cpp index 53c395b944f..80679f7cd72 100644 --- a/tests/unit/unittest/codecompletiontest.cpp +++ b/tests/unit/unittest/codecompletiontest.cpp @@ -135,7 +135,7 @@ void CodeCompleter::SetUp() { EXPECT_TRUE(includeDirectory.isValid()); projects.createOrUpdate({projectPart}); - translationUnits.createOrUpdate({mainFileContainer}); + translationUnits.create({mainFileContainer}); translationUnit = translationUnits.translationUnit(mainFileContainer); completer = ClangBackEnd::CodeCompleter(translationUnit); @@ -147,7 +147,7 @@ void CodeCompleter::SetUp() TEST_F(CodeCompleter, FunctionInUnsavedFile) { unsavedFiles.createOrUpdate({unsavedMainFileContainer}); - translationUnits.createOrUpdate({unsavedMainFileContainer}); + translationUnits.update({unsavedMainFileContainer}); ASSERT_THAT(completer.complete(27, 1), AllOf(Contains(IsCodeCompletion(Utf8StringLiteral("FunctionWithArguments"), @@ -165,7 +165,7 @@ TEST_F(CodeCompleter, FunctionInUnsavedFile) TEST_F(CodeCompleter, VariableInUnsavedFile) { unsavedFiles.createOrUpdate({unsavedMainFileContainer}); - translationUnits.createOrUpdate({unsavedMainFileContainer}); + translationUnits.update({unsavedMainFileContainer}); ASSERT_THAT(completer.complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("VariableInUnsavedFile"), @@ -175,7 +175,7 @@ TEST_F(CodeCompleter, VariableInUnsavedFile) TEST_F(CodeCompleter, GlobalVariableInUnsavedFile) { unsavedFiles.createOrUpdate({unsavedMainFileContainer}); - translationUnits.createOrUpdate({unsavedMainFileContainer}); + translationUnits.update({unsavedMainFileContainer}); ASSERT_THAT(completer.complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("GlobalVariableInUnsavedFile"), @@ -185,7 +185,7 @@ TEST_F(CodeCompleter, GlobalVariableInUnsavedFile) TEST_F(CodeCompleter, Macro) { unsavedFiles.createOrUpdate({unsavedMainFileContainer}); - translationUnits.createOrUpdate({unsavedMainFileContainer}); + translationUnits.update({unsavedMainFileContainer}); ASSERT_THAT(completer.complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("Macro"), @@ -209,7 +209,7 @@ TEST_F(CodeCompleter, FunctionInIncludedHeader) TEST_F(CodeCompleter, FunctionInUnsavedIncludedHeader) { unsavedFiles.createOrUpdate({unsavedTargetHeaderFileContainer}); - translationUnits.createOrUpdate({unsavedTargetHeaderFileContainer}); + translationUnits.create({unsavedTargetHeaderFileContainer}); ASSERT_THAT(completer.complete(27, 1), Contains(IsCodeCompletion(Utf8StringLiteral("FunctionInIncludedHeaderUnsaved"), @@ -228,7 +228,7 @@ TEST_F(CodeCompleter, DISABLED_FunctionInChangedIncludedHeader) TEST_F(CodeCompleter, FunctionInChangedIncludedHeaderWithUnsavedContentInMainFile) { unsavedFiles.createOrUpdate({unsavedMainFileContainer}); - translationUnits.createOrUpdate({unsavedMainFileContainer}); + translationUnits.update({unsavedMainFileContainer}); copyChangedTargetHeaderToTemporaryIncludeDirecory(); diff --git a/tests/unit/unittest/mockipcserver.h b/tests/unit/unittest/mockipcserver.h index 19ac454d1d3..31591c28c0d 100644 --- a/tests/unit/unittest/mockipcserver.h +++ b/tests/unit/unittest/mockipcserver.h @@ -44,6 +44,8 @@ public: void()); MOCK_METHOD1(registerTranslationUnitsForEditor, void(const ClangBackEnd::RegisterTranslationUnitForEditorMessage &message)); + MOCK_METHOD1(updateTranslationUnitsForEditor, + void(const ClangBackEnd::UpdateTranslationUnitsForEditorMessage &message)); MOCK_METHOD1(unregisterTranslationUnitsForEditor, void(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &message)); MOCK_METHOD1(registerProjectPartsForEditor, diff --git a/tests/unit/unittest/readandwritemessageblocktest.cpp b/tests/unit/unittest/readandwritemessageblocktest.cpp index 161a2529bab..78f1f8d4869 100644 --- a/tests/unit/unittest/readandwritemessageblocktest.cpp +++ b/tests/unit/unittest/readandwritemessageblocktest.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -151,6 +152,11 @@ TEST_F(ReadAndWriteMessageBlock, CompareRegisterTranslationUnitForEditorMessage) CompareMessage(ClangBackEnd::RegisterTranslationUnitForEditorMessage({fileContainer})); } +TEST_F(ReadAndWriteMessageBlock, CompareUpdateTranslationUnitForEditorMessage) +{ + CompareMessage(ClangBackEnd::UpdateTranslationUnitsForEditorMessage({fileContainer})); +} + TEST_F(ReadAndWriteMessageBlock, CompareUnregisterFileForEditorMessage) { CompareMessage(ClangBackEnd::UnregisterTranslationUnitsForEditorMessage({fileContainer})); diff --git a/tests/unit/unittest/translationunitstest.cpp b/tests/unit/unittest/translationunitstest.cpp index a5efcfca454..d291c368b09 100644 --- a/tests/unit/unittest/translationunitstest.cpp +++ b/tests/unit/unittest/translationunitstest.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -115,7 +116,7 @@ TEST_F(TranslationUnits, ThrowForAddingNonExistingFile) { ClangBackEnd::FileContainer fileContainer(nonExistingFilePath, projectPartId); - ASSERT_THROW(translationUnits.createOrUpdate({fileContainer}), + ASSERT_THROW(translationUnits.create({fileContainer}), ClangBackEnd::TranslationUnitFileNotExitsException); } @@ -123,29 +124,56 @@ TEST_F(TranslationUnits, DoNotThrowForAddingNonExistingFileWithUnsavedContent) { ClangBackEnd::FileContainer fileContainer(nonExistingFilePath, projectPartId, Utf8String(), true); - ASSERT_NO_THROW(translationUnits.createOrUpdate({fileContainer})); + ASSERT_NO_THROW(translationUnits.create({fileContainer})); } TEST_F(TranslationUnits, Add) { ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u); - translationUnits.createOrUpdate({fileContainer}); + translationUnits.create({fileContainer}); ASSERT_THAT(translationUnits.translationUnit(filePath, projectPartId), IsTranslationUnit(filePath, projectPartId, 74u)); } +TEST_F(TranslationUnits, ThrowForCreatingAnExistingTranslationUnit) +{ + ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u); + translationUnits.create({fileContainer}); + + ASSERT_THROW(translationUnits.create({fileContainer}), + ClangBackEnd::TranslationUnitAlreadyExistsException); +} + +TEST_F(TranslationUnits, ThrowForUpdatingANonExistingTranslationUnit) +{ + ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u); + ASSERT_THROW(translationUnits.update({fileContainer}), + ClangBackEnd::TranslationUnitDoesNotExistException); +} + +TEST_F(TranslationUnits, Update) +{ + ClangBackEnd::FileContainer createFileContainer(filePath, projectPartId, 74u); + ClangBackEnd::FileContainer updateFileContainer(filePath, Utf8String(), 75u); + translationUnits.create({createFileContainer}); + + translationUnits.update({updateFileContainer}); + + ASSERT_THAT(translationUnits.translationUnit(filePath, projectPartId), + IsTranslationUnit(filePath, projectPartId, 75u)); +} TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForReparse) { ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u); ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, 74u); ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); - translationUnits.createOrUpdate({fileContainer, headerContainer}); + translationUnits.create({fileContainer, headerContainer}); translationUnits.translationUnit(filePath, projectPartId).cxTranslationUnit(); - translationUnits.createOrUpdate({headerContainerWithUnsavedContent}); + translationUnits.update({headerContainerWithUnsavedContent}); ASSERT_TRUE(translationUnits.translationUnit(filePath, projectPartId).isNeedingReparse()); } @@ -155,10 +183,10 @@ TEST_F(TranslationUnits, UpdateUnsavedFileAndCheckForDiagnostics) ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u); ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, 74u); ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); - translationUnits.createOrUpdate({fileContainer, headerContainer}); + translationUnits.create({fileContainer, headerContainer}); translationUnits.translationUnit(filePath, projectPartId).diagnostics(); - translationUnits.createOrUpdate({headerContainerWithUnsavedContent}); + translationUnits.update({headerContainerWithUnsavedContent}); ASSERT_TRUE(translationUnits.translationUnit(filePath, projectPartId).hasNewDiagnostics()); } @@ -168,7 +196,7 @@ TEST_F(TranslationUnits, RemoveFileAndCheckForDiagnostics) ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u); ClangBackEnd::FileContainer headerContainer(headerPath, projectPartId, 74u); ClangBackEnd::FileContainer headerContainerWithUnsavedContent(headerPath, projectPartId, Utf8String(), true, 75u); - translationUnits.createOrUpdate({fileContainer, headerContainer}); + translationUnits.create({fileContainer, headerContainer}); translationUnits.translationUnit(filePath, projectPartId).diagnostics(); translationUnits.remove({headerContainerWithUnsavedContent}); @@ -179,7 +207,7 @@ TEST_F(TranslationUnits, RemoveFileAndCheckForDiagnostics) TEST_F(TranslationUnits, DontGetNewerFileContainerIfRevisionIsTheSame) { ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u); - translationUnits.createOrUpdate({fileContainer}); + translationUnits.create({fileContainer}); auto newerFileContainers = translationUnits.newerFileContainers({fileContainer}); @@ -190,7 +218,7 @@ TEST_F(TranslationUnits, GetNewerFileContainerIfRevisionIsDifferent) { ClangBackEnd::FileContainer fileContainer(filePath, projectPartId, 74u); ClangBackEnd::FileContainer newerContainer(filePath, projectPartId, 75u); - translationUnits.createOrUpdate({fileContainer}); + translationUnits.create({fileContainer}); auto newerFileContainers = translationUnits.newerFileContainers({newerContainer}); @@ -216,7 +244,7 @@ TEST_F(TranslationUnits, ThrowForRemovingWithWrongProjectPartFilePath) TEST_F(TranslationUnits, Remove) { ClangBackEnd::FileContainer fileContainer(filePath, projectPartId); - translationUnits.createOrUpdate({fileContainer}); + translationUnits.create({fileContainer}); translationUnits.remove({fileContainer}); @@ -227,7 +255,7 @@ TEST_F(TranslationUnits, Remove) TEST_F(TranslationUnits, RemoveAllValidIfExceptionIsThrown) { ClangBackEnd::FileContainer fileContainer(filePath, projectPartId); - translationUnits.createOrUpdate({fileContainer}); + translationUnits.create({fileContainer}); ASSERT_THROW(translationUnits.remove({ClangBackEnd::FileContainer(Utf8StringLiteral("dontextist.pro"), projectPartId), fileContainer}), ClangBackEnd::TranslationUnitDoesNotExistException); @@ -240,7 +268,7 @@ TEST_F(TranslationUnits, RemoveAllValidIfExceptionIsThrown) TEST_F(TranslationUnits, HasTranslationUnit) { - translationUnits.createOrUpdate({{filePath, projectPartId}}); + translationUnits.create({{filePath, projectPartId}}); ASSERT_TRUE(translationUnits.hasTranslationUnit(filePath)); }