Clang: Add unsaved files messages

We have auto generated buffers from ui files which are not open but have no
file representation. So we need to provide them as unsaved files only.

Change-Id: I48a426c18e06eeda2fa707864f32f293e17ac651
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Marco Bubke
2015-08-31 16:10:36 +02:00
parent 3114780e55
commit 7eee8061f6
25 changed files with 662 additions and 69 deletions
@@ -43,7 +43,9 @@ SOURCES += $$PWD/ipcserverinterface.cpp \
$$PWD/sourcerangecontainer.cpp \ $$PWD/sourcerangecontainer.cpp \
$$PWD/sourcelocationcontainer.cpp \ $$PWD/sourcelocationcontainer.cpp \
$$PWD/fixitcontainer.cpp \ $$PWD/fixitcontainer.cpp \
$$PWD/requestdiagnosticsmessage.cpp $$PWD/requestdiagnosticsmessage.cpp \
$$PWD/registerunsavedfilesforeditormessage.cpp \
$$PWD/unregisterunsavedfilesforeditormessage.cpp
HEADERS += \ HEADERS += \
$$PWD/ipcserverinterface.h \ $$PWD/ipcserverinterface.h \
@@ -81,6 +83,8 @@ HEADERS += \
$$PWD/sourcerangecontainer.h \ $$PWD/sourcerangecontainer.h \
$$PWD/sourcelocationcontainer.h \ $$PWD/sourcelocationcontainer.h \
$$PWD/fixitcontainer.h \ $$PWD/fixitcontainer.h \
$$PWD/requestdiagnosticsmessage.h $$PWD/requestdiagnosticsmessage.h \
$$PWD/registerunsavedfilesforeditormessage.h \
$$PWD/unregisterunsavedfilesforeditormessage.h
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
+10
View File
@@ -41,11 +41,13 @@
#include "cmbcodecompletedmessage.h" #include "cmbcodecompletedmessage.h"
#include "diagnosticcontainer.h" #include "diagnosticcontainer.h"
#include "diagnosticschangedmessage.h" #include "diagnosticschangedmessage.h"
#include "registerunsavedfilesforeditormessage.h"
#include "requestdiagnosticsmessage.h" #include "requestdiagnosticsmessage.h"
#include "projectpartsdonotexistmessage.h" #include "projectpartsdonotexistmessage.h"
#include "sourcelocationcontainer.h" #include "sourcelocationcontainer.h"
#include "sourcerangecontainer.h" #include "sourcerangecontainer.h"
#include "translationunitdoesnotexistmessage.h" #include "translationunitdoesnotexistmessage.h"
#include "unregisterunsavedfilesforeditormessage.h"
#include <QDataStream> #include <QDataStream>
@@ -127,6 +129,14 @@ void Messages::registerMessages()
qRegisterMetaType<RequestDiagnosticsMessage>(); qRegisterMetaType<RequestDiagnosticsMessage>();
qRegisterMetaTypeStreamOperators<RequestDiagnosticsMessage>(); qRegisterMetaTypeStreamOperators<RequestDiagnosticsMessage>();
QMetaType::registerComparators<RequestDiagnosticsMessage>(); QMetaType::registerComparators<RequestDiagnosticsMessage>();
qRegisterMetaType<RegisterUnsavedFilesForEditorMessage>();
qRegisterMetaTypeStreamOperators<RegisterUnsavedFilesForEditorMessage>();
QMetaType::registerComparators<RegisterUnsavedFilesForEditorMessage>();
qRegisterMetaType<UnregisterUnsavedFilesForEditorMessage>();
qRegisterMetaTypeStreamOperators<UnregisterUnsavedFilesForEditorMessage>();
QMetaType::registerComparators<UnregisterUnsavedFilesForEditorMessage>();
} }
} // namespace ClangBackEnd } // namespace ClangBackEnd
@@ -47,6 +47,8 @@ class TranslationUnitDoesNotExistMessage;
class ProjectPartsDoNotExistMessage; class ProjectPartsDoNotExistMessage;
class DiagnosticsChangedMessage; class DiagnosticsChangedMessage;
class RequestDiagnosticsMessage; class RequestDiagnosticsMessage;
class RegisterUnsavedFilesForEditorMessage;
class UnregisterUnsavedFilesForEditorMessage;
class CMBIPC_EXPORT IpcClientInterface : public IpcInterface class CMBIPC_EXPORT IpcClientInterface : public IpcInterface
{ {
@@ -35,7 +35,9 @@
#include "cmbregistertranslationunitsforeditormessage.h" #include "cmbregistertranslationunitsforeditormessage.h"
#include "cmbunregisterprojectsforeditormessage.h" #include "cmbunregisterprojectsforeditormessage.h"
#include "cmbunregistertranslationunitsforeditormessage.h" #include "cmbunregistertranslationunitsforeditormessage.h"
#include "registerunsavedfilesforeditormessage.h"
#include "requestdiagnosticsmessage.h" #include "requestdiagnosticsmessage.h"
#include "unregisterunsavedfilesforeditormessage.h"
#include <QDebug> #include <QDebug>
#include <QVariant> #include <QVariant>
@@ -49,6 +51,8 @@ void IpcServerInterface::dispatch(const QVariant &message)
static const int unregisterTranslationUnitsForEditorMessageType = QMetaType::type("ClangBackEnd::UnregisterTranslationUnitsForEditorMessage"); static const int unregisterTranslationUnitsForEditorMessageType = QMetaType::type("ClangBackEnd::UnregisterTranslationUnitsForEditorMessage");
static const int registerProjectPartsForEditorMessageType = QMetaType::type("ClangBackEnd::RegisterProjectPartsForEditorMessage"); static const int registerProjectPartsForEditorMessageType = QMetaType::type("ClangBackEnd::RegisterProjectPartsForEditorMessage");
static const int unregisterProjectPartsForEditorMessageType = QMetaType::type("ClangBackEnd::UnregisterProjectPartsForEditorMessage"); static const int unregisterProjectPartsForEditorMessageType = QMetaType::type("ClangBackEnd::UnregisterProjectPartsForEditorMessage");
static const int registerUnsavedFilesForEditorMessageType = QMetaType::type("ClangBackEnd::RegisterUnsavedFilesForEditorMessage");
static const int unregisterUnsavedFilesForEditorMessageType = QMetaType::type("ClangBackEnd::UnregisterUnsavedFilesForEditorMessage");
static const int completeCodeMessageType = QMetaType::type("ClangBackEnd::CompleteCodeMessage"); static const int completeCodeMessageType = QMetaType::type("ClangBackEnd::CompleteCodeMessage");
static const int requestDiagnosticsMessageType = QMetaType::type("ClangBackEnd::RequestDiagnosticsMessage"); static const int requestDiagnosticsMessageType = QMetaType::type("ClangBackEnd::RequestDiagnosticsMessage");
@@ -64,6 +68,10 @@ void IpcServerInterface::dispatch(const QVariant &message)
registerProjectPartsForEditor(message.value<RegisterProjectPartsForEditorMessage>()); registerProjectPartsForEditor(message.value<RegisterProjectPartsForEditorMessage>());
else if (type == unregisterProjectPartsForEditorMessageType) else if (type == unregisterProjectPartsForEditorMessageType)
unregisterProjectPartsForEditor(message.value<UnregisterProjectPartsForEditorMessage>()); unregisterProjectPartsForEditor(message.value<UnregisterProjectPartsForEditorMessage>());
else if (type == registerUnsavedFilesForEditorMessageType)
registerUnsavedFilesForEditor(message.value<RegisterUnsavedFilesForEditorMessage>());
else if (type == unregisterUnsavedFilesForEditorMessageType)
unregisterUnsavedFilesForEditor(message.value<UnregisterUnsavedFilesForEditorMessage>());
else if (type == completeCodeMessageType) else if (type == completeCodeMessageType)
completeCode(message.value<CompleteCodeMessage>()); completeCode(message.value<CompleteCodeMessage>());
else if (type == requestDiagnosticsMessageType) else if (type == requestDiagnosticsMessageType)
@@ -49,6 +49,8 @@ public:
virtual void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) = 0; virtual void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) = 0;
virtual void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) = 0; virtual void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) = 0;
virtual void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) = 0; virtual void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) = 0;
virtual void registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message) = 0;
virtual void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) = 0;
virtual void completeCode(const CompleteCodeMessage &message) = 0; virtual void completeCode(const CompleteCodeMessage &message) = 0;
virtual void requestDiagnostics(const RequestDiagnosticsMessage &message) = 0; virtual void requestDiagnostics(const RequestDiagnosticsMessage &message) = 0;
+13 -1
View File
@@ -37,8 +37,10 @@
#include <cmbregistertranslationunitsforeditormessage.h> #include <cmbregistertranslationunitsforeditormessage.h>
#include <cmbunregisterprojectsforeditormessage.h> #include <cmbunregisterprojectsforeditormessage.h>
#include <cmbunregistertranslationunitsforeditormessage.h> #include <cmbunregistertranslationunitsforeditormessage.h>
#include <requestdiagnosticsmessage.h>
#include <ipcclientinterface.h> #include <ipcclientinterface.h>
#include <registerunsavedfilesforeditormessage.h>
#include <requestdiagnosticsmessage.h>
#include <unregisterunsavedfilesforeditormessage.h>
#include <QLocalServer> #include <QLocalServer>
#include <QLocalSocket> #include <QLocalSocket>
@@ -91,6 +93,16 @@ void IpcServerProxy::unregisterProjectPartsForEditor(const UnregisterProjectPart
writeMessageBlock.write(QVariant::fromValue(message)); writeMessageBlock.write(QVariant::fromValue(message));
} }
void ClangBackEnd::IpcServerProxy::registerUnsavedFilesForEditor(const ClangBackEnd::RegisterUnsavedFilesForEditorMessage &message)
{
writeMessageBlock.write(QVariant::fromValue(message));
}
void ClangBackEnd::IpcServerProxy::unregisterUnsavedFilesForEditor(const ClangBackEnd::UnregisterUnsavedFilesForEditorMessage &message)
{
writeMessageBlock.write(QVariant::fromValue(message));
}
void IpcServerProxy::completeCode(const CompleteCodeMessage &message) void IpcServerProxy::completeCode(const CompleteCodeMessage &message)
{ {
writeMessageBlock.write(QVariant::fromValue(message)); writeMessageBlock.write(QVariant::fromValue(message));
@@ -60,6 +60,8 @@ public:
void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override; void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override;
void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) override; void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) override;
void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override; void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override;
void registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message) override;
void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override;
void completeCode(const CompleteCodeMessage &message) override; void completeCode(const CompleteCodeMessage &message) override;
void requestDiagnostics(const RequestDiagnosticsMessage &message) override; void requestDiagnostics(const RequestDiagnosticsMessage &message) override;
@@ -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 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 "registerunsavedfilesforeditormessage.h"
#include "container_common.h"
#include <QDataStream>
#include <QDebug>
#include <ostream>
namespace ClangBackEnd {
RegisterUnsavedFilesForEditorMessage::RegisterUnsavedFilesForEditorMessage(const QVector<FileContainer> &fileContainers)
: fileContainers_(fileContainers)
{
}
const QVector<FileContainer> &RegisterUnsavedFilesForEditorMessage::fileContainers() const
{
return fileContainers_;
}
QDataStream &operator<<(QDataStream &out, const RegisterUnsavedFilesForEditorMessage &message)
{
out << message.fileContainers_;
return out;
}
QDataStream &operator>>(QDataStream &in, RegisterUnsavedFilesForEditorMessage &message)
{
in >> message.fileContainers_;
return in;
}
bool operator==(const RegisterUnsavedFilesForEditorMessage &first, const RegisterUnsavedFilesForEditorMessage &second)
{
return first.fileContainers_ == second.fileContainers_;
}
bool operator<(const RegisterUnsavedFilesForEditorMessage &first, const RegisterUnsavedFilesForEditorMessage &second)
{
return compareContainer(first.fileContainers_, second.fileContainers_);
}
QDebug operator<<(QDebug debug, const RegisterUnsavedFilesForEditorMessage &message)
{
debug.nospace() << "RegisterUnsavedFilesForEditorMessage(";
for (const FileContainer &fileContainer : message.fileContainers())
debug.nospace() << fileContainer<< ", ";
debug.nospace() << ")";
return debug;
}
void PrintTo(const RegisterUnsavedFilesForEditorMessage &message, ::std::ostream* os)
{
*os << "RegisterUnsavedFilesForEditorMessage(";
for (const FileContainer &fileContainer : message.fileContainers())
PrintTo(fileContainer, os);
*os << ")";
}
} // namespace ClangBackEnd
@@ -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 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_REGISTERUNSAVEDFILESFOREDITORMESSAGE_H
#define CLANGBACKEND_REGISTERUNSAVEDFILESFOREDITORMESSAGE_H
#include "filecontainer.h"
#include <QMetaType>
#include <QVector>
namespace ClangBackEnd {
class CMBIPC_EXPORT RegisterUnsavedFilesForEditorMessage
{
friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const RegisterUnsavedFilesForEditorMessage &message);
friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, RegisterUnsavedFilesForEditorMessage &message);
friend CMBIPC_EXPORT bool operator==(const RegisterUnsavedFilesForEditorMessage &first, const RegisterUnsavedFilesForEditorMessage &second);
friend CMBIPC_EXPORT bool operator<(const RegisterUnsavedFilesForEditorMessage &first, const RegisterUnsavedFilesForEditorMessage &second);
friend void PrintTo(const RegisterUnsavedFilesForEditorMessage &message, ::std::ostream* os);
public:
RegisterUnsavedFilesForEditorMessage() = default;
RegisterUnsavedFilesForEditorMessage(const QVector<FileContainer> &fileContainers);
const QVector<FileContainer> &fileContainers() const;
private:
QVector<FileContainer> fileContainers_;
};
CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const RegisterUnsavedFilesForEditorMessage &message);
CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, RegisterUnsavedFilesForEditorMessage &message);
CMBIPC_EXPORT bool operator==(const RegisterUnsavedFilesForEditorMessage &first, const RegisterUnsavedFilesForEditorMessage &second);
CMBIPC_EXPORT bool operator<(const RegisterUnsavedFilesForEditorMessage &first, const RegisterUnsavedFilesForEditorMessage &second);
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const RegisterUnsavedFilesForEditorMessage &message);
void PrintTo(const RegisterUnsavedFilesForEditorMessage &message, ::std::ostream* os);
} // namespace ClangBackEnd
Q_DECLARE_METATYPE(ClangBackEnd::RegisterUnsavedFilesForEditorMessage)
#endif // CLANGBACKEND_REGISTERUNSAVEDFILESFOREDITORMESSAGE_H
@@ -0,0 +1,100 @@
/****************************************************************************
**
** 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 "unregisterunsavedfilesforeditormessage.h"
#include "container_common.h"
#include <QDataStream>
#include <QDebug>
#include <ostream>
namespace ClangBackEnd {
UnregisterUnsavedFilesForEditorMessage::UnregisterUnsavedFilesForEditorMessage(const QVector<FileContainer> &fileContainers)
: fileContainers_(fileContainers)
{
}
const QVector<FileContainer> &UnregisterUnsavedFilesForEditorMessage::fileContainers() const
{
return fileContainers_;
}
QDataStream &operator<<(QDataStream &out, const UnregisterUnsavedFilesForEditorMessage &message)
{
out << message.fileContainers_;
return out;
}
QDataStream &operator>>(QDataStream &in, UnregisterUnsavedFilesForEditorMessage &message)
{
in >> message.fileContainers_;
return in;
}
bool operator==(const UnregisterUnsavedFilesForEditorMessage &first, const UnregisterUnsavedFilesForEditorMessage &second)
{
return first.fileContainers_ == second.fileContainers_;
}
bool operator<(const UnregisterUnsavedFilesForEditorMessage &first, const UnregisterUnsavedFilesForEditorMessage &second)
{
return compareContainer(first.fileContainers_, second.fileContainers_);
}
QDebug operator<<(QDebug debug, const UnregisterUnsavedFilesForEditorMessage &message)
{
debug.nospace() << "UnregisterUnsavedFilesForEditorMessage(";
for (const FileContainer &fileContainer : message.fileContainers())
debug.nospace() << fileContainer<< ", ";
debug.nospace() << ")";
return debug;
}
void PrintTo(const UnregisterUnsavedFilesForEditorMessage &message, ::std::ostream* os)
{
*os << "UnregisterUnsavedFilesForEditorMessage(";
for (const FileContainer &fileContainer : message.fileContainers())
PrintTo(fileContainer, os);
*os << ")";
}
} // namespace ClangBackEnd
@@ -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 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_UNREGISTERTRANSLATIONUNITSFOREDITORMESSAGE_H
#define CLANGBACKEND_UNREGISTERTRANSLATIONUNITSFOREDITORMESSAGE_H
#include "filecontainer.h"
#include <QMetaType>
#include <QVector>
namespace ClangBackEnd {
class CMBIPC_EXPORT UnregisterUnsavedFilesForEditorMessage
{
friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UnregisterUnsavedFilesForEditorMessage &message);
friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UnregisterUnsavedFilesForEditorMessage &message);
friend CMBIPC_EXPORT bool operator==(const UnregisterUnsavedFilesForEditorMessage &first, const UnregisterUnsavedFilesForEditorMessage &second);
friend CMBIPC_EXPORT bool operator<(const UnregisterUnsavedFilesForEditorMessage &first, const UnregisterUnsavedFilesForEditorMessage &second);
friend void PrintTo(const UnregisterUnsavedFilesForEditorMessage &message, ::std::ostream* os);
public:
UnregisterUnsavedFilesForEditorMessage() = default;
UnregisterUnsavedFilesForEditorMessage(const QVector<FileContainer> &fileContainers);
const QVector<FileContainer> &fileContainers() const;
private:
QVector<FileContainer> fileContainers_;
};
CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const UnregisterUnsavedFilesForEditorMessage &message);
CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, UnregisterUnsavedFilesForEditorMessage &message);
CMBIPC_EXPORT bool operator==(const UnregisterUnsavedFilesForEditorMessage &first, const UnregisterUnsavedFilesForEditorMessage &second);
CMBIPC_EXPORT bool operator<(const UnregisterUnsavedFilesForEditorMessage &first, const UnregisterUnsavedFilesForEditorMessage &second);
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const UnregisterUnsavedFilesForEditorMessage &message);
void PrintTo(const UnregisterUnsavedFilesForEditorMessage &message, ::std::ostream* os);
} // namespace ClangBackEnd
Q_DECLARE_METATYPE(ClangBackEnd::UnregisterUnsavedFilesForEditorMessage)
#endif // CLANGBACKEND_UNREGISTERTRANSLATIONUNITSFOREDITORMESSAGE_H
@@ -60,10 +60,12 @@
#include <clangbackendipc/cmbunregistertranslationunitsforeditormessage.h> #include <clangbackendipc/cmbunregistertranslationunitsforeditormessage.h>
#include <clangbackendipc/cmbunregisterprojectsforeditormessage.h> #include <clangbackendipc/cmbunregisterprojectsforeditormessage.h>
#include <clangbackendipc/cmbmessages.h> #include <clangbackendipc/cmbmessages.h>
#include <clangbackendipc/registerunsavedfilesforeditormessage.h>
#include <clangbackendipc/requestdiagnosticsmessage.h> #include <clangbackendipc/requestdiagnosticsmessage.h>
#include <clangbackendipc/filecontainer.h> #include <clangbackendipc/filecontainer.h>
#include <clangbackendipc/projectpartsdonotexistmessage.h> #include <clangbackendipc/projectpartsdonotexistmessage.h>
#include <clangbackendipc/translationunitdoesnotexistmessage.h> #include <clangbackendipc/translationunitdoesnotexistmessage.h>
#include <clangbackendipc/unregisterunsavedfilesforeditormessage.h>
#include <cplusplus/Icons.h> #include <cplusplus/Icons.h>
@@ -195,6 +197,8 @@ public:
void unregisterTranslationUnitsForEditor(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &message) override; void unregisterTranslationUnitsForEditor(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &message) override;
void registerProjectPartsForEditor(const ClangBackEnd::RegisterProjectPartsForEditorMessage &message) override; void registerProjectPartsForEditor(const ClangBackEnd::RegisterProjectPartsForEditorMessage &message) override;
void unregisterProjectPartsForEditor(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &message) override; void unregisterProjectPartsForEditor(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &message) override;
void registerUnsavedFilesForEditor(const ClangBackEnd::RegisterUnsavedFilesForEditorMessage &message) override;
void unregisterUnsavedFilesForEditor(const ClangBackEnd::UnregisterUnsavedFilesForEditorMessage &message) override;
void completeCode(const ClangBackEnd::CompleteCodeMessage &message) override; void completeCode(const ClangBackEnd::CompleteCodeMessage &message) override;
void requestDiagnostics(const ClangBackEnd::RequestDiagnosticsMessage &message) override; void requestDiagnostics(const ClangBackEnd::RequestDiagnosticsMessage &message) override;
@@ -232,6 +236,18 @@ void IpcSender::unregisterProjectPartsForEditor(const UnregisterProjectPartsForE
m_connection.serverProxy().unregisterProjectPartsForEditor(message); m_connection.serverProxy().unregisterProjectPartsForEditor(message);
} }
void IpcSender::registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message)
{
QTC_CHECK(m_connection.isConnected());
m_connection.serverProxy().registerUnsavedFilesForEditor(message);
}
void IpcSender::unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message)
{
QTC_CHECK(m_connection.isConnected());
m_connection.serverProxy().unregisterUnsavedFilesForEditor(message);
}
void IpcSender::completeCode(const CompleteCodeMessage &message) void IpcSender::completeCode(const CompleteCodeMessage &message)
{ {
QTC_CHECK(m_connection.isConnected()); QTC_CHECK(m_connection.isConnected());
@@ -306,7 +322,7 @@ void IpcCommunicator::registerCurrentUnsavedFiles()
const auto cppEditorDocuments = CppModelManager::instance()->cppEditorDocuments(); const auto cppEditorDocuments = CppModelManager::instance()->cppEditorDocuments();
foreach (const CppEditorDocumentHandle *cppEditorDocument, cppEditorDocuments) { foreach (const CppEditorDocumentHandle *cppEditorDocument, cppEditorDocuments) {
if (cppEditorDocument->processor()->baseTextDocument()->isModified()) if (cppEditorDocument->processor()->baseTextDocument()->isModified())
updateUnsavedFileFromCppEditorDocument(cppEditorDocument->filePath()); updateTranslationUnitFromCppEditorDocument(cppEditorDocument->filePath());
} }
} }
@@ -353,6 +369,13 @@ void IpcCommunicator::registerProjectsParts(const QList<CppTools::ProjectPart::P
registerProjectPartsForEditor(projectPartContainers); registerProjectPartsForEditor(projectPartContainers);
} }
void IpcCommunicator::updateTranslationUnitFromCppEditorDocument(const QString &filePath)
{
const auto document = CppTools::CppModelManager::instance()->cppEditorDocument(filePath);
updateTranslationUnit(filePath, document->contents(), document->revision());
}
void IpcCommunicator::updateUnsavedFileFromCppEditorDocument(const QString &filePath) void IpcCommunicator::updateUnsavedFileFromCppEditorDocument(const QString &filePath)
{ {
const auto document = CppTools::CppModelManager::instance()->cppEditorDocument(filePath); const auto document = CppTools::CppModelManager::instance()->cppEditorDocument(filePath);
@@ -360,7 +383,7 @@ void IpcCommunicator::updateUnsavedFileFromCppEditorDocument(const QString &file
updateUnsavedFile(filePath, document->contents(), document->revision()); updateUnsavedFile(filePath, document->contents(), document->revision());
} }
void IpcCommunicator::updateUnsavedFile(const QString &filePath, void IpcCommunicator::updateTranslationUnit(const QString &filePath,
const QByteArray &contents, const QByteArray &contents,
uint documentRevision) uint documentRevision)
{ {
@@ -368,25 +391,44 @@ void IpcCommunicator::updateUnsavedFile(const QString &filePath,
const bool hasUnsavedContent = true; const bool hasUnsavedContent = true;
// TODO: Send new only if changed // TODO: Send new only if changed
registerFilesForEditor({{filePath, registerTranslationUnitsForEditor({{filePath,
projectPartId, projectPartId,
Utf8String::fromByteArray(contents), Utf8String::fromByteArray(contents),
hasUnsavedContent, hasUnsavedContent,
documentRevision}}); 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::fromByteArray(contents),
hasUnsavedContent,
documentRevision}});
} }
void IpcCommunicator::requestDiagnostics(const FileContainer &fileContainer) void IpcCommunicator::requestDiagnostics(const FileContainer &fileContainer)
{ {
registerFilesForEditor({fileContainer}); registerTranslationUnitsForEditor({fileContainer});
m_ipcSender->requestDiagnostics({fileContainer}); m_ipcSender->requestDiagnostics({fileContainer});
} }
void IpcCommunicator::updateUnsavedFileIfNotCurrentDocument(Core::IDocument *document) void IpcCommunicator::updateTranslationUnitIfNotCurrentDocument(Core::IDocument *document)
{
QTC_ASSERT(document, return);
if (Core::EditorManager::currentDocument() != document)
updateTranslationUnitFromCppEditorDocument(document->filePath().toString());
}
void IpcCommunicator::updateUnsavedFile(Core::IDocument *document)
{ {
QTC_ASSERT(document, return); QTC_ASSERT(document, return);
if (Core::EditorManager::currentDocument() != document) updateUnsavedFileFromCppEditorDocument(document->filePath().toString());
updateUnsavedFileFromCppEditorDocument(document->filePath().toString());
} }
void IpcCommunicator::onBackendRestarted() void IpcCommunicator::onBackendRestarted()
@@ -431,7 +473,7 @@ void IpcCommunicator::killBackendProcess()
m_connection.processForTestOnly()->kill(); m_connection.processForTestOnly()->kill();
} }
void IpcCommunicator::registerFilesForEditor(const FileContainers &fileContainers) void IpcCommunicator::registerTranslationUnitsForEditor(const FileContainers &fileContainers)
{ {
if (m_sendMode == IgnoreSendRequests) if (m_sendMode == IgnoreSendRequests)
return; return;
@@ -441,7 +483,7 @@ void IpcCommunicator::registerFilesForEditor(const FileContainers &fileContainer
m_ipcSender->registerTranslationUnitsForEditor(message); m_ipcSender->registerTranslationUnitsForEditor(message);
} }
void IpcCommunicator::unregisterFilesForEditor(const FileContainers &fileContainers) void IpcCommunicator::unregisterTranslationUnitsForEditor(const FileContainers &fileContainers)
{ {
if (m_sendMode == IgnoreSendRequests) if (m_sendMode == IgnoreSendRequests)
return; return;
@@ -472,6 +514,26 @@ void IpcCommunicator::unregisterProjectPartsForEditor(const QStringList &project
m_ipcSender->unregisterProjectPartsForEditor(message); m_ipcSender->unregisterProjectPartsForEditor(message);
} }
void IpcCommunicator::registerUnsavedFilesForEditor(const IpcCommunicator::FileContainers &fileContainers)
{
if (m_sendMode == IgnoreSendRequests)
return;
const RegisterUnsavedFilesForEditorMessage message(fileContainers);
qCDebug(log) << ">>>" << message;
m_ipcSender->registerUnsavedFilesForEditor(message);
}
void IpcCommunicator::unregisterUnsavedFilesForEditor(const IpcCommunicator::FileContainers &fileContainers)
{
if (m_sendMode == IgnoreSendRequests)
return;
const UnregisterUnsavedFilesForEditorMessage message(fileContainers);
qCDebug(log) << ">>>" << message;
m_ipcSender->unregisterUnsavedFilesForEditor(message);
}
void IpcCommunicator::completeCode(ClangCompletionAssistProcessor *assistProcessor, void IpcCommunicator::completeCode(ClangCompletionAssistProcessor *assistProcessor,
const QString &filePath, const QString &filePath,
quint32 line, quint32 line,
@@ -99,6 +99,8 @@ public:
virtual void unregisterTranslationUnitsForEditor(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &message) = 0; virtual void unregisterTranslationUnitsForEditor(const ClangBackEnd::UnregisterTranslationUnitsForEditorMessage &message) = 0;
virtual void registerProjectPartsForEditor(const ClangBackEnd::RegisterProjectPartsForEditorMessage &message) = 0; virtual void registerProjectPartsForEditor(const ClangBackEnd::RegisterProjectPartsForEditorMessage &message) = 0;
virtual void unregisterProjectPartsForEditor(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &message) = 0; virtual void unregisterProjectPartsForEditor(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &message) = 0;
virtual void registerUnsavedFilesForEditor(const ClangBackEnd::RegisterUnsavedFilesForEditorMessage &message) = 0;
virtual void unregisterUnsavedFilesForEditor(const ClangBackEnd::UnregisterUnsavedFilesForEditorMessage &message) = 0;
virtual void completeCode(const ClangBackEnd::CompleteCodeMessage &message) = 0; virtual void completeCode(const ClangBackEnd::CompleteCodeMessage &message) = 0;
virtual void requestDiagnostics(const ClangBackEnd::RequestDiagnosticsMessage &message) = 0; virtual void requestDiagnostics(const ClangBackEnd::RequestDiagnosticsMessage &message) = 0;
}; };
@@ -115,10 +117,12 @@ public:
public: public:
IpcCommunicator(); IpcCommunicator();
void registerFilesForEditor(const FileContainers &fileContainers); void registerTranslationUnitsForEditor(const FileContainers &fileContainers);
void unregisterFilesForEditor(const FileContainers &fileContainers); void unregisterTranslationUnitsForEditor(const FileContainers &fileContainers);
void registerProjectPartsForEditor(const ProjectPartContainers &projectPartContainers); void registerProjectPartsForEditor(const ProjectPartContainers &projectPartContainers);
void unregisterProjectPartsForEditor(const QStringList &projectPartIds); void unregisterProjectPartsForEditor(const QStringList &projectPartIds);
void registerUnsavedFilesForEditor(const FileContainers &fileContainers);
void unregisterUnsavedFilesForEditor(const FileContainers &fileContainers);
void completeCode(ClangCompletionAssistProcessor *assistProcessor, const QString &filePath, void completeCode(ClangCompletionAssistProcessor *assistProcessor, const QString &filePath,
quint32 line, quint32 line,
quint32 column, quint32 column,
@@ -126,8 +130,11 @@ public:
void registerProjectsParts(const QList<CppTools::ProjectPart::Ptr> projectParts); void registerProjectsParts(const QList<CppTools::ProjectPart::Ptr> projectParts);
void updateUnsavedFileIfNotCurrentDocument(Core::IDocument *document); void updateTranslationUnitIfNotCurrentDocument(Core::IDocument *document);
void updateUnsavedFile(Core::IDocument *document);
void updateTranslationUnitFromCppEditorDocument(const QString &filePath);
void updateUnsavedFileFromCppEditorDocument(const QString &filePath); void updateUnsavedFileFromCppEditorDocument(const QString &filePath);
void updateTranslationUnit(const QString &filePath, const QByteArray &contents, uint documentRevision);
void updateUnsavedFile(const QString &filePath, const QByteArray &contents, uint documentRevision); void updateUnsavedFile(const QString &filePath, const QByteArray &contents, uint documentRevision);
void requestDiagnostics(const ClangBackEnd::FileContainer &fileContainer); void requestDiagnostics(const ClangBackEnd::FileContainer &fileContainer);
@@ -674,11 +674,11 @@ void ClangCompletionAssistProcessor::sendFileContent(const QString &projectPartI
const UnsavedFileContentInfo info = unsavedFileContent(customFileContent); const UnsavedFileContentInfo info = unsavedFileContent(customFileContent);
IpcCommunicator &ipcCommunicator = m_interface->ipcCommunicator(); IpcCommunicator &ipcCommunicator = m_interface->ipcCommunicator();
ipcCommunicator.registerFilesForEditor({{m_interface->fileName(), ipcCommunicator.registerTranslationUnitsForEditor({{m_interface->fileName(),
projectPartId, projectPartId,
Utf8String::fromByteArray(info.unsavedContent), Utf8String::fromByteArray(info.unsavedContent),
info.isDocumentModified, info.isDocumentModified,
uint(m_interface->textDocument()->revision())}}); uint(m_interface->textDocument()->revision())}});
} }
void ClangCompletionAssistProcessor::sendCompletionRequest(int position, void ClangCompletionAssistProcessor::sendCompletionRequest(int position,
@@ -109,7 +109,7 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor()
if (m_projectPart) { if (m_projectPart) {
QTC_ASSERT(m_modelManagerSupport, return); QTC_ASSERT(m_modelManagerSupport, return);
m_modelManagerSupport->ipcCommunicator().unregisterFilesForEditor( m_modelManagerSupport->ipcCommunicator().unregisterTranslationUnitsForEditor(
{ClangBackEnd::FileContainer(filePath(), m_projectPart->id())}); {ClangBackEnd::FileContainer(filePath(), m_projectPart->id())});
} }
} }
@@ -228,18 +228,18 @@ void ClangEditorDocumentProcessor::updateTranslationUnitForEditor(CppTools::Proj
auto container1 = ClangBackEnd::FileContainer(filePath(), auto container1 = ClangBackEnd::FileContainer(filePath(),
m_projectPart->id(), m_projectPart->id(),
revision()); revision());
ipcCommunicator.unregisterFilesForEditor({container1}); ipcCommunicator.unregisterTranslationUnitsForEditor({container1});
auto container2 = ClangBackEnd::FileContainer(filePath(), auto container2 = ClangBackEnd::FileContainer(filePath(),
projectPart.id(), projectPart.id(),
revision()); revision());
ipcCommunicator.registerFilesForEditor({container2}); ipcCommunicator.registerTranslationUnitsForEditor({container2});
} }
} else { } else {
auto container = ClangBackEnd::FileContainer(filePath(), auto container = ClangBackEnd::FileContainer(filePath(),
projectPart.id(), projectPart.id(),
revision()); revision());
ipcCommunicator.registerFilesForEditor({container}); ipcCommunicator.registerTranslationUnitsForEditor({container});
} }
} }
@@ -100,7 +100,7 @@ void ModelManagerSupportClang::onCurrentEditorChanged(Core::IEditor *newCurrent)
// If we switch away from a cpp editor, update the backend about // If we switch away from a cpp editor, update the backend about
// the document's unsaved content. // the document's unsaved content.
if (m_previousCppEditor && m_previousCppEditor->document()->isModified()) { if (m_previousCppEditor && m_previousCppEditor->document()->isModified()) {
m_ipcCommunicator.updateUnsavedFileFromCppEditorDocument( m_ipcCommunicator.updateTranslationUnitFromCppEditorDocument(
m_previousCppEditor->document()->filePath().toString()); m_previousCppEditor->document()->filePath().toString());
} }
@@ -111,6 +111,32 @@ void ModelManagerSupportClang::onCurrentEditorChanged(Core::IEditor *newCurrent)
m_previousCppEditor.clear(); m_previousCppEditor.clear();
} }
void ModelManagerSupportClang::connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument)
{
// Handle externally changed documents
connect(textDocument, &Core::IDocument::reloadFinished,
this, &ModelManagerSupportClang::onCppDocumentReloadFinishedOnTranslationUnit,
Qt::UniqueConnection);
// Handle changes from e.g. refactoring actions
connect(textDocument, &TextEditor::TextDocument::contentsChanged,
this, &ModelManagerSupportClang::onCppDocumentContentsChangedOnTranslationUnit,
Qt::UniqueConnection);
}
void ModelManagerSupportClang::connectTextDocumentToUnsavedFiles(TextEditor::TextDocument *textDocument)
{
// Handle externally changed documents
connect(textDocument, &Core::IDocument::reloadFinished,
this, &ModelManagerSupportClang::onCppDocumentReloadFinishedOnUnsavedFile,
Qt::UniqueConnection);
// Handle changes from e.g. refactoring actions
connect(textDocument, &TextEditor::TextDocument::contentsChanged,
this, &ModelManagerSupportClang::onCppDocumentContentsChangedOnUnsavedFile,
Qt::UniqueConnection);
}
void ModelManagerSupportClang::onEditorOpened(Core::IEditor *editor) void ModelManagerSupportClang::onEditorOpened(Core::IEditor *editor)
{ {
QTC_ASSERT(editor, return); QTC_ASSERT(editor, return);
@@ -119,33 +145,41 @@ void ModelManagerSupportClang::onEditorOpened(Core::IEditor *editor)
TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(document); TextEditor::TextDocument *textDocument = qobject_cast<TextEditor::TextDocument *>(document);
if (textDocument && cppModelManager()->isCppEditor(editor)) { if (textDocument && cppModelManager()->isCppEditor(editor)) {
// Handle externally changed documents if (cppModelManager()->isManagedByModelManagerSupport(textDocument, QLatin1String(Constants::CLANG_MODELMANAGERSUPPORT_ID)))
connect(textDocument, &Core::IDocument::reloadFinished, connectTextDocumentToTranslationUnit(textDocument);
this, &ModelManagerSupportClang::onCppDocumentReloadFinished, else
Qt::UniqueConnection); connectTextDocumentToUnsavedFiles(textDocument);
// Handle changes from e.g. refactoring actions
connect(textDocument, &TextEditor::TextDocument::contentsChanged,
this, &ModelManagerSupportClang::onCppDocumentContentsChanged,
Qt::UniqueConnection);
// TODO: Ensure that not fully loaded documents are updated? // TODO: Ensure that not fully loaded documents are updated?
} }
} }
void ModelManagerSupportClang::onCppDocumentReloadFinished(bool success) void ModelManagerSupportClang::onCppDocumentReloadFinishedOnTranslationUnit(bool success)
{ {
if (!success) if (success) {
return; Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
m_ipcCommunicator.updateTranslationUnitIfNotCurrentDocument(document);
Core::IDocument *document = qobject_cast<Core::IDocument *>(sender()); }
m_ipcCommunicator.updateUnsavedFileIfNotCurrentDocument(document);
} }
void ModelManagerSupportClang::onCppDocumentContentsChanged() void ModelManagerSupportClang::onCppDocumentContentsChangedOnTranslationUnit()
{ {
Core::IDocument *document = qobject_cast<Core::IDocument *>(sender()); Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
m_ipcCommunicator.updateUnsavedFileIfNotCurrentDocument(document); m_ipcCommunicator.updateTranslationUnitIfNotCurrentDocument(document);
}
void ModelManagerSupportClang::onCppDocumentReloadFinishedOnUnsavedFile(bool success)
{
if (success) {
Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
m_ipcCommunicator.updateUnsavedFile(document);
}
}
void ModelManagerSupportClang::onCppDocumentContentsChangedOnUnsavedFile()
{
Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
m_ipcCommunicator.updateUnsavedFile(document);
} }
void ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated(const QString &filePath, void ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated(const QString &filePath,
@@ -160,8 +194,7 @@ void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &fil
QTC_ASSERT(!filePath.isEmpty(), return); QTC_ASSERT(!filePath.isEmpty(), return);
if (!cppModelManager()->cppEditorDocument(filePath)) { if (!cppModelManager()->cppEditorDocument(filePath)) {
const QString projectPartId = Utils::projectPartIdForFile(filePath); const QString projectPartId = Utils::projectPartIdForFile(filePath);
m_ipcCommunicator.unregisterFilesForEditor( m_ipcCommunicator.unregisterUnsavedFilesForEditor({{filePath, projectPartId}});
{ClangBackEnd::FileContainer(filePath, projectPartId)});
} }
} }
@@ -66,8 +66,10 @@ public:
private: private:
void onEditorOpened(Core::IEditor *editor); void onEditorOpened(Core::IEditor *editor);
void onCurrentEditorChanged(Core::IEditor *newCurrent); void onCurrentEditorChanged(Core::IEditor *newCurrent);
void onCppDocumentReloadFinished(bool success); void onCppDocumentReloadFinishedOnTranslationUnit(bool success);
void onCppDocumentContentsChanged(); void onCppDocumentContentsChangedOnTranslationUnit();
void onCppDocumentReloadFinishedOnUnsavedFile(bool success);
void onCppDocumentContentsChangedOnUnsavedFile();
void onAbstractEditorSupportContentsUpdated(const QString &filePath, const QByteArray &content); void onAbstractEditorSupportContentsUpdated(const QString &filePath, const QByteArray &content);
void onAbstractEditorSupportRemoved(const QString &filePath); void onAbstractEditorSupportRemoved(const QString &filePath);
@@ -75,6 +77,10 @@ private:
void onProjectPartsUpdated(ProjectExplorer::Project *project); void onProjectPartsUpdated(ProjectExplorer::Project *project);
void onProjectPartsRemoved(const QStringList &projectPartIds); void onProjectPartsRemoved(const QStringList &projectPartIds);
void connectTextDocumentToTranslationUnit(TextEditor::TextDocument *textDocument);
void connectTextDocumentToUnsavedFiles(TextEditor::TextDocument *textDocument);
private:
IpcCommunicator m_ipcCommunicator; IpcCommunicator m_ipcCommunicator;
ClangCompletionAssistProvider m_completionAssistProvider; ClangCompletionAssistProvider m_completionAssistProvider;
QPointer<Core::IEditor> m_previousCppEditor; QPointer<Core::IEditor> m_previousCppEditor;
@@ -60,6 +60,7 @@
#include <clangbackendipc/cmbregistertranslationunitsforeditormessage.h> #include <clangbackendipc/cmbregistertranslationunitsforeditormessage.h>
#include <clangbackendipc/cmbunregisterprojectsforeditormessage.h> #include <clangbackendipc/cmbunregisterprojectsforeditormessage.h>
#include <clangbackendipc/cmbunregistertranslationunitsforeditormessage.h> #include <clangbackendipc/cmbunregistertranslationunitsforeditormessage.h>
#include <clangbackendipc/registerunsavedfilesforeditormessage.h>
#include <utils/changeset.h> #include <utils/changeset.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
@@ -347,6 +348,23 @@ QString toString(const UnregisterProjectPartsForEditorMessage &message)
return out; return out;
} }
QString toString(const RegisterUnsavedFilesForEditorMessage &message)
{
QString out;
QTextStream ts(&out);
ts << "RegisterUnsavedFilesForEditorMessage\n"
<< toString(message.fileContainers());
return out;
return QLatin1String("RegisterUnsavedFilesForEditorMessage\n");
}
QString toString(const UnregisterUnsavedFilesForEditorMessage &)
{
return QLatin1String("UnregisterUnsavedFilesForEditorMessage\n");
}
QString toString(const CompleteCodeMessage &) QString toString(const CompleteCodeMessage &)
{ {
return QLatin1String("CompleteCodeMessage\n"); return QLatin1String("CompleteCodeMessage\n");
@@ -375,6 +393,12 @@ public:
void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override
{ senderLog.append(toString(message)); } { senderLog.append(toString(message)); }
void registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message) override
{ senderLog.append(toString(message)); }
void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override
{ senderLog.append(toString(message)); }
void completeCode(const CompleteCodeMessage &message) override void completeCode(const CompleteCodeMessage &message) override
{ senderLog.append(toString(message)); } { senderLog.append(toString(message)); }
@@ -48,9 +48,11 @@
#include <cmbunregisterprojectsforeditormessage.h> #include <cmbunregisterprojectsforeditormessage.h>
#include <cmbunregistertranslationunitsforeditormessage.h> #include <cmbunregistertranslationunitsforeditormessage.h>
#include <diagnosticschangedmessage.h> #include <diagnosticschangedmessage.h>
#include <registerunsavedfilesforeditormessage.h>
#include <requestdiagnosticsmessage.h> #include <requestdiagnosticsmessage.h>
#include <projectpartsdonotexistmessage.h> #include <projectpartsdonotexistmessage.h>
#include <translationunitdoesnotexistmessage.h> #include <translationunitdoesnotexistmessage.h>
#include <unregisterunsavedfilesforeditormessage.h>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
@@ -138,6 +140,37 @@ void ClangIpcServer::unregisterProjectPartsForEditor(const UnregisterProjectPart
} }
} }
void ClangIpcServer::registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message)
{
TIME_SCOPE_DURATION("ClangIpcServer::registerUnsavedFilesForEditor");
try {
unsavedFiles.createOrUpdate(message.fileContainers());
translationUnits.updateTranslationUnitsWithChangedDependencies(message.fileContainers());
sendDiagnosticsTimer.start();
} catch (const ProjectPartDoNotExistException &exception) {
client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds()));
} catch (const std::exception &exception) {
qWarning() << "Error in ClangIpcServer::registerUnsavedFilesForEditor:" << exception.what();
}
}
void ClangIpcServer::unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message)
{
TIME_SCOPE_DURATION("ClangIpcServer::unregisterUnsavedFilesForEditor");
try {
unsavedFiles.remove(message.fileContainers());
translationUnits.updateTranslationUnitsWithChangedDependencies(message.fileContainers());
} catch (const TranslationUnitDoesNotExistException &exception) {
client()->translationUnitDoesNotExist(TranslationUnitDoesNotExistMessage(exception.fileContainer()));
} catch (const ProjectPartDoNotExistException &exception) {
client()->projectPartsDoNotExist(ProjectPartsDoNotExistMessage(exception.projectPartIds()));
} catch (const std::exception &exception) {
qWarning() << "Error in ClangIpcServer::unregisterUnsavedFilesForEditor:" << exception.what();
}
}
void ClangIpcServer::completeCode(const ClangBackEnd::CompleteCodeMessage &message) void ClangIpcServer::completeCode(const ClangBackEnd::CompleteCodeMessage &message)
{ {
TIME_SCOPE_DURATION("ClangIpcServer::completeCode"); TIME_SCOPE_DURATION("ClangIpcServer::completeCode");
@@ -56,6 +56,8 @@ public:
void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override; void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override;
void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) override; void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) override;
void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override; void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override;
void registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message) override;
void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override;
void completeCode(const CompleteCodeMessage &message) override; void completeCode(const CompleteCodeMessage &message) override;
void requestDiagnostics(const RequestDiagnosticsMessage &message) override; void requestDiagnostics(const RequestDiagnosticsMessage &message) override;
+12
View File
@@ -39,7 +39,9 @@
#include "cmbunregisterprojectsforeditormessage.h" #include "cmbunregisterprojectsforeditormessage.h"
#include "cmbunregistertranslationunitsforeditormessage.h" #include "cmbunregistertranslationunitsforeditormessage.h"
#include "connectionserver.h" #include "connectionserver.h"
#include "registerunsavedfilesforeditormessage.h"
#include "requestdiagnosticsmessage.h" #include "requestdiagnosticsmessage.h"
#include "unregisterunsavedfilesforeditormessage.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
@@ -78,6 +80,16 @@ void EchoIpcServer::unregisterProjectPartsForEditor(const UnregisterProjectParts
echoMessage(QVariant::fromValue(message)); echoMessage(QVariant::fromValue(message));
} }
void EchoIpcServer::registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message)
{
echoMessage(QVariant::fromValue(message));
}
void EchoIpcServer::unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message)
{
echoMessage(QVariant::fromValue(message));
}
void EchoIpcServer::completeCode(const CompleteCodeMessage &message) void EchoIpcServer::completeCode(const CompleteCodeMessage &message)
{ {
echoMessage(QVariant::fromValue(message)); echoMessage(QVariant::fromValue(message));
+2
View File
@@ -44,6 +44,8 @@ public:
void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override; void unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message) override;
void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) override; void registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message) override;
void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override; void unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message) override;
void registerUnsavedFilesForEditor(const RegisterUnsavedFilesForEditorMessage &message) override;
void unregisterUnsavedFilesForEditor(const UnregisterUnsavedFilesForEditorMessage &message) override;
void completeCode(const CompleteCodeMessage &message) override; void completeCode(const CompleteCodeMessage &message) override;
void requestDiagnostics(const RequestDiagnosticsMessage &message) override; void requestDiagnostics(const RequestDiagnosticsMessage &message) override;
@@ -38,18 +38,20 @@
#include <cmbalivemessage.h> #include <cmbalivemessage.h>
#include <cmbcodecompletedmessage.h> #include <cmbcodecompletedmessage.h>
#include <cmbmessages.h>
#include <cmbcompletecodemessage.h> #include <cmbcompletecodemessage.h>
#include <cmbechomessage.h> #include <cmbechomessage.h>
#include <cmbendmessage.h> #include <cmbendmessage.h>
#include <cmbmessages.h>
#include <cmbregisterprojectsforeditormessage.h> #include <cmbregisterprojectsforeditormessage.h>
#include <cmbregistertranslationunitsforeditormessage.h> #include <cmbregistertranslationunitsforeditormessage.h>
#include <cmbunregisterprojectsforeditormessage.h> #include <cmbunregisterprojectsforeditormessage.h>
#include <cmbunregistertranslationunitsforeditormessage.h> #include <cmbunregistertranslationunitsforeditormessage.h>
#include <diagnosticschangedmessage.h> #include <diagnosticschangedmessage.h>
#include <requestdiagnosticsmessage.h>
#include <readmessageblock.h> #include <readmessageblock.h>
#include <registerunsavedfilesforeditormessage.h>
#include <requestdiagnosticsmessage.h>
#include <translationunitdoesnotexistmessage.h> #include <translationunitdoesnotexistmessage.h>
#include <unregisterunsavedfilesforeditormessage.h>
#include <writemessageblock.h> #include <writemessageblock.h>
#include <QBuffer> #include <QBuffer>
@@ -83,6 +85,12 @@ protected:
void scheduleServerMessages(); void scheduleServerMessages();
void scheduleClientMessages(); void scheduleClientMessages();
protected:
ClangBackEnd::FileContainer fileContainer{Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"),
Utf8StringLiteral("projectPartId"),
Utf8StringLiteral("unsaved content"),
true,
1};
QBuffer buffer; QBuffer buffer;
MockIpcClient mockIpcClient; MockIpcClient mockIpcClient;
MockIpcServer mockIpcServer; MockIpcServer mockIpcServer;
@@ -111,8 +119,6 @@ TEST_F(ClientServerInProcess, SendAliveMessage)
TEST_F(ClientServerInProcess, SendRegisterTranslationUnitForEditorMessage) TEST_F(ClientServerInProcess, SendRegisterTranslationUnitForEditorMessage)
{ {
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"),
Utf8StringLiteral("projectId"));
ClangBackEnd::RegisterTranslationUnitForEditorMessage message({fileContainer}); ClangBackEnd::RegisterTranslationUnitForEditorMessage message({fileContainer});
EXPECT_CALL(mockIpcServer, registerTranslationUnitsForEditor(message)) EXPECT_CALL(mockIpcServer, registerTranslationUnitsForEditor(message))
@@ -124,7 +130,6 @@ TEST_F(ClientServerInProcess, SendRegisterTranslationUnitForEditorMessage)
TEST_F(ClientServerInProcess, SendUnregisterTranslationUnitsForEditorMessage) TEST_F(ClientServerInProcess, SendUnregisterTranslationUnitsForEditorMessage)
{ {
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("projectId"));
ClangBackEnd::UnregisterTranslationUnitsForEditorMessage message({fileContainer}); ClangBackEnd::UnregisterTranslationUnitsForEditorMessage message({fileContainer});
EXPECT_CALL(mockIpcServer, unregisterTranslationUnitsForEditor(message)) EXPECT_CALL(mockIpcServer, unregisterTranslationUnitsForEditor(message))
@@ -134,6 +139,28 @@ TEST_F(ClientServerInProcess, SendUnregisterTranslationUnitsForEditorMessage)
scheduleServerMessages(); scheduleServerMessages();
} }
TEST_F(ClientServerInProcess, SendRegisterUnsavedFilesForEditorMessage)
{
ClangBackEnd::RegisterUnsavedFilesForEditorMessage message({fileContainer});
EXPECT_CALL(mockIpcServer, registerUnsavedFilesForEditor(message))
.Times(1);
serverProxy.registerUnsavedFilesForEditor(message);
scheduleServerMessages();
}
TEST_F(ClientServerInProcess, SendUnregisterUnsavedFilesForEditorMessage)
{
ClangBackEnd::UnregisterUnsavedFilesForEditorMessage message({fileContainer});
EXPECT_CALL(mockIpcServer, unregisterUnsavedFilesForEditor(message))
.Times(1);
serverProxy.unregisterUnsavedFilesForEditor(message);
scheduleServerMessages();
}
TEST_F(ClientServerInProcess, SendCompleteCodeMessage) TEST_F(ClientServerInProcess, SendCompleteCodeMessage)
{ {
ClangBackEnd::CompleteCodeMessage message(Utf8StringLiteral("foo.cpp"), 24, 33, Utf8StringLiteral("do what I want")); ClangBackEnd::CompleteCodeMessage message(Utf8StringLiteral("foo.cpp"), 24, 33, Utf8StringLiteral("do what I want"));
@@ -195,8 +222,6 @@ TEST_F(ClientServerInProcess, SendUnregisterProjectPartsForEditorMessage)
TEST_F(ClientServerInProcess, SendTranslationUnitDoesNotExistMessage) TEST_F(ClientServerInProcess, SendTranslationUnitDoesNotExistMessage)
{ {
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"),
Utf8StringLiteral("projectId"));
ClangBackEnd::TranslationUnitDoesNotExistMessage message(fileContainer); ClangBackEnd::TranslationUnitDoesNotExistMessage message(fileContainer);
EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(message)) EXPECT_CALL(mockIpcClient, translationUnitDoesNotExist(message))
@@ -220,8 +245,6 @@ TEST_F(ClientServerInProcess, SendProjectPartDoesNotExistMessage)
TEST_F(ClientServerInProcess, SendDiagnosticsChangedMessage) TEST_F(ClientServerInProcess, SendDiagnosticsChangedMessage)
{ {
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"),
Utf8StringLiteral("projectId"));
ClangBackEnd::DiagnosticContainer container(Utf8StringLiteral("don't do that"), ClangBackEnd::DiagnosticContainer container(Utf8StringLiteral("don't do that"),
Utf8StringLiteral("warning"), Utf8StringLiteral("warning"),
{Utf8StringLiteral("-Wpadded"), Utf8StringLiteral("-Wno-padded")}, {Utf8StringLiteral("-Wpadded"), Utf8StringLiteral("-Wno-padded")},
+4
View File
@@ -50,6 +50,10 @@ public:
void(const ClangBackEnd::RegisterProjectPartsForEditorMessage &message)); void(const ClangBackEnd::RegisterProjectPartsForEditorMessage &message));
MOCK_METHOD1(unregisterProjectPartsForEditor, MOCK_METHOD1(unregisterProjectPartsForEditor,
void(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &message)); void(const ClangBackEnd::UnregisterProjectPartsForEditorMessage &message));
MOCK_METHOD1(registerUnsavedFilesForEditor,
void(const ClangBackEnd::RegisterUnsavedFilesForEditorMessage &message));
MOCK_METHOD1(unregisterUnsavedFilesForEditor,
void(const ClangBackEnd::UnregisterUnsavedFilesForEditorMessage &message));
MOCK_METHOD1(completeCode, MOCK_METHOD1(completeCode,
void(const ClangBackEnd::CompleteCodeMessage &message)); void(const ClangBackEnd::CompleteCodeMessage &message));
MOCK_METHOD1(requestDiagnostics, MOCK_METHOD1(requestDiagnostics,
@@ -40,6 +40,8 @@
#include <requestdiagnosticsmessage.h> #include <requestdiagnosticsmessage.h>
#include <readmessageblock.h> #include <readmessageblock.h>
#include <sourcelocation.h> #include <sourcelocation.h>
#include <registerunsavedfilesforeditormessage.h>
#include <unregisterunsavedfilesforeditormessage.h>
#include <writemessageblock.h> #include <writemessageblock.h>
#include <QBuffer> #include <QBuffer>
@@ -73,6 +75,11 @@ protected:
void readPartialMessage(); void readPartialMessage();
protected: protected:
ClangBackEnd::FileContainer fileContainer{Utf8StringLiteral("foo.cpp"),
Utf8StringLiteral("projectPartId"),
Utf8StringLiteral("unsaved content"),
true,
1};
QBuffer buffer; QBuffer buffer;
ClangBackEnd::WriteMessageBlock writeMessageBlock; ClangBackEnd::WriteMessageBlock writeMessageBlock;
ClangBackEnd::ReadMessageBlock readMessageBlock; ClangBackEnd::ReadMessageBlock readMessageBlock;
@@ -141,16 +148,11 @@ TEST_F(ReadAndWriteMessageBlock, CompareAliveMessage)
TEST_F(ReadAndWriteMessageBlock, CompareRegisterTranslationUnitForEditorMessage) TEST_F(ReadAndWriteMessageBlock, CompareRegisterTranslationUnitForEditorMessage)
{ {
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("pathToProject.pro")); CompareMessage(ClangBackEnd::RegisterTranslationUnitForEditorMessage({fileContainer}));
QVector<ClangBackEnd::FileContainer> fileContainers({fileContainer});
CompareMessage(ClangBackEnd::RegisterTranslationUnitForEditorMessage(fileContainers));
} }
TEST_F(ReadAndWriteMessageBlock, CompareUnregisterFileForEditorMessage) TEST_F(ReadAndWriteMessageBlock, CompareUnregisterFileForEditorMessage)
{ {
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("pathToProject.pro"));
CompareMessage(ClangBackEnd::UnregisterTranslationUnitsForEditorMessage({fileContainer})); CompareMessage(ClangBackEnd::UnregisterTranslationUnitsForEditorMessage({fileContainer}));
} }
@@ -168,8 +170,6 @@ TEST_F(ReadAndWriteMessageBlock, CompareCodeCompletedMessage)
TEST_F(ReadAndWriteMessageBlock, CompareDiagnosticsChangedMessage) TEST_F(ReadAndWriteMessageBlock, CompareDiagnosticsChangedMessage)
{ {
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"),
Utf8StringLiteral("projectId"));
ClangBackEnd::DiagnosticContainer container(Utf8StringLiteral("don't do that"), ClangBackEnd::DiagnosticContainer container(Utf8StringLiteral("don't do that"),
Utf8StringLiteral("warning"), Utf8StringLiteral("warning"),
{Utf8StringLiteral("-Wpadded"), Utf8StringLiteral("-Wno-padded")}, {Utf8StringLiteral("-Wpadded"), Utf8StringLiteral("-Wno-padded")},
@@ -183,10 +183,18 @@ TEST_F(ReadAndWriteMessageBlock, CompareDiagnosticsChangedMessage)
{container})); {container}));
} }
TEST_F(ReadAndWriteMessageBlock, RequestDiagnosticsMessage) TEST_F(ReadAndWriteMessageBlock, CompareRegisterUnsavedFilesForEditorMessage)
{ {
ClangBackEnd::FileContainer fileContainer(Utf8StringLiteral("foo.cpp"), Utf8StringLiteral("pathToProject.pro")); CompareMessage(ClangBackEnd::RegisterUnsavedFilesForEditorMessage({fileContainer}));
}
TEST_F(ReadAndWriteMessageBlock, CompareUnregisterUnsavedFilesForEditorMessage)
{
CompareMessage(ClangBackEnd::UnregisterUnsavedFilesForEditorMessage({fileContainer}));
}
TEST_F(ReadAndWriteMessageBlock, CompareRequestDiagnosticsMessage)
{
CompareMessage(ClangBackEnd::RequestDiagnosticsMessage(fileContainer)); CompareMessage(ClangBackEnd::RequestDiagnosticsMessage(fileContainer));
} }