forked from qt-creator/qt-creator
Clang: Add current and visible editor message
Change-Id: Ifd88bc032388ae7a8d3dbc0f1f5746665074cc18 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
9310c02bc8
commit
8c3959534d
@@ -46,7 +46,8 @@ SOURCES += $$PWD/ipcserverinterface.cpp \
|
||||
$$PWD/requestdiagnosticsmessage.cpp \
|
||||
$$PWD/registerunsavedfilesforeditormessage.cpp \
|
||||
$$PWD/unregisterunsavedfilesforeditormessage.cpp \
|
||||
$$PWD/updatetranslationunitsforeditormessage.cpp
|
||||
$$PWD/updatetranslationunitsforeditormessage.cpp \
|
||||
$$PWD/updatevisibletranslationunitsmessage.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/ipcserverinterface.h \
|
||||
@@ -87,6 +88,7 @@ HEADERS += \
|
||||
$$PWD/requestdiagnosticsmessage.h \
|
||||
$$PWD/registerunsavedfilesforeditormessage.h \
|
||||
$$PWD/unregisterunsavedfilesforeditormessage.h \
|
||||
$$PWD/updatetranslationunitsforeditormessage.h
|
||||
$$PWD/updatetranslationunitsforeditormessage.h \
|
||||
$$PWD/updatevisibletranslationunitsmessage.h
|
||||
|
||||
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
|
||||
|
@@ -49,6 +49,7 @@
|
||||
#include "translationunitdoesnotexistmessage.h"
|
||||
#include "unregisterunsavedfilesforeditormessage.h"
|
||||
#include "updatetranslationunitsforeditormessage.h"
|
||||
#include "updatevisibletranslationunitsmessage.h"
|
||||
|
||||
#include <QDataStream>
|
||||
|
||||
@@ -82,6 +83,8 @@ void Messages::registerMessages()
|
||||
registerMetaType<RequestDiagnosticsMessage>();
|
||||
registerMetaType<DiagnosticsChangedMessage>();
|
||||
|
||||
registerMetaType<UpdateVisibleTranslationUnitsMessage>();
|
||||
|
||||
registerMetaType<CompleteCodeMessage>();
|
||||
registerMetaType<CodeCompletedMessage>();
|
||||
registerMetaType<CodeCompletion>();
|
||||
|
@@ -50,6 +50,7 @@ class DiagnosticsChangedMessage;
|
||||
class RequestDiagnosticsMessage;
|
||||
class RegisterUnsavedFilesForEditorMessage;
|
||||
class UnregisterUnsavedFilesForEditorMessage;
|
||||
class UpdateVisibleTranslationUnitsMessage;
|
||||
|
||||
class CMBIPC_EXPORT IpcClientInterface : public IpcInterface
|
||||
{
|
||||
|
@@ -39,6 +39,7 @@
|
||||
#include "requestdiagnosticsmessage.h"
|
||||
#include "unregisterunsavedfilesforeditormessage.h"
|
||||
#include "updatetranslationunitsforeditormessage.h"
|
||||
#include "updatevisibletranslationunitsmessage.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QVariant>
|
||||
@@ -57,6 +58,8 @@ void IpcServerInterface::dispatch(const QVariant &message)
|
||||
static const int unregisterUnsavedFilesForEditorMessageType = QMetaType::type("ClangBackEnd::UnregisterUnsavedFilesForEditorMessage");
|
||||
static const int completeCodeMessageType = QMetaType::type("ClangBackEnd::CompleteCodeMessage");
|
||||
static const int requestDiagnosticsMessageType = QMetaType::type("ClangBackEnd::RequestDiagnosticsMessage");
|
||||
static const int updateVisibleTranslationUnitsMessageType = QMetaType::type("ClangBackEnd::UpdateVisibleTranslationUnitsMessage");
|
||||
|
||||
|
||||
int type = message.userType();
|
||||
|
||||
@@ -80,6 +83,8 @@ void IpcServerInterface::dispatch(const QVariant &message)
|
||||
completeCode(message.value<CompleteCodeMessage>());
|
||||
else if (type == requestDiagnosticsMessageType)
|
||||
requestDiagnostics(message.value<RequestDiagnosticsMessage>());
|
||||
else if (type == updateVisibleTranslationUnitsMessageType)
|
||||
updateVisibleTranslationUnits(message.value<UpdateVisibleTranslationUnitsMessage>());
|
||||
else
|
||||
qWarning() << "Unknown IpcServerMessage";
|
||||
}
|
||||
|
@@ -54,6 +54,7 @@ public:
|
||||
virtual void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) = 0;
|
||||
virtual void completeCode(const CompleteCodeMessage &message) = 0;
|
||||
virtual void requestDiagnostics(const RequestDiagnosticsMessage &message) = 0;
|
||||
virtual void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) = 0;
|
||||
|
||||
void addClient(IpcClientInterface *client);
|
||||
void removeClient(IpcClientInterface *client);
|
||||
|
@@ -42,6 +42,7 @@
|
||||
#include <requestdiagnosticsmessage.h>
|
||||
#include <unregisterunsavedfilesforeditormessage.h>
|
||||
#include <updatetranslationunitsforeditormessage.h>
|
||||
#include <updatevisibletranslationunitsmessage.h>
|
||||
|
||||
#include <QLocalServer>
|
||||
#include <QLocalSocket>
|
||||
@@ -119,5 +120,10 @@ void IpcServerProxy::requestDiagnostics(const ClangBackEnd::RequestDiagnosticsMe
|
||||
writeMessageBlock.write(QVariant::fromValue(message));
|
||||
}
|
||||
|
||||
void IpcServerProxy::updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message)
|
||||
{
|
||||
writeMessageBlock.write(QVariant::fromValue(message));
|
||||
}
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
|
@@ -65,7 +65,7 @@ public:
|
||||
void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override;
|
||||
void completeCode(const CompleteCodeMessage &message) override;
|
||||
void requestDiagnostics(const RequestDiagnosticsMessage &message) override;
|
||||
|
||||
void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) override;
|
||||
void readMessages();
|
||||
|
||||
void resetCounter();
|
||||
|
@@ -0,0 +1,116 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "updatevisibletranslationunitsmessage.h"
|
||||
|
||||
#include "container_common.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QDebug>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <ostream>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
UpdateVisibleTranslationUnitsMessage::UpdateVisibleTranslationUnitsMessage(
|
||||
const Utf8String ¤tEditorFilePath,
|
||||
const Utf8StringVector &visibleEditorFilePaths)
|
||||
: currentEditorFilePath_(currentEditorFilePath),
|
||||
visibleEditorFilePaths_(visibleEditorFilePaths)
|
||||
{
|
||||
}
|
||||
|
||||
const Utf8String &UpdateVisibleTranslationUnitsMessage::currentEditorFilePath() const
|
||||
{
|
||||
return currentEditorFilePath_;
|
||||
}
|
||||
|
||||
const Utf8StringVector &UpdateVisibleTranslationUnitsMessage::visibleEditorFilePaths() const
|
||||
{
|
||||
return visibleEditorFilePaths_;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const UpdateVisibleTranslationUnitsMessage &message)
|
||||
{
|
||||
out << message.currentEditorFilePath_;
|
||||
out << message.visibleEditorFilePaths_;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, UpdateVisibleTranslationUnitsMessage &message)
|
||||
{
|
||||
in >> message.currentEditorFilePath_;
|
||||
in >> message.visibleEditorFilePaths_;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
bool operator==(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second)
|
||||
{
|
||||
return first.currentEditorFilePath_ == second.currentEditorFilePath_
|
||||
&& first.visibleEditorFilePaths_ == second.visibleEditorFilePaths_;
|
||||
}
|
||||
|
||||
bool operator<(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second)
|
||||
{
|
||||
return first.currentEditorFilePath_ < second.currentEditorFilePath_
|
||||
&& compareContainer(first.visibleEditorFilePaths_, second.visibleEditorFilePaths_);
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const UpdateVisibleTranslationUnitsMessage &message)
|
||||
{
|
||||
debug.nospace() << "UpdateVisibleTranslationUnitsMessage(";
|
||||
|
||||
debug.nospace() << message.currentEditorFilePath() << ", ";
|
||||
|
||||
for (const Utf8String &visibleEditorFilePath : message.visibleEditorFilePaths())
|
||||
debug.nospace() << visibleEditorFilePath << ", ";
|
||||
|
||||
debug.nospace() << ")";
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
void PrintTo(const UpdateVisibleTranslationUnitsMessage &message, ::std::ostream* os)
|
||||
{
|
||||
*os << "UpdateVisibleTranslationUnitsMessage(";
|
||||
|
||||
*os << message.currentEditorFilePath().constData() << ", ";
|
||||
|
||||
auto visiblePaths = message.visibleEditorFilePaths();
|
||||
|
||||
std::copy(visiblePaths.cbegin(), visiblePaths.cend(), std::ostream_iterator<Utf8String>(*os, ", "));
|
||||
|
||||
*os << ")";
|
||||
}
|
||||
|
||||
} // namespace ClangBackEnd
|
@@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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_UPDATEVISIBLETRANSLATIONUNITSMESSAGE_H
|
||||
#define CLANGBACKEND_UPDATEVISIBLETRANSLATIONUNITSMESSAGE_H
|
||||
|
||||
#include <clangbackendipc_global.h>
|
||||
|
||||
#include <utf8stringvector.h>
|
||||
|
||||
#include <QMetaType>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class CMBIPC_EXPORT UpdateVisibleTranslationUnitsMessage
|
||||
{
|
||||
friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UpdateVisibleTranslationUnitsMessage &message);
|
||||
friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UpdateVisibleTranslationUnitsMessage &message);
|
||||
friend CMBIPC_EXPORT bool operator==(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second);
|
||||
friend CMBIPC_EXPORT bool operator<(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second);
|
||||
|
||||
public:
|
||||
UpdateVisibleTranslationUnitsMessage() = default;
|
||||
UpdateVisibleTranslationUnitsMessage(const Utf8String ¤tEditorFilePath,
|
||||
const Utf8StringVector &visibleEditorFilePaths);
|
||||
|
||||
const Utf8String ¤tEditorFilePath() const;
|
||||
const Utf8StringVector &visibleEditorFilePaths() const;
|
||||
|
||||
private:
|
||||
Utf8String currentEditorFilePath_;
|
||||
Utf8StringVector visibleEditorFilePaths_;
|
||||
};
|
||||
|
||||
CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UpdateVisibleTranslationUnitsMessage &message);
|
||||
CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UpdateVisibleTranslationUnitsMessage &message);
|
||||
CMBIPC_EXPORT bool operator==(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second);
|
||||
CMBIPC_EXPORT bool operator<(const UpdateVisibleTranslationUnitsMessage &first, const UpdateVisibleTranslationUnitsMessage &second);
|
||||
|
||||
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UpdateVisibleTranslationUnitsMessage &message);
|
||||
void PrintTo(const UpdateVisibleTranslationUnitsMessage &message, ::std::ostream* os);
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
Q_DECLARE_METATYPE(ClangBackEnd::UpdateVisibleTranslationUnitsMessage)
|
||||
|
||||
#endif // CLANGBACKEND_UPDATEVISIBLETRANSLATIONUNITSMESSAGE_H
|
@@ -269,6 +269,14 @@ void PrintTo(const Utf8String &text, ::std::ostream* os)
|
||||
*os << "\"" << text.toByteArray().data() << "\"";
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream &os, const Utf8String &utf8String)
|
||||
{
|
||||
using std::ostream;
|
||||
os << utf8String.constData();
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
uint qHash(const Utf8String &utf8String)
|
||||
{
|
||||
return qHash(utf8String.byteArray);
|
||||
|
@@ -36,6 +36,8 @@
|
||||
#include <QByteArray>
|
||||
#include <QMetaType>
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
class Utf8StringVector;
|
||||
class Utf8String;
|
||||
|
||||
@@ -120,6 +122,7 @@ SQLITE_EXPORT QDataStream &operator<<(QDataStream &datastream, const Utf8String
|
||||
SQLITE_EXPORT QDataStream &operator>>(QDataStream &datastream, Utf8String &text);
|
||||
SQLITE_EXPORT QDebug operator<<(QDebug debug, const Utf8String &text);
|
||||
SQLITE_EXPORT void PrintTo(const Utf8String &text, ::std::ostream* os);
|
||||
SQLITE_EXPORT std::ostream& operator<<(std::ostream &os, const Utf8String &utf8String);
|
||||
|
||||
SQLITE_EXPORT uint qHash(const Utf8String &utf8String);
|
||||
|
||||
|
@@ -54,6 +54,7 @@
|
||||
#include <translationunitdoesnotexistmessage.h>
|
||||
#include <unregisterunsavedfilesforeditormessage.h>
|
||||
#include <updatetranslationunitsforeditormessage.h>
|
||||
#include <updatevisibletranslationunitsmessage.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
@@ -243,6 +244,18 @@ void ClangIpcServer::requestDiagnostics(const RequestDiagnosticsMessage &message
|
||||
}
|
||||
}
|
||||
|
||||
void ClangIpcServer::updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message)
|
||||
{
|
||||
TIME_SCOPE_DURATION("ClangIpcServer::updateVisibleTranslationUnits");
|
||||
|
||||
try {
|
||||
translationUnits.setCurrentEditor(message.currentEditorFilePath());
|
||||
translationUnits.setVisibleEditors(message.visibleEditorFilePaths());
|
||||
} catch (const std::exception &exception) {
|
||||
qWarning() << "Error in ClangIpcServer::updateVisibleTranslationUnits:" << exception.what();
|
||||
}
|
||||
}
|
||||
|
||||
const TranslationUnits &ClangIpcServer::translationUnitsForTestOnly() const
|
||||
{
|
||||
return translationUnits;
|
||||
|
@@ -61,6 +61,7 @@ public:
|
||||
void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override;
|
||||
void completeCode(const CompleteCodeMessage &message) override;
|
||||
void requestDiagnostics(const RequestDiagnosticsMessage &message) override;
|
||||
void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) override;
|
||||
|
||||
const TranslationUnits &translationUnitsForTestOnly() const;
|
||||
|
||||
|
@@ -43,6 +43,7 @@
|
||||
#include "requestdiagnosticsmessage.h"
|
||||
#include "unregisterunsavedfilesforeditormessage.h"
|
||||
#include "updatetranslationunitsforeditormessage.h"
|
||||
#include "updatevisibletranslationunitsmessage.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
@@ -106,6 +107,11 @@ void EchoIpcServer::requestDiagnostics(const RequestDiagnosticsMessage &message)
|
||||
echoMessage(QVariant::fromValue(message));
|
||||
}
|
||||
|
||||
void EchoIpcServer::updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message)
|
||||
{
|
||||
echoMessage(QVariant::fromValue(message));
|
||||
}
|
||||
|
||||
void EchoIpcServer::echoMessage(const QVariant &message)
|
||||
{
|
||||
client()->echo(EchoMessage(message));
|
||||
|
@@ -49,6 +49,7 @@ public:
|
||||
void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override;
|
||||
void completeCode(const CompleteCodeMessage &message) override;
|
||||
void requestDiagnostics(const RequestDiagnosticsMessage &message) override;
|
||||
void updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message) override;
|
||||
|
||||
private:
|
||||
void echoMessage(const QVariant &message);
|
||||
|
@@ -47,6 +47,7 @@
|
||||
#include <projectpartsdonotexistmessage.h>
|
||||
#include <translationunitdoesnotexistmessage.h>
|
||||
#include <updatetranslationunitsforeditormessage.h>
|
||||
#include <updatevisibletranslationunitsmessage.h>
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QFile>
|
||||
@@ -76,6 +77,7 @@ using ClangBackEnd::ProjectPartContainer;
|
||||
using ClangBackEnd::TranslationUnitDoesNotExistMessage;
|
||||
using ClangBackEnd::ProjectPartsDoNotExistMessage;
|
||||
using ClangBackEnd::UpdateTranslationUnitsForEditorMessage;
|
||||
using ClangBackEnd::UpdateVisibleTranslationUnitsMessage;
|
||||
|
||||
MATCHER_P5(HasDirtyTranslationUnit,
|
||||
filePath,
|
||||
@@ -135,11 +137,13 @@ protected:
|
||||
void registerProjectPart();
|
||||
void changeProjectPartArguments();
|
||||
void changeProjectPartArgumentsToWrongValues();
|
||||
void updateVisibilty(const Utf8String ¤tEditor, const Utf8String &additionalVisibleEditor);
|
||||
static const Utf8String unsavedContent(const QString &unsavedFilePath);
|
||||
|
||||
protected:
|
||||
MockIpcClient mockIpcClient;
|
||||
ClangBackEnd::ClangIpcServer clangServer;
|
||||
const ClangBackEnd::TranslationUnits &translationUnits = clangServer.translationUnitsForTestOnly();
|
||||
const Utf8String projectPartId = Utf8StringLiteral("pathToProjectPart.pro");
|
||||
const Utf8String functionTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp");
|
||||
const Utf8String variableTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp");
|
||||
@@ -148,53 +152,6 @@ protected:
|
||||
const Utf8String parseErrorTestFilePath = Utf8StringLiteral(TESTDATA_DIR"/complete_translationunit_parse_error.cpp");
|
||||
};
|
||||
|
||||
|
||||
void ClangIpcServer::SetUp()
|
||||
{
|
||||
clangServer.addClient(&mockIpcClient);
|
||||
registerProjectPart();
|
||||
registerFiles();
|
||||
}
|
||||
|
||||
void ClangIpcServer::registerFiles()
|
||||
{
|
||||
RegisterTranslationUnitForEditorMessage message({FileContainer(functionTestFilePath, projectPartId, unsavedContent(unsavedTestFilePath), true),
|
||||
FileContainer(variableTestFilePath, projectPartId)});
|
||||
|
||||
clangServer.registerTranslationUnitsForEditor(message);
|
||||
}
|
||||
|
||||
void ClangIpcServer::registerProjectPart()
|
||||
{
|
||||
RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId)});
|
||||
|
||||
clangServer.registerProjectPartsForEditor(message);
|
||||
}
|
||||
|
||||
void ClangIpcServer::changeProjectPartArguments()
|
||||
{
|
||||
RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DArgumentDefinition")})});
|
||||
|
||||
clangServer.registerProjectPartsForEditor(message);
|
||||
}
|
||||
|
||||
void ClangIpcServer::changeProjectPartArgumentsToWrongValues()
|
||||
{
|
||||
RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-blah")})});
|
||||
|
||||
clangServer.registerProjectPartsForEditor(message);
|
||||
}
|
||||
|
||||
const Utf8String ClangIpcServer::unsavedContent(const QString &unsavedFilePath)
|
||||
{
|
||||
QFile unsavedFileContentFile(unsavedFilePath);
|
||||
bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
if (!isOpen)
|
||||
ADD_FAILURE() << "File with the unsaved content cannot be opened!";
|
||||
|
||||
return Utf8String::fromByteArray(unsavedFileContentFile.readAll());
|
||||
}
|
||||
|
||||
TEST_F(ClangIpcServer, GetCodeCompletion)
|
||||
{
|
||||
CompleteCodeMessage completeCodeMessage(functionTestFilePath,
|
||||
@@ -426,6 +383,86 @@ TEST_F(ClangIpcServer, TranslationUnitAfterCreationNeedsNoReparseAndHasNewDiagno
|
||||
ASSERT_THAT(clangServer, HasDirtyTranslationUnit(functionTestFilePath, projectPartId, 0U, false, true));
|
||||
}
|
||||
|
||||
TEST_F(ClangIpcServer, SetCurrentAndVisibleEditor)
|
||||
{
|
||||
auto functionTranslationUnit = translationUnits.translationUnit(functionTestFilePath, projectPartId);
|
||||
auto variableTranslationUnit = translationUnits.translationUnit(variableTestFilePath, projectPartId);
|
||||
|
||||
updateVisibilty(functionTestFilePath, variableTestFilePath);
|
||||
|
||||
ASSERT_TRUE(functionTranslationUnit.isUsedByCurrentEditor());
|
||||
ASSERT_TRUE(functionTranslationUnit.isVisibleInEditor());
|
||||
ASSERT_TRUE(variableTranslationUnit.isVisibleInEditor());
|
||||
}
|
||||
|
||||
TEST_F(ClangIpcServer, IsNotCurrentCurrentAndVisibleEditorAnymore)
|
||||
{
|
||||
auto functionTranslationUnit = translationUnits.translationUnit(functionTestFilePath, projectPartId);
|
||||
auto variableTranslationUnit = translationUnits.translationUnit(variableTestFilePath, projectPartId);
|
||||
updateVisibilty(functionTestFilePath, variableTestFilePath);
|
||||
|
||||
updateVisibilty(variableTestFilePath, Utf8String());
|
||||
|
||||
ASSERT_FALSE(functionTranslationUnit.isUsedByCurrentEditor());
|
||||
ASSERT_FALSE(functionTranslationUnit.isVisibleInEditor());
|
||||
ASSERT_TRUE(variableTranslationUnit.isUsedByCurrentEditor());
|
||||
ASSERT_TRUE(variableTranslationUnit.isVisibleInEditor());
|
||||
}
|
||||
|
||||
void ClangIpcServer::SetUp()
|
||||
{
|
||||
clangServer.addClient(&mockIpcClient);
|
||||
registerProjectPart();
|
||||
registerFiles();
|
||||
}
|
||||
|
||||
void ClangIpcServer::registerFiles()
|
||||
{
|
||||
RegisterTranslationUnitForEditorMessage message({FileContainer(functionTestFilePath, projectPartId, unsavedContent(unsavedTestFilePath), true),
|
||||
FileContainer(variableTestFilePath, projectPartId)});
|
||||
|
||||
clangServer.registerTranslationUnitsForEditor(message);
|
||||
}
|
||||
|
||||
void ClangIpcServer::registerProjectPart()
|
||||
{
|
||||
RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId)});
|
||||
|
||||
clangServer.registerProjectPartsForEditor(message);
|
||||
}
|
||||
|
||||
void ClangIpcServer::changeProjectPartArguments()
|
||||
{
|
||||
RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-DArgumentDefinition")})});
|
||||
|
||||
clangServer.registerProjectPartsForEditor(message);
|
||||
}
|
||||
|
||||
void ClangIpcServer::changeProjectPartArgumentsToWrongValues()
|
||||
{
|
||||
RegisterProjectPartsForEditorMessage message({ProjectPartContainer(projectPartId, {Utf8StringLiteral("-blah")})});
|
||||
|
||||
clangServer.registerProjectPartsForEditor(message);
|
||||
}
|
||||
|
||||
void ClangIpcServer::updateVisibilty(const Utf8String ¤tEditor, const Utf8String &additionalVisibleEditor)
|
||||
{
|
||||
UpdateVisibleTranslationUnitsMessage message(currentEditor,
|
||||
{currentEditor, additionalVisibleEditor});
|
||||
|
||||
clangServer.updateVisibleTranslationUnits(message);
|
||||
}
|
||||
|
||||
const Utf8String ClangIpcServer::unsavedContent(const QString &unsavedFilePath)
|
||||
{
|
||||
QFile unsavedFileContentFile(unsavedFilePath);
|
||||
bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
if (!isOpen)
|
||||
ADD_FAILURE() << "File with the unsaved content cannot be opened!";
|
||||
|
||||
return Utf8String::fromByteArray(unsavedFileContentFile.readAll());
|
||||
}
|
||||
|
||||
TEST_F(ClangIpcServer, TranslationUnitAfterUpdateNeedsReparseAndHasNewDiagnostics)
|
||||
{
|
||||
const auto fileContainer = FileContainer(functionTestFilePath, projectPartId,unsavedContent(unsavedTestFilePath), true, 1);
|
||||
|
@@ -53,6 +53,7 @@
|
||||
#include <translationunitdoesnotexistmessage.h>
|
||||
#include <unregisterunsavedfilesforeditormessage.h>
|
||||
#include <updatetranslationunitsforeditormessage.h>
|
||||
#include <updatevisibletranslationunitsmessage.h>
|
||||
#include <writemessageblock.h>
|
||||
|
||||
#include <QBuffer>
|
||||
@@ -232,6 +233,19 @@ TEST_F(ClientServerInProcess, SendUnregisterProjectPartsForEditorMessage)
|
||||
scheduleServerMessages();
|
||||
}
|
||||
|
||||
TEST_F(ClientServerInProcess, UpdateVisibleTranslationUnitsMessage)
|
||||
{
|
||||
ClangBackEnd::UpdateVisibleTranslationUnitsMessage message(Utf8StringLiteral(TESTDATA_DIR"/fileone.cpp"),
|
||||
{Utf8StringLiteral(TESTDATA_DIR"/fileone.cpp"),
|
||||
Utf8StringLiteral(TESTDATA_DIR"/filetwo.cpp")});
|
||||
|
||||
EXPECT_CALL(mockIpcServer, updateVisibleTranslationUnits(message))
|
||||
.Times(1);
|
||||
|
||||
serverProxy.updateVisibleTranslationUnits(message);
|
||||
scheduleServerMessages();
|
||||
}
|
||||
|
||||
TEST_F(ClientServerInProcess, SendTranslationUnitDoesNotExistMessage)
|
||||
{
|
||||
ClangBackEnd::TranslationUnitDoesNotExistMessage message(fileContainer);
|
||||
|
@@ -60,6 +60,8 @@ public:
|
||||
void(const ClangBackEnd::CompleteCodeMessage &message));
|
||||
MOCK_METHOD1(requestDiagnostics,
|
||||
void(const ClangBackEnd::RequestDiagnosticsMessage &message));
|
||||
MOCK_METHOD1(updateVisibleTranslationUnits,
|
||||
void(const ClangBackEnd::UpdateVisibleTranslationUnitsMessage &message));
|
||||
};
|
||||
|
||||
#endif // MOCKIPCSERVER_H
|
||||
|
Reference in New Issue
Block a user