forked from qt-creator/qt-creator
Clang: Indicate lines from ClangBackEnd
...with a prefix. Change-Id: I6e23e00254d7b7316057514d1234cde66ab44a0d Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -35,8 +35,8 @@ SOURCES += $$PWD/ipcserverinterface.cpp \
|
|||||||
$$PWD/translationunitdoesnotexistcommand.cpp \
|
$$PWD/translationunitdoesnotexistcommand.cpp \
|
||||||
$$PWD/codecompletionchunk.cpp \
|
$$PWD/codecompletionchunk.cpp \
|
||||||
$$PWD/projectpartcontainer.cpp \
|
$$PWD/projectpartcontainer.cpp \
|
||||||
$$PWD/projectpartsdonotexistcommand.cpp
|
$$PWD/projectpartsdonotexistcommand.cpp \
|
||||||
|
$$PWD/lineprefixer.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/ipcserverinterface.h \
|
$$PWD/ipcserverinterface.h \
|
||||||
@@ -66,6 +66,7 @@ HEADERS += \
|
|||||||
$$PWD/projectpartcontainer.h \
|
$$PWD/projectpartcontainer.h \
|
||||||
$$PWD/projectpartsdonotexistcommand.h \
|
$$PWD/projectpartsdonotexistcommand.h \
|
||||||
$$PWD/container_common.h \
|
$$PWD/container_common.h \
|
||||||
$$PWD/clangbackendipc_global.h
|
$$PWD/clangbackendipc_global.h \
|
||||||
|
$$PWD/lineprefixer.h
|
||||||
|
|
||||||
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
|
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
|
||||||
|
@@ -54,7 +54,9 @@ QString connectionName()
|
|||||||
|
|
||||||
ConnectionClient::ConnectionClient(IpcClientInterface *client)
|
ConnectionClient::ConnectionClient(IpcClientInterface *client)
|
||||||
: serverProxy_(client, &localSocket),
|
: serverProxy_(client, &localSocket),
|
||||||
isAliveTimerResetted(false)
|
isAliveTimerResetted(false),
|
||||||
|
stdErrPrefixer("ClangBackEnd-StdErr: "),
|
||||||
|
stdOutPrefixer("ClangBackEnd: ")
|
||||||
{
|
{
|
||||||
processAliveTimer.setInterval(10000);
|
processAliveTimer.setInterval(10000);
|
||||||
|
|
||||||
@@ -204,12 +206,12 @@ void ConnectionClient::printLocalSocketError(QLocalSocket::LocalSocketError sock
|
|||||||
|
|
||||||
void ConnectionClient::printStandardOutput()
|
void ConnectionClient::printStandardOutput()
|
||||||
{
|
{
|
||||||
qWarning() << "ClangBackEnd:" << process_->readAllStandardOutput();
|
QTextStream(stdout) << stdOutPrefixer.prefix(process_->readAllStandardOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionClient::printStandardError()
|
void ConnectionClient::printStandardError()
|
||||||
{
|
{
|
||||||
qWarning() << "ClangBackEnd Error:" << process_->readAllStandardError();
|
QTextStream(stderr) << stdErrPrefixer.prefix(process_->readAllStandardError());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionClient::finishProcess()
|
void ConnectionClient::finishProcess()
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#define CLANGBACKEND_CONNECTIONCLIENT_H
|
#define CLANGBACKEND_CONNECTIONCLIENT_H
|
||||||
|
|
||||||
#include "ipcserverproxy.h"
|
#include "ipcserverproxy.h"
|
||||||
|
#include "lineprefixer.h"
|
||||||
|
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
|
|
||||||
@@ -106,6 +107,9 @@ private:
|
|||||||
QTimer processAliveTimer;
|
QTimer processAliveTimer;
|
||||||
QString processPath_;
|
QString processPath_;
|
||||||
bool isAliveTimerResetted;
|
bool isAliveTimerResetted;
|
||||||
|
|
||||||
|
LinePrefixer stdErrPrefixer;
|
||||||
|
LinePrefixer stdOutPrefixer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ClangBackEnd
|
} // namespace ClangBackEnd
|
||||||
|
61
src/libs/clangbackendipc/lineprefixer.cpp
Normal file
61
src/libs/clangbackendipc/lineprefixer.cpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2015 The Qt Company Ltd.
|
||||||
|
** Contact: http://www.qt.io/licensing
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and The Qt Company. For licensing terms and
|
||||||
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
||||||
|
** use the contact form at http://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 or version 3 as published by the Free
|
||||||
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||||
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||||
|
** following information to ensure the GNU Lesser General Public License
|
||||||
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||||
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
||||||
|
** rights. These rights are described in The Qt Company LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "lineprefixer.h"
|
||||||
|
|
||||||
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
|
LinePrefixer::LinePrefixer(const QByteArray &prefix)
|
||||||
|
: m_prefix(prefix)
|
||||||
|
, m_previousIsEndingWithNewLine(true)
|
||||||
|
{}
|
||||||
|
|
||||||
|
QByteArray LinePrefixer::prefix(const QByteArray &text)
|
||||||
|
{
|
||||||
|
QByteArray output = text;
|
||||||
|
|
||||||
|
if (m_previousIsEndingWithNewLine)
|
||||||
|
output.prepend(m_prefix);
|
||||||
|
|
||||||
|
if (output.endsWith('\n')) {
|
||||||
|
m_previousIsEndingWithNewLine = true;
|
||||||
|
output.chop(1);
|
||||||
|
} else {
|
||||||
|
m_previousIsEndingWithNewLine = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
output.replace("\n", "\n" + m_prefix);
|
||||||
|
if (m_previousIsEndingWithNewLine)
|
||||||
|
output.append('\n');
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ClangBackEnd
|
55
src/libs/clangbackendipc/lineprefixer.h
Normal file
55
src/libs/clangbackendipc/lineprefixer.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 PRINTLINESWITHPREFIX_H
|
||||||
|
#define PRINTLINESWITHPREFIX_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <utf8string.h>
|
||||||
|
|
||||||
|
namespace ClangBackEnd {
|
||||||
|
|
||||||
|
class LinePrefixer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LinePrefixer() = delete;
|
||||||
|
LinePrefixer(const QByteArray &m_prefix);
|
||||||
|
QByteArray prefix(const QByteArray &text);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QByteArray m_prefix;
|
||||||
|
bool m_previousIsEndingWithNewLine;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ClangBackEnd
|
||||||
|
|
||||||
|
#endif // PRINTLINESWITHPREFIX_H
|
120
tests/unit/unittest/lineprefixertest.cpp
Normal file
120
tests/unit/unittest/lineprefixertest.cpp
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
|
||||||
|
** Contact: http://www.qt.io/licensing
|
||||||
|
**
|
||||||
|
** This file is part of Qt Creator.
|
||||||
|
**
|
||||||
|
** Commercial License Usage
|
||||||
|
** Licensees holding valid commercial Qt licenses may use this file in
|
||||||
|
** accordance with the commercial license agreement provided with the
|
||||||
|
** Software or, alternatively, in accordance with the terms contained in
|
||||||
|
** a written agreement between you and Digia. For licensing terms and
|
||||||
|
** conditions see http://www.qt.io/licensing. For further information
|
||||||
|
** use the contact form at http://www.qt.io/contact-us.
|
||||||
|
**
|
||||||
|
** GNU Lesser General Public License Usage
|
||||||
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||||
|
** General Public License version 2.1 or version 3 as published by the Free
|
||||||
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
||||||
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
||||||
|
** following information to ensure the GNU Lesser General Public License
|
||||||
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
||||||
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||||
|
**
|
||||||
|
** In addition, as a special exception, Digia gives you certain additional
|
||||||
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
||||||
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <lineprefixer.h>
|
||||||
|
#include <utf8string.h>
|
||||||
|
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <gtest-qt-printing.h>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
QByteArray runPrefixer(QList<QByteArray> inputChunks)
|
||||||
|
{
|
||||||
|
QByteArray actualOutput;
|
||||||
|
ClangBackEnd::LinePrefixer prefixer("PREFIX ");
|
||||||
|
foreach (const QByteArray &chunk, inputChunks)
|
||||||
|
actualOutput += prefixer.prefix(chunk);
|
||||||
|
return actualOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LinePrefixer, OneChunkEndsWithNewline)
|
||||||
|
{
|
||||||
|
const QList<QByteArray> inputChunks { "hello\n" };
|
||||||
|
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
||||||
|
Utf8String::fromUtf8("PREFIX hello\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LinePrefixer, OneChunkEndsWithoutNewline)
|
||||||
|
{
|
||||||
|
const QList<QByteArray> inputChunks { "hello" };
|
||||||
|
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
||||||
|
Utf8String::fromUtf8("PREFIX hello"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LinePrefixer, OneChunkStartsWithNewline)
|
||||||
|
{
|
||||||
|
const QList<QByteArray> inputChunks { "\nhello" };
|
||||||
|
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
||||||
|
Utf8String::fromUtf8("PREFIX \n"
|
||||||
|
"PREFIX hello"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LinePrefixer, OneChunkStartsAndEndsWithNewline)
|
||||||
|
{
|
||||||
|
const QList<QByteArray> inputChunks { "\nhello\n" };
|
||||||
|
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
||||||
|
Utf8String::fromUtf8("PREFIX \n"
|
||||||
|
"PREFIX hello\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LinePrefixer, OneChunkEndsWithExtraNewline)
|
||||||
|
{
|
||||||
|
const QList<QByteArray> inputChunks { "hello\n\n" };
|
||||||
|
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
||||||
|
Utf8String::fromUtf8("PREFIX hello\n"
|
||||||
|
"PREFIX \n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LinePrefixer, OneChunkEndsWithTwoExtraNewlines)
|
||||||
|
{
|
||||||
|
const QList<QByteArray> inputChunks { "hello\n\n\n" };
|
||||||
|
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
||||||
|
Utf8String::fromUtf8("PREFIX hello\n"
|
||||||
|
"PREFIX \n"
|
||||||
|
"PREFIX \n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LinePrefixer, ChunkWithoutNewlineAndChunkWithNewline)
|
||||||
|
{
|
||||||
|
const QList<QByteArray> inputChunks { "hello", "\n" };
|
||||||
|
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
||||||
|
Utf8String::fromUtf8("PREFIX hello\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LinePrefixer, ChunkWithoutNewlineAndChunkWithTwoNewlines)
|
||||||
|
{
|
||||||
|
const QList<QByteArray> inputChunks { "hello", "\n\n" };
|
||||||
|
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
||||||
|
Utf8String::fromUtf8("PREFIX hello\n"
|
||||||
|
"PREFIX \n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LinePrefixer, ChunkWithTwoNewlinesAndChunkWithoutNewline)
|
||||||
|
{
|
||||||
|
const QList<QByteArray> inputChunks { "\n\n", "hello" };
|
||||||
|
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
||||||
|
Utf8String::fromUtf8("PREFIX \n"
|
||||||
|
"PREFIX \n"
|
||||||
|
"PREFIX hello"));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
@@ -56,7 +56,8 @@ SOURCES += main.cpp \
|
|||||||
projecttest.cpp \
|
projecttest.cpp \
|
||||||
clangipcservertest.cpp \
|
clangipcservertest.cpp \
|
||||||
translationunitstest.cpp \
|
translationunitstest.cpp \
|
||||||
completionchunkstotextconvertertest.cpp
|
completionchunkstotextconvertertest.cpp \
|
||||||
|
lineprefixertest.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
gtest-qt-printing.h \
|
gtest-qt-printing.h \
|
||||||
|
Reference in New Issue
Block a user