forked from qt-creator/qt-creator
Clang: Tool tips for clang query diagnostics
If you hover a diagnostics in for a clang query you get now a simple tool tip. Change-Id: I6352dd3d4b9a33c183e69037eac903469b90eea4 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -55,7 +55,7 @@ public:
|
|||||||
return m_contextType;
|
return m_contextType;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::SmallString contextTypeText() const;
|
CMBIPC_EXPORT Utils::SmallString contextTypeText() const;
|
||||||
|
|
||||||
const Utils::SmallStringVector &arguments() const
|
const Utils::SmallStringVector &arguments() const
|
||||||
{
|
{
|
||||||
|
@@ -33,8 +33,8 @@ namespace ClangBackEnd {
|
|||||||
QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticMessageContainer &container)
|
QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticMessageContainer &container)
|
||||||
{
|
{
|
||||||
debug.nospace() << "DynamicASTMatcherDiagnosticMessageContainer("
|
debug.nospace() << "DynamicASTMatcherDiagnosticMessageContainer("
|
||||||
<< container.sourceRange() << ", "
|
|
||||||
<< container.errorTypeText() << ", "
|
<< container.errorTypeText() << ", "
|
||||||
|
<< container.sourceRange() << ", "
|
||||||
<< container.arguments()
|
<< container.arguments()
|
||||||
<< ")";
|
<< ")";
|
||||||
|
|
||||||
|
@@ -55,7 +55,7 @@ public:
|
|||||||
return m_errorType;
|
return m_errorType;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::SmallString errorTypeText() const;
|
CMBIPC_EXPORT Utils::SmallString errorTypeText() const;
|
||||||
|
|
||||||
const Utils::SmallStringVector &arguments() const
|
const Utils::SmallStringVector &arguments() const
|
||||||
{
|
{
|
||||||
|
@@ -72,6 +72,18 @@ bool ClangQueryHighlighter::hasDiagnostics() const
|
|||||||
return m_marker.hasMessagesOrContexts();
|
return m_marker.hasMessagesOrContexts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers
|
||||||
|
ClangQueryHighlighter::messagesForLineAndColumn(uint line, uint column) const
|
||||||
|
{
|
||||||
|
return m_marker.messagesForLineAndColumn(line, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers
|
||||||
|
ClangQueryHighlighter::contextsForLineAndColumn(uint line, uint column) const
|
||||||
|
{
|
||||||
|
return m_marker.contextsForLineAndColumn(line, column);
|
||||||
|
}
|
||||||
|
|
||||||
void ClangQueryHighlighter::highlightBlock(const QString &text)
|
void ClangQueryHighlighter::highlightBlock(const QString &text)
|
||||||
{
|
{
|
||||||
int currentLineNumber = currentBlock().blockNumber() + 1;
|
int currentLineNumber = currentBlock().blockNumber() + 1;
|
||||||
|
@@ -44,6 +44,12 @@ public:
|
|||||||
|
|
||||||
bool hasDiagnostics() const;
|
bool hasDiagnostics() const;
|
||||||
|
|
||||||
|
ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers
|
||||||
|
messagesForLineAndColumn(uint line, uint column) const;
|
||||||
|
|
||||||
|
ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers
|
||||||
|
contextsForLineAndColumn(uint line, uint column) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void highlightBlock(const QString &text) override;
|
void highlightBlock(const QString &text) override;
|
||||||
|
|
||||||
|
@@ -250,6 +250,85 @@ public:
|
|||||||
return !m_messages.empty() || !m_contexts.empty();
|
return !m_messages.empty() || !m_contexts.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool isAfterStartColumn(const SourceRange &sourceRange, uint line, uint column)
|
||||||
|
{
|
||||||
|
return sourceRange.start().line() == line && sourceRange.start().column() <= column;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool isBeforeEndColumn(const SourceRange &sourceRange, uint line, uint column)
|
||||||
|
{
|
||||||
|
return sourceRange.end().line() == line && sourceRange.end().column() >= column;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool isInBetweenLine(const SourceRange &sourceRange, uint line)
|
||||||
|
{
|
||||||
|
return sourceRange.start().line() < line && sourceRange.end().line() > line;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool isSingleLine(const SourceRange &sourceRange)
|
||||||
|
{
|
||||||
|
return sourceRange.start().line() == sourceRange.end().line();
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool isInsideMultiLine(const SourceRange &sourceRange, uint line, uint column)
|
||||||
|
{
|
||||||
|
return !isSingleLine(sourceRange)
|
||||||
|
&& (isAfterStartColumn(sourceRange, line, column)
|
||||||
|
|| isInBetweenLine(sourceRange, line)
|
||||||
|
|| isBeforeEndColumn(sourceRange, line, column));
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool isInsideSingleLine(const SourceRange &sourceRange, uint line, uint column)
|
||||||
|
{
|
||||||
|
return isSingleLine(sourceRange)
|
||||||
|
&& isAfterStartColumn(sourceRange, line, column)
|
||||||
|
&& isBeforeEndColumn(sourceRange, line, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
bool isInsideRange(const SourceRange &sourceRange, uint line, uint column)
|
||||||
|
{
|
||||||
|
return isInsideSingleLine(sourceRange, line, column)
|
||||||
|
|| isInsideMultiLine(sourceRange, line, column);
|
||||||
|
}
|
||||||
|
|
||||||
|
Messages messagesForLineAndColumn(uint line, uint column) const
|
||||||
|
{
|
||||||
|
Messages messages;
|
||||||
|
|
||||||
|
auto underPosition = [=] (const Message &message) {
|
||||||
|
return ClangQueryHighlightMarker::isInsideRange(message.sourceRange(), line, column);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::copy_if(m_messages.begin(),
|
||||||
|
m_messages.end(),
|
||||||
|
std::back_inserter(messages),
|
||||||
|
underPosition);
|
||||||
|
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
Contexts contextsForLineAndColumn(uint line, uint column) const
|
||||||
|
{
|
||||||
|
Contexts contexts;
|
||||||
|
|
||||||
|
auto underPosition = [=] (const Context &context) {
|
||||||
|
return ClangQueryHighlightMarker::isInsideRange(context.sourceRange(), line, column);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::copy_if(m_contexts.begin(),
|
||||||
|
m_contexts.end(),
|
||||||
|
std::back_inserter(contexts),
|
||||||
|
underPosition);
|
||||||
|
|
||||||
|
return contexts;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Contexts m_contexts;
|
Contexts m_contexts;
|
||||||
|
60
src/plugins/clangrefactoring/clangqueryhoverhandler.cpp
Normal file
60
src/plugins/clangrefactoring/clangqueryhoverhandler.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2017 The Qt Company Ltd.
|
||||||
|
** Contact: https://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 https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "clangqueryhoverhandler.h"
|
||||||
|
|
||||||
|
#include "clangqueryhighlighter.h"
|
||||||
|
|
||||||
|
#include <dynamicastmatcherdiagnosticmessagecontainer.h>
|
||||||
|
|
||||||
|
#include <texteditor/texteditor.h>
|
||||||
|
|
||||||
|
namespace ClangRefactoring {
|
||||||
|
|
||||||
|
ClangQueryHoverHandler::ClangQueryHoverHandler(ClangQueryHighlighter *highligher)
|
||||||
|
: m_highligher(highligher)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClangQueryHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, int position)
|
||||||
|
{
|
||||||
|
using Messages = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers;
|
||||||
|
using Contexts = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers;
|
||||||
|
|
||||||
|
QTextCursor textCursor = editorWidget->textCursor();
|
||||||
|
textCursor.setPosition(position);
|
||||||
|
int line = textCursor.blockNumber() + 1;
|
||||||
|
int column = textCursor.columnNumber() + 1;
|
||||||
|
|
||||||
|
Messages messages = m_highligher->messagesForLineAndColumn(uint(line), uint(column));
|
||||||
|
Contexts contexts = m_highligher->contextsForLineAndColumn(uint(line), uint(column));
|
||||||
|
|
||||||
|
if (!messages.empty())
|
||||||
|
setToolTip(QString("%1: %2").arg(messages[0].errorTypeText()).arg(messages[0].arguments().join(", ")));
|
||||||
|
else if (!contexts.empty())
|
||||||
|
setToolTip(QString("%1: %2").arg(contexts[0].contextTypeText()).arg(contexts[0].arguments().join(", ")));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ClangRefactoring
|
46
src/plugins/clangrefactoring/clangqueryhoverhandler.h
Normal file
46
src/plugins/clangrefactoring/clangqueryhoverhandler.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2017 The Qt Company Ltd.
|
||||||
|
** Contact: https://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 https://www.qt.io/terms-conditions. For further
|
||||||
|
** information use the contact form at https://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU
|
||||||
|
** General Public License version 3 as published by the Free Software
|
||||||
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||||
|
** included in the packaging of this file. Please review the following
|
||||||
|
** information to ensure the GNU General Public License requirements will
|
||||||
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <texteditor/basehoverhandler.h>
|
||||||
|
|
||||||
|
namespace ClangRefactoring {
|
||||||
|
|
||||||
|
class ClangQueryHighlighter;
|
||||||
|
|
||||||
|
class ClangQueryHoverHandler : public TextEditor::BaseHoverHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ClangQueryHoverHandler(ClangQueryHighlighter *highligher);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int position) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ClangQueryHighlighter *m_highligher;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ClangRefactoring
|
@@ -26,19 +26,24 @@
|
|||||||
#include "clangquerytexteditorwidget.h"
|
#include "clangquerytexteditorwidget.h"
|
||||||
|
|
||||||
#include "clangqueryhighlighter.h"
|
#include "clangqueryhighlighter.h"
|
||||||
|
#include "clangqueryhoverhandler.h"
|
||||||
|
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
|
|
||||||
namespace ClangRefactoring {
|
namespace ClangRefactoring {
|
||||||
|
|
||||||
ClangQueryTextEditorWidget::ClangQueryTextEditorWidget(QWidget *parent)
|
ClangQueryTextEditorWidget::ClangQueryTextEditorWidget(QWidget *parent)
|
||||||
: BaseClangQueryTextEditorWidget(parent)
|
: BaseClangQueryTextEditorWidget(parent),
|
||||||
|
m_syntaxHighlighter(new ClangQueryHighlighter),
|
||||||
|
m_hoverHandler(std::make_unique<ClangQueryHoverHandler>(m_syntaxHighlighter))
|
||||||
{
|
{
|
||||||
m_syntaxHighlighter = new ClangQueryHighlighter;
|
|
||||||
|
|
||||||
textDocument()->setSyntaxHighlighter(m_syntaxHighlighter);
|
textDocument()->setSyntaxHighlighter(m_syntaxHighlighter);
|
||||||
|
|
||||||
|
addHoverHandler(m_hoverHandler.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClangQueryTextEditorWidget::~ClangQueryTextEditorWidget() = default;
|
||||||
|
|
||||||
ClangQueryHighlighter *ClangQueryTextEditorWidget::syntaxHighlighter() const
|
ClangQueryHighlighter *ClangQueryTextEditorWidget::syntaxHighlighter() const
|
||||||
{
|
{
|
||||||
return m_syntaxHighlighter;
|
return m_syntaxHighlighter;
|
||||||
|
@@ -27,9 +27,12 @@
|
|||||||
|
|
||||||
#include "baseclangquerytexteditorwidget.h"
|
#include "baseclangquerytexteditorwidget.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace ClangRefactoring {
|
namespace ClangRefactoring {
|
||||||
|
|
||||||
class ClangQueryHighlighter;
|
class ClangQueryHighlighter;
|
||||||
|
class ClangQueryHoverHandler;
|
||||||
|
|
||||||
class ClangQueryTextEditorWidget : public BaseClangQueryTextEditorWidget
|
class ClangQueryTextEditorWidget : public BaseClangQueryTextEditorWidget
|
||||||
{
|
{
|
||||||
@@ -37,11 +40,13 @@ class ClangQueryTextEditorWidget : public BaseClangQueryTextEditorWidget
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ClangQueryTextEditorWidget(QWidget *parent);
|
ClangQueryTextEditorWidget(QWidget *parent);
|
||||||
|
~ClangQueryTextEditorWidget();
|
||||||
|
|
||||||
ClangQueryHighlighter *syntaxHighlighter() const;
|
ClangQueryHighlighter *syntaxHighlighter() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ClangQueryHighlighter *m_syntaxHighlighter;
|
ClangQueryHighlighter *m_syntaxHighlighter;
|
||||||
|
std::unique_ptr<ClangQueryHoverHandler> m_hoverHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ClangRefactoring
|
} // namespace ClangRefactoring
|
||||||
|
@@ -14,7 +14,8 @@ HEADERS += \
|
|||||||
clangqueryprojectsfindfilterwidget.h \
|
clangqueryprojectsfindfilterwidget.h \
|
||||||
clangqueryexampletexteditorwidget.h \
|
clangqueryexampletexteditorwidget.h \
|
||||||
clangquerytexteditorwidget.h \
|
clangquerytexteditorwidget.h \
|
||||||
baseclangquerytexteditorwidget.h
|
baseclangquerytexteditorwidget.h \
|
||||||
|
clangqueryhoverhandler.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
clangrefactoringplugin.cpp \
|
clangrefactoringplugin.cpp \
|
||||||
@@ -24,7 +25,8 @@ SOURCES += \
|
|||||||
clangqueryprojectsfindfilterwidget.cpp \
|
clangqueryprojectsfindfilterwidget.cpp \
|
||||||
clangqueryexampletexteditorwidget.cpp \
|
clangqueryexampletexteditorwidget.cpp \
|
||||||
clangquerytexteditorwidget.cpp \
|
clangquerytexteditorwidget.cpp \
|
||||||
baseclangquerytexteditorwidget.cpp
|
baseclangquerytexteditorwidget.cpp \
|
||||||
|
clangqueryhoverhandler.cpp
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
clangqueryprojectsfindfilter.ui
|
clangqueryprojectsfindfilter.ui
|
||||||
|
@@ -5339,6 +5339,11 @@ void TextEditorWidget::showDefaultContextMenu(QContextMenuEvent *e, Id menuConte
|
|||||||
menu.exec(e->globalPos());
|
menu.exec(e->globalPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditorWidget::addHoverHandler(BaseHoverHandler *handler)
|
||||||
|
{
|
||||||
|
d->m_hoverHandlers.append(handler);
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorWidget::extraAreaLeaveEvent(QEvent *)
|
void TextEditorWidget::extraAreaLeaveEvent(QEvent *)
|
||||||
{
|
{
|
||||||
d->extraAreaPreviousMarkTooltipRequestedLine = -1;
|
d->extraAreaPreviousMarkTooltipRequestedLine = -1;
|
||||||
|
@@ -512,6 +512,8 @@ protected:
|
|||||||
virtual void finalizeInitializationAfterDuplication(TextEditorWidget *) {}
|
virtual void finalizeInitializationAfterDuplication(TextEditorWidget *) {}
|
||||||
static QTextCursor flippedCursor(const QTextCursor &cursor);
|
static QTextCursor flippedCursor(const QTextCursor &cursor);
|
||||||
|
|
||||||
|
void addHoverHandler(BaseHoverHandler *handler);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Link
|
struct Link
|
||||||
{
|
{
|
||||||
|
@@ -92,7 +92,7 @@ SourceRangesContainer ClangQuery::takeSourceRanges()
|
|||||||
return std::move(sourceRangesContainer);
|
return std::move(sourceRangesContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DynamicASTMatcherDiagnosticContainer> ClangQuery::takeDiagnosticContainers()
|
DynamicASTMatcherDiagnosticContainers ClangQuery::takeDiagnosticContainers()
|
||||||
{
|
{
|
||||||
return std::move(diagnosticContainers_);
|
return std::move(diagnosticContainers_);
|
||||||
}
|
}
|
||||||
|
@@ -58,7 +58,7 @@ public:
|
|||||||
void findLocations();
|
void findLocations();
|
||||||
|
|
||||||
SourceRangesContainer takeSourceRanges();
|
SourceRangesContainer takeSourceRanges();
|
||||||
std::vector<DynamicASTMatcherDiagnosticContainer> takeDiagnosticContainers();
|
DynamicASTMatcherDiagnosticContainers takeDiagnosticContainers();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseDiagnostics(const clang::ast_matchers::dynamic::Diagnostics &diagnostics);
|
void parseDiagnostics(const clang::ast_matchers::dynamic::Diagnostics &diagnostics);
|
||||||
|
@@ -32,12 +32,16 @@
|
|||||||
namespace {
|
namespace {
|
||||||
using testing::AllOf;
|
using testing::AllOf;
|
||||||
using testing::Contains;
|
using testing::Contains;
|
||||||
|
using testing::ElementsAre;
|
||||||
|
using testing::Pointwise;
|
||||||
using testing::IsEmpty;
|
using testing::IsEmpty;
|
||||||
using testing::Not;
|
using testing::Not;
|
||||||
using testing::InSequence;
|
using testing::InSequence;
|
||||||
using testing::_;
|
using testing::_;
|
||||||
|
|
||||||
using SourceRange = ClangBackEnd::V2::SourceRangeContainer;
|
using SourceRange = ClangBackEnd::V2::SourceRangeContainer;
|
||||||
|
using Message = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainer;
|
||||||
|
using Context = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainer;
|
||||||
using Messages = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers;
|
using Messages = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers;
|
||||||
using Contexts = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers;
|
using Contexts = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers;
|
||||||
using Marker = ClangRefactoring::ClangQueryHighlightMarker<MockSyntaxHighlighter>;
|
using Marker = ClangRefactoring::ClangQueryHighlightMarker<MockSyntaxHighlighter>;
|
||||||
@@ -54,7 +58,6 @@ protected:
|
|||||||
QTextCharFormat contextTextFormat;
|
QTextCharFormat contextTextFormat;
|
||||||
MockSyntaxHighlighter highlighter;
|
MockSyntaxHighlighter highlighter;
|
||||||
Marker marker{highlighter};
|
Marker marker{highlighter};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(ClangQueryHighlightMarker, NoCallForNoMessagesAndContexts)
|
TEST_F(ClangQueryHighlightMarker, NoCallForNoMessagesAndContexts)
|
||||||
@@ -120,6 +123,262 @@ TEST_F(ClangQueryHighlightMarker, CallForMessagesAndContextForAMultiLine)
|
|||||||
marker.highlightBlock(3, " ) ");
|
marker.highlightBlock(3, " ) ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, NoMessagesIfEmpty)
|
||||||
|
{
|
||||||
|
Messages messages;
|
||||||
|
Contexts contexts;
|
||||||
|
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
|
||||||
|
|
||||||
|
auto foundMessages = marker.messagesForLineAndColumn(1, 1);
|
||||||
|
|
||||||
|
ASSERT_THAT(foundMessages, IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, NoMessagesForBeforePosition)
|
||||||
|
{
|
||||||
|
Messages messages{{{1, 1, 5, 0, 3, 3, 0},
|
||||||
|
ErrorType::RegistryMatcherNotFound,
|
||||||
|
{"foo"}}};
|
||||||
|
Contexts contexts;
|
||||||
|
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
|
||||||
|
|
||||||
|
auto foundMessages = marker.messagesForLineAndColumn(1, 4);
|
||||||
|
|
||||||
|
ASSERT_THAT(foundMessages, IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, NoMessagesForAfterPosition)
|
||||||
|
{
|
||||||
|
Messages messages{{{1, 1, 5, 0, 3, 3, 0},
|
||||||
|
ErrorType::RegistryMatcherNotFound,
|
||||||
|
{"foo"}}};
|
||||||
|
Contexts contexts;
|
||||||
|
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
|
||||||
|
|
||||||
|
auto foundMessages = marker.messagesForLineAndColumn(3, 4);
|
||||||
|
|
||||||
|
ASSERT_THAT(foundMessages, IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, OneMessagesForInsidePosition)
|
||||||
|
{
|
||||||
|
Message message{{1, 1, 5, 0, 3, 3, 0},
|
||||||
|
ErrorType::RegistryMatcherNotFound,
|
||||||
|
{"foo"}};
|
||||||
|
Messages messages{message.clone()};
|
||||||
|
Contexts contexts;
|
||||||
|
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
|
||||||
|
|
||||||
|
auto foundMessages = marker.messagesForLineAndColumn(2, 3);
|
||||||
|
|
||||||
|
ASSERT_THAT(foundMessages, ElementsAre(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, NoMessagesForOutsidePosition)
|
||||||
|
{
|
||||||
|
Message message{{1, 1, 5, 0, 3, 3, 0},
|
||||||
|
ErrorType::RegistryMatcherNotFound,
|
||||||
|
{"foo"}};
|
||||||
|
Messages messages{message.clone()};
|
||||||
|
Contexts contexts;
|
||||||
|
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
|
||||||
|
|
||||||
|
auto foundMessages = marker.messagesForLineAndColumn(3, 4);
|
||||||
|
|
||||||
|
ASSERT_THAT(foundMessages, IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeLine)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
|
||||||
|
|
||||||
|
bool isAfterStartColumn = marker.isInsideRange(sourceRange, 1, 6);
|
||||||
|
|
||||||
|
ASSERT_FALSE(isAfterStartColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeColumn)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
|
||||||
|
|
||||||
|
bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 4);
|
||||||
|
|
||||||
|
ASSERT_FALSE(isAfterStartColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, AfterStartColumnAtColumn)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
|
||||||
|
|
||||||
|
bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 5);
|
||||||
|
|
||||||
|
ASSERT_TRUE(isAfterStartColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, AfterStartColumnAfterColumn)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
|
||||||
|
|
||||||
|
bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 6);
|
||||||
|
|
||||||
|
ASSERT_TRUE(isAfterStartColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterLine)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
|
||||||
|
|
||||||
|
bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 4, 1);
|
||||||
|
|
||||||
|
ASSERT_FALSE(isBeforeEndColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterColumn)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
|
||||||
|
|
||||||
|
bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 4);
|
||||||
|
|
||||||
|
ASSERT_FALSE(isBeforeEndColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAtColumn)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
|
||||||
|
|
||||||
|
bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 3);
|
||||||
|
|
||||||
|
ASSERT_TRUE(isBeforeEndColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, BeforeEndColumnBeforeColumn)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
|
||||||
|
|
||||||
|
bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 2);
|
||||||
|
|
||||||
|
ASSERT_TRUE(isBeforeEndColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, InBetweenLineBeforeLine)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0};
|
||||||
|
|
||||||
|
bool isInBetween = marker.isInsideRange(sourceRange, 1, 6);
|
||||||
|
|
||||||
|
ASSERT_FALSE(isInBetween);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, InBetweenLineAfterLine)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 4, 3, 0};
|
||||||
|
|
||||||
|
bool isInBetween = marker.isInsideRange(sourceRange, 5, 1);
|
||||||
|
|
||||||
|
ASSERT_FALSE(isInBetween);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, InBetweenLine)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 4, 3, 0};
|
||||||
|
|
||||||
|
bool isInBetween = marker.isInsideRange(sourceRange, 3, 1);
|
||||||
|
|
||||||
|
ASSERT_TRUE(isInBetween);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, SingleLineBefore)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0};
|
||||||
|
|
||||||
|
bool isInRange = marker.isInsideRange(sourceRange, 2, 4);
|
||||||
|
|
||||||
|
ASSERT_FALSE(isInRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, SingleLineAfter)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0};
|
||||||
|
|
||||||
|
bool isInRange = marker.isInsideRange(sourceRange, 2, 11);
|
||||||
|
|
||||||
|
ASSERT_FALSE(isInRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, SingleLineInRange)
|
||||||
|
{
|
||||||
|
SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0};
|
||||||
|
|
||||||
|
bool isInRange = marker.isInsideRange(sourceRange, 2, 6);
|
||||||
|
|
||||||
|
ASSERT_TRUE(isInRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, NoContextsIfEmpty)
|
||||||
|
{
|
||||||
|
Messages messages;
|
||||||
|
Contexts contexts;
|
||||||
|
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
|
||||||
|
|
||||||
|
auto foundContexts = marker.contextsForLineAndColumn(1, 1);
|
||||||
|
|
||||||
|
ASSERT_THAT(foundContexts, IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, NoContextsForBeforePosition)
|
||||||
|
{
|
||||||
|
Messages messages;
|
||||||
|
Contexts contexts{{{1, 1, 5, 0, 3, 3, 0},
|
||||||
|
ContextType::MatcherArg,
|
||||||
|
{"foo"}}};
|
||||||
|
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
|
||||||
|
|
||||||
|
auto foundContexts = marker.contextsForLineAndColumn(1, 4);
|
||||||
|
|
||||||
|
ASSERT_THAT(foundContexts, IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, NoContextsForAfterPosition)
|
||||||
|
{
|
||||||
|
Messages messages;
|
||||||
|
Contexts contexts{{{1, 1, 5, 0, 3, 3, 0},
|
||||||
|
ContextType::MatcherArg,
|
||||||
|
{"foo"}}};
|
||||||
|
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
|
||||||
|
|
||||||
|
auto foundContexts = marker.contextsForLineAndColumn(3, 4);
|
||||||
|
|
||||||
|
ASSERT_THAT(foundContexts, IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, OneContextsForInsidePosition)
|
||||||
|
{
|
||||||
|
Context context{{1, 1, 5, 0, 3, 3, 0},
|
||||||
|
ContextType::MatcherArg,
|
||||||
|
{"foo"}};
|
||||||
|
Messages messages;
|
||||||
|
Contexts contexts{context.clone()};
|
||||||
|
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
|
||||||
|
|
||||||
|
auto foundContexts = marker.contextsForLineAndColumn(2, 3);
|
||||||
|
|
||||||
|
ASSERT_THAT(foundContexts, ElementsAre(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ClangQueryHighlightMarker, NoContextsForOutsidePosition)
|
||||||
|
{
|
||||||
|
Context context{{1, 1, 5, 0, 3, 3, 0},
|
||||||
|
ContextType::MatcherArg,
|
||||||
|
{"foo"}};
|
||||||
|
Messages messages;
|
||||||
|
Contexts contexts{context.clone()};
|
||||||
|
marker.setMessagesAndContexts(std::move(messages), std::move(contexts));
|
||||||
|
|
||||||
|
auto foundContexts = marker.contextsForLineAndColumn(3, 4);
|
||||||
|
|
||||||
|
ASSERT_THAT(foundContexts, IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
void ClangQueryHighlightMarker::SetUp()
|
void ClangQueryHighlightMarker::SetUp()
|
||||||
{
|
{
|
||||||
messageTextFormat.setFontItalic(true);
|
messageTextFormat.setFontItalic(true);
|
||||||
|
Reference in New Issue
Block a user