Commit 7ce9ef9d authored by Marco Bubke's avatar Marco Bubke Committed by Nikolai Kosjar

Clang: Integrate highlighting results from backend

Change-Id: I2c3fb69aabfe075bde76d63eafc2ca370f17493c
Reviewed-by: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
parent eb245786
...@@ -42,10 +42,13 @@ SOURCES += $$PWD/ipcserverinterface.cpp \ ...@@ -42,10 +42,13 @@ SOURCES += $$PWD/ipcserverinterface.cpp \
$$PWD/sourcelocationcontainer.cpp \ $$PWD/sourcelocationcontainer.cpp \
$$PWD/fixitcontainer.cpp \ $$PWD/fixitcontainer.cpp \
$$PWD/requestdiagnosticsmessage.cpp \ $$PWD/requestdiagnosticsmessage.cpp \
$$PWD/requesthighlightingmessage.cpp \
$$PWD/registerunsavedfilesforeditormessage.cpp \ $$PWD/registerunsavedfilesforeditormessage.cpp \
$$PWD/unregisterunsavedfilesforeditormessage.cpp \ $$PWD/unregisterunsavedfilesforeditormessage.cpp \
$$PWD/updatetranslationunitsforeditormessage.cpp \ $$PWD/updatetranslationunitsforeditormessage.cpp \
$$PWD/updatevisibletranslationunitsmessage.cpp $$PWD/updatevisibletranslationunitsmessage.cpp \
$$PWD/highlightingchangedmessage.cpp \
$$PWD/highlightingmarkcontainer.cpp
HEADERS += \ HEADERS += \
$$PWD/ipcserverinterface.h \ $$PWD/ipcserverinterface.h \
...@@ -84,9 +87,12 @@ HEADERS += \ ...@@ -84,9 +87,12 @@ HEADERS += \
$$PWD/sourcelocationcontainer.h \ $$PWD/sourcelocationcontainer.h \
$$PWD/fixitcontainer.h \ $$PWD/fixitcontainer.h \
$$PWD/requestdiagnosticsmessage.h \ $$PWD/requestdiagnosticsmessage.h \
$$PWD/requesthighlightingmessage.h \
$$PWD/registerunsavedfilesforeditormessage.h \ $$PWD/registerunsavedfilesforeditormessage.h \
$$PWD/unregisterunsavedfilesforeditormessage.h \ $$PWD/unregisterunsavedfilesforeditormessage.h \
$$PWD/updatetranslationunitsforeditormessage.h \ $$PWD/updatetranslationunitsforeditormessage.h \
$$PWD/updatevisibletranslationunitsmessage.h $$PWD/updatevisibletranslationunitsmessage.h \
$$PWD/highlightingchangedmessage.h \
$$PWD/highlightingmarkcontainer.h
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
...@@ -43,6 +43,9 @@ ...@@ -43,6 +43,9 @@
#include "diagnosticschangedmessage.h" #include "diagnosticschangedmessage.h"
#include "registerunsavedfilesforeditormessage.h" #include "registerunsavedfilesforeditormessage.h"
#include "requestdiagnosticsmessage.h" #include "requestdiagnosticsmessage.h"
#include "requesthighlightingmessage.h"
#include "highlightingchangedmessage.h"
#include "highlightingmarkcontainer.h"
#include "projectpartsdonotexistmessage.h" #include "projectpartsdonotexistmessage.h"
#include "sourcelocationcontainer.h" #include "sourcelocationcontainer.h"
#include "sourcerangecontainer.h" #include "sourcerangecontainer.h"
...@@ -83,6 +86,9 @@ void Messages::registerMessages() ...@@ -83,6 +86,9 @@ void Messages::registerMessages()
registerMetaType<RequestDiagnosticsMessage>(); registerMetaType<RequestDiagnosticsMessage>();
registerMetaType<DiagnosticsChangedMessage>(); registerMetaType<DiagnosticsChangedMessage>();
registerMetaType<RequestHighlightingMessage>();
registerMetaType<HighlightingChangedMessage>();
registerMetaType<UpdateVisibleTranslationUnitsMessage>(); registerMetaType<UpdateVisibleTranslationUnitsMessage>();
registerMetaType<CompleteCodeMessage>(); registerMetaType<CompleteCodeMessage>();
...@@ -94,6 +100,7 @@ void Messages::registerMessages() ...@@ -94,6 +100,7 @@ void Messages::registerMessages()
// Containers // Containers
registerMetaType<DiagnosticContainer>(); registerMetaType<DiagnosticContainer>();
registerMetaType<HighlightingMarkContainer>();
registerMetaType<FileContainer>(); registerMetaType<FileContainer>();
registerMetaType<ProjectPartContainer>(); registerMetaType<ProjectPartContainer>();
registerMetaType<SourceLocationContainer>(); registerMetaType<SourceLocationContainer>();
......
/****************************************************************************
**
** 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 "highlightingchangedmessage.h"
#include "container_common.h"
#include <QDataStream>
#include <QDebug>
#include <ostream>
namespace ClangBackEnd {
HighlightingChangedMessage::HighlightingChangedMessage(const FileContainer &file,
const QVector<HighlightingMarkContainer> &highlightingMarks,
const QVector<SourceRangeContainer> &skippedPreprocessorRanges)
: file_(file),
highlightingMarks_(highlightingMarks),
skippedPreprocessorRanges_(skippedPreprocessorRanges)
{
}
const FileContainer &HighlightingChangedMessage::file() const
{
return file_;
}
const QVector<HighlightingMarkContainer> &HighlightingChangedMessage::highlightingMarks() const
{
return highlightingMarks_;
}
const QVector<SourceRangeContainer> &HighlightingChangedMessage::skippedPreprocessorRanges() const
{
return skippedPreprocessorRanges_;
}
QDataStream &operator<<(QDataStream &out, const HighlightingChangedMessage &message)
{
out << message.file_;
out << message.highlightingMarks_;
out << message.skippedPreprocessorRanges_;
return out;
}
QDataStream &operator>>(QDataStream &in, HighlightingChangedMessage &message)
{
in >> message.file_;
in >> message.highlightingMarks_;
in >> message.skippedPreprocessorRanges_;
return in;
}
bool operator==(const HighlightingChangedMessage &first, const HighlightingChangedMessage &second)
{
return first.file_ == second.file_
&& first.highlightingMarks_ == second.highlightingMarks_
&& first.skippedPreprocessorRanges_ == second.skippedPreprocessorRanges_;
}
bool operator<(const HighlightingChangedMessage &first, const HighlightingChangedMessage &second)
{
return first.file_ < second.file_
&& compareContainer(first.highlightingMarks_, second.highlightingMarks_)
&& compareContainer(first.skippedPreprocessorRanges_, second.skippedPreprocessorRanges_);
}
QDebug operator<<(QDebug debug, const HighlightingChangedMessage &message)
{
debug.nospace() << "HighlightingChangedMessage("
<< message.file_
<< ", " << message.highlightingMarks_.size()
<< ", " << message.skippedPreprocessorRanges_.size()
<< ")";
return debug;
}
void PrintTo(const HighlightingChangedMessage &message, ::std::ostream* os)
{
*os << "HighlightingChangedMessage(";
PrintTo(message.file(), os);
*os << "," << message.highlightingMarks().size();
*os << "," << message.skippedPreprocessorRanges().size();
*os << ")";
}
} // namespace ClangBackEnd
/****************************************************************************
**
** 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_HIGHLIGHTINGCHANGEDMESSAGE_H
#define CLANGBACKEND_HIGHLIGHTINGCHANGEDMESSAGE_H
#include "clangbackendipc_global.h"
#include "filecontainer.h"
#include "highlightingmarkcontainer.h"
#include "sourcerangecontainer.h"
#include <QVector>
namespace ClangBackEnd {
class CMBIPC_EXPORT HighlightingChangedMessage
{
friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const HighlightingChangedMessage &message);
friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, HighlightingChangedMessage &message);
friend CMBIPC_EXPORT bool operator==(const HighlightingChangedMessage &first, const HighlightingChangedMessage &second);
friend CMBIPC_EXPORT bool operator<(const HighlightingChangedMessage &first, const HighlightingChangedMessage &second);
friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const HighlightingChangedMessage &message);
friend void PrintTo(const HighlightingChangedMessage &message, ::std::ostream* os);
public:
HighlightingChangedMessage() = default;
HighlightingChangedMessage(const FileContainer &file,
const QVector<HighlightingMarkContainer> &highlightingMarks,
const QVector<SourceRangeContainer> &skippedPreprocessorRanges);
const FileContainer &file() const;
const QVector<HighlightingMarkContainer> &highlightingMarks() const;
const QVector<SourceRangeContainer> &skippedPreprocessorRanges() const;
private:
FileContainer file_;
QVector<HighlightingMarkContainer> highlightingMarks_;
QVector<SourceRangeContainer> skippedPreprocessorRanges_;
};
CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const HighlightingChangedMessage &message);
CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, HighlightingChangedMessage &message);
CMBIPC_EXPORT bool operator==(const HighlightingChangedMessage &first, const HighlightingChangedMessage &second);
CMBIPC_EXPORT bool operator<(const HighlightingChangedMessage &first, const HighlightingChangedMessage &second);
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const HighlightingChangedMessage &message);
void PrintTo(const HighlightingChangedMessage &message, ::std::ostream* os);
} // namespace ClangBackEnd
Q_DECLARE_METATYPE(ClangBackEnd::HighlightingChangedMessage)
#endif // CLANGBACKEND_HIGHLIGHTINGCHANGEDMESSAGE_H
/****************************************************************************
**
** 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 "highlightingmarkcontainer.h"
#include <QDataStream>
#include <QDebug>
#include <ostream>
namespace ClangBackEnd {
HighlightingMarkContainer::HighlightingMarkContainer(uint line,
uint column,
uint length,
HighlightingType type)
: line_(line),
column_(column),
length_(length),
type_(type)
{
}
uint HighlightingMarkContainer::line() const
{
return line_;
}
uint HighlightingMarkContainer::column() const
{
return column_;
}
uint HighlightingMarkContainer::length() const
{
return length_;
}
HighlightingType HighlightingMarkContainer::type() const
{
return type_;
}
quint32 &HighlightingMarkContainer::typeAsInt()
{
return reinterpret_cast<quint32&>(type_);
}
QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &container)
{
out << container.line_;
out << container.column_;
out << container.length_;
out << quint32(container.type_);
return out;
}
QDataStream &operator>>(QDataStream &in, HighlightingMarkContainer &container)
{
in >> container.line_;
in >> container.column_;
in >> container.length_;
in >> container.typeAsInt();
return in;
}
bool operator==(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second)
{
return first.line_ == second.line_
&& first.column_ == second.column_
&& first.length_ == second.length_
&& first.type_ == second.type_;
}
bool operator<(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second)
{
if (first.line() == second.line()) {
if (first.column() == second.column()) {
if (first.length() == second.length())
return first.type() < second.type();
return first.length() < second.length();
}
return first.column() < second.column();
}
return first.line() < second.line();
}
#define RETURN_TEXT_FOR_CASE(enumValue) case HighlightingType::enumValue: return #enumValue
static const char *highlightingTypeToCStringLiteral(HighlightingType type)
{
switch (type) {
RETURN_TEXT_FOR_CASE(Invalid);
RETURN_TEXT_FOR_CASE(Comment);
RETURN_TEXT_FOR_CASE(Keyword);
RETURN_TEXT_FOR_CASE(StringLiteral);
RETURN_TEXT_FOR_CASE(NumberLiteral);
RETURN_TEXT_FOR_CASE(Function);
RETURN_TEXT_FOR_CASE(VirtualFunction);
RETURN_TEXT_FOR_CASE(Type);
RETURN_TEXT_FOR_CASE(LocalVariable);
RETURN_TEXT_FOR_CASE(GlobalVariable);
RETURN_TEXT_FOR_CASE(Field);
RETURN_TEXT_FOR_CASE(Enumeration);
RETURN_TEXT_FOR_CASE(Operator);
RETURN_TEXT_FOR_CASE(Preprocessor);
RETURN_TEXT_FOR_CASE(Label);
RETURN_TEXT_FOR_CASE(OutputArgument);
RETURN_TEXT_FOR_CASE(PreprocessorDefinition);
RETURN_TEXT_FOR_CASE(PreprocessorExpansion);
default: return "UnhandledHighlightingType";
}
}
#undef RETURN_TEXT_FOR_CASE
QDebug operator<<(QDebug debug, const HighlightingMarkContainer &container)
{
debug.nospace() << "HighlightingMarkContainer("
<< container.line() << ", "
<< container.column() << ", "
<< container.length() << ", "
<< highlightingTypeToCStringLiteral(container.type()) << ", "
<< ")";
return debug;
}
void PrintTo(HighlightingType highlightingType, std::ostream *os)
{
*os << highlightingTypeToCStringLiteral(highlightingType);
}
void PrintTo(const HighlightingMarkContainer& container, ::std::ostream *os)
{
*os << "HighlightingMarkContainer("
<< container.line() << ", "
<< container.column() << ", "
<< container.length() << ", ";
PrintTo(container.type(), os);
*os << ")";
}
} // namespace ClangBackEnd
/****************************************************************************
**
** 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_HIGHLIGHTINGMARKCONTAINER_H
#define CLANGBACKEND_HIGHLIGHTINGMARKCONTAINER_H
#include "clangbackendipc_global.h"
#include <QMetaType>
namespace ClangBackEnd {
class CMBIPC_EXPORT HighlightingMarkContainer
{
friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &container);
friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, HighlightingMarkContainer &container);
friend CMBIPC_EXPORT bool operator==(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second);
friend CMBIPC_EXPORT bool operator<(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second);
public:
HighlightingMarkContainer() = default;
HighlightingMarkContainer(uint line, uint column, uint length, HighlightingType type);
uint line() const;
uint column() const;
uint length() const;
HighlightingType type() const;
private:
quint32 &typeAsInt();
private:
uint line_;
uint column_;
uint length_;
HighlightingType type_;
};
CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const HighlightingMarkContainer &container);
CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, HighlightingMarkContainer &container);
CMBIPC_EXPORT bool operator==(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second);
CMBIPC_EXPORT bool operator<(const HighlightingMarkContainer &first, const HighlightingMarkContainer &second);
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const HighlightingMarkContainer &container);
CMBIPC_EXPORT void PrintTo(HighlightingType highlightingType, ::std::ostream *os);
void PrintTo(const HighlightingMarkContainer &container, ::std::ostream *os);
} // namespace ClangBackEnd
Q_DECLARE_METATYPE(ClangBackEnd::HighlightingMarkContainer)
#endif // CLANGBACKEND_HIGHLIGHTINGMARKCONTAINER_H
...@@ -80,5 +80,11 @@ void IpcClientDispatcher::diagnosticsChanged(const DiagnosticsChangedMessage &me ...@@ -80,5 +80,11 @@ void IpcClientDispatcher::diagnosticsChanged(const DiagnosticsChangedMessage &me
client->diagnosticsChanged(message); client->diagnosticsChanged(message);
} }
void IpcClientDispatcher::highlightingChanged(const HighlightingChangedMessage &message)
{
for (auto *client : clients)
client->highlightingChanged(message);
}
} // namespace ClangBackEnd } // namespace ClangBackEnd
...@@ -49,6 +49,7 @@ public: ...@@ -49,6 +49,7 @@ public:
void translationUnitDoesNotExist(const TranslationUnitDoesNotExistMessage &message) override; void translationUnitDoesNotExist(const TranslationUnitDoesNotExistMessage &message) override;
void projectPartsDoNotExist(const ProjectPartsDoNotExistMessage &message) override; void projectPartsDoNotExist(const ProjectPartsDoNotExistMessage &message) override;
void diagnosticsChanged(const DiagnosticsChangedMessage &message) override; void diagnosticsChanged(const DiagnosticsChangedMessage &message) override;
void highlightingChanged(const HighlightingChangedMessage &message) override;
private: private:
QVector<IpcClientInterface*> clients; QVector<IpcClientInterface*> clients;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "projectpartsdonotexistmessage.h" #include "projectpartsdonotexistmessage.h"
#include "translationunitdoesnotexistmessage.h" #include "translationunitdoesnotexistmessage.h"
#include "diagnosticschangedmessage.h" #include "diagnosticschangedmessage.h"
#include "highlightingchangedmessage.h"
#include <QDebug> #include <QDebug>
#include <QVariant> #include <QVariant>
...@@ -50,6 +51,7 @@ void IpcClientInterface::dispatch(const QVariant &message) ...@@ -50,6 +51,7 @@ void IpcClientInterface::dispatch(const QVariant &message)
static const int translationUnitDoesNotExistMessage = QMetaType::type("ClangBackEnd::TranslationUnitDoesNotExistMessage"); static const int translationUnitDoesNotExistMessage = QMetaType::type("ClangBackEnd::TranslationUnitDoesNotExistMessage");
static const int projectPartsDoNotExistMessage = QMetaType::type("ClangBackEnd::ProjectPartsDoNotExistMessage"); static const int projectPartsDoNotExistMessage = QMetaType::type("ClangBackEnd::ProjectPartsDoNotExistMessage");
static const int diagnosticsChangedMessage = QMetaType::type("ClangBackEnd::DiagnosticsChangedMessage"); static const int diagnosticsChangedMessage = QMetaType::type("ClangBackEnd::DiagnosticsChangedMessage");
static const int highlightingChangedMessage = QMetaType::type("ClangBackEnd::HighlightingChangedMessage");
int type = message.userType(); int type = message.userType();
...@@ -65,6 +67,8 @@ void IpcClientInterface::dispatch(const QVariant &message) ...@@ -65,6 +67,8 @@ void IpcClientInterface::dispatch(const QVariant &message)
projectPartsDoNotExist(message.value<ProjectPartsDoNotExistMessage>()); projectPartsDoNotExist(message.value<ProjectPartsDoNotExistMessage>());
else if (type == diagnosticsChangedMessage) else if (type == diagnosticsChangedMessage)
diagnosticsChanged(message.value<DiagnosticsChangedMessage>()); diagnosticsChanged(message.value<DiagnosticsChangedMessage>());
else if (type == highlightingChangedMessage)
highlightingChanged(message.value<HighlightingChangedMessage>());
else else
qWarning() << "Unknown IpcClientMessage"; qWarning() << "Unknown IpcClientMessage";
}