aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/outputformatter.h
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-04-16 13:53:05 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-04-23 08:47:08 +0000
commit1c6e4fbd3211bc180b0de95d232226825bcb124d (patch)
treec9adce875a62a7fa980eb8a99231034585ae8fbf /src/libs/utils/outputformatter.h
parentb7851eeb55fd284bd647b7042e7f94a1ea1d3490 (diff)
Merge output formatters and output parsers
Now only one piece of code needs to be written to both linkify output in an output pane and create tasks for it in the issues pane. The calling sites are also simplified. For instance, until now, build steps had to feed their output parsers manually and then push the created tasks up the signal stack in parallel with the actual output, which the build manager relied upon for cross-linking the output pane content. Afterwards, the output would get forwarded to the formatter (and parsed for ANSI escape codes a second time). In contrast, a build step now just forwards the process output, and task parsing as well as output formatting is done centrally further up the stack. Concrete user-visible improvements so far: - File paths in compiler/linker messages are clickable links now. - QtTest applications now create clickable links also when run as part of a build step, not just in the app output pane. Task-number: QTCREATORBUG-22665 Change-Id: Ic9fb95b2d97f2520ab3ec653315e9219466ec08d Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/libs/utils/outputformatter.h')
-rw-r--r--src/libs/utils/outputformatter.h93
1 files changed, 82 insertions, 11 deletions
diff --git a/src/libs/utils/outputformatter.h b/src/libs/utils/outputformatter.h
index edee0ef0b6..dcc5b5f76c 100644
--- a/src/libs/utils/outputformatter.h
+++ b/src/libs/utils/outputformatter.h
@@ -26,25 +26,32 @@
#pragma once
#include "utils_global.h"
+#include "fileutils.h"
#include "optional.h"
#include "outputformat.h"
#include <QObject>
+#include <functional>
+
QT_BEGIN_NAMESPACE
class QPlainTextEdit;
+class QRegExp;
+class QRegularExpressionMatch;
class QTextCharFormat;
class QTextCursor;
QT_END_NAMESPACE
namespace Utils {
-
+class FileInProjectFinder;
class FormattedText;
-class QTCREATOR_UTILS_EXPORT OutputLineParser
+class QTCREATOR_UTILS_EXPORT OutputLineParser : public QObject
{
+ Q_OBJECT
public:
- virtual ~OutputLineParser();
+ OutputLineParser();
+ ~OutputLineParser() override;
enum class Status { Done, InProgress, NotHandled };
class LinkSpec {
@@ -65,20 +72,62 @@ public:
optional<QString> newContent; // Hard content override. Only to be used in extreme cases.
};
+ static bool isLinkTarget(const QString &target);
+ static void parseLinkTarget(const QString &target, FilePath &filePath, int &line, int &column);
+
+ void addSearchDir(const Utils::FilePath &dir);
+ void dropSearchDir(const Utils::FilePath &dir);
+ const FilePaths searchDirectories() const;
+
+ void setFileFinder(Utils::FileInProjectFinder *finder);
+
+ void setDemoteErrorsToWarnings(bool demote);
+ bool demoteErrorsToWarnings() const;
+
// line contains at most one line feed character, and if it does occur, it's the last character.
// Either way, the input is to be considered "complete" for parsing purposes.
virtual Result handleLine(const QString &line, OutputFormat format) = 0;
virtual bool handleLink(const QString &href) { Q_UNUSED(href); return false; }
- virtual void reset() {}
-};
+ virtual bool hasFatalErrors() const { return false; }
+ virtual void flush() {}
+ virtual void runPostPrintActions() {}
+ void setRedirectionDetector(const OutputLineParser *detector);
+ bool needsRedirection() const;
+ virtual bool hasDetectedRedirection() const { return false; }
+#ifdef WITH_TESTS
+ void skipFileExistsCheck();
+#endif
-namespace Internal { class OutputFormatterPrivate; }
+protected:
+ static QString rightTrimmed(const QString &in);
+ Utils::FilePath absoluteFilePath(const Utils::FilePath &filePath);
+ static QString createLinkTarget(const FilePath &filePath, int line, int column);
+ void addLinkSpecForAbsoluteFilePath(LinkSpecs &linkSpecs, const FilePath &filePath,
+ int lineNo, int pos, int len);
+ void addLinkSpecForAbsoluteFilePath(LinkSpecs &linkSpecs, const FilePath &filePath,
+ int lineNo, const QRegExp &regex, int capIndex);
+ void addLinkSpecForAbsoluteFilePath(LinkSpecs &linkSpecs, const FilePath &filePath,
+ int lineNo, const QRegularExpressionMatch &match,
+ int capIndex);
+ void addLinkSpecForAbsoluteFilePath(LinkSpecs &linkSpecs, const FilePath &filePath,
+ int lineNo, const QRegularExpressionMatch &match,
+ const QString &capName);
+
+signals:
+ void newSearchDir(const Utils::FilePath &dir);
+ void searchDirExpired(const Utils::FilePath &dir);
+
+private:
+ class Private;
+ Private * const d;
+};
class QTCREATOR_UTILS_EXPORT OutputFormatter : public QObject
{
+ Q_OBJECT
public:
OutputFormatter();
~OutputFormatter() override;
@@ -86,17 +135,33 @@ public:
QPlainTextEdit *plainTextEdit() const;
void setPlainTextEdit(QPlainTextEdit *plainText);
+ // Forwards to line parsers. Add those before.
+ void addSearchDir(const FilePath &dir);
+ void dropSearchDir(const FilePath &dir);
+
void setLineParsers(const QList<OutputLineParser *> &parsers); // Takes ownership
+ void addLineParsers(const QList<OutputLineParser *> &parsers);
+ void addLineParser(OutputLineParser *parser);
+
+ void setFileFinder(const FileInProjectFinder &finder);
+ void setDemoteErrorsToWarnings(bool demote);
+
+ using PostPrintAction = std::function<void(OutputLineParser *)>;
+ void overridePostPrintAction(const PostPrintAction &postPrintAction);
void appendMessage(const QString &text, OutputFormat format);
- void flush();
+ void flush(); // Flushes in-flight data.
+ void clear(); // Clears the text edit, if there is one.
+ void reset(); // Wipes everything except the text edit.
void handleLink(const QString &href);
- void clear();
void setBoldFontEnabled(bool enabled);
+ bool hasFatalErrors() const;
+
#ifdef WITH_TESTS
void overrideTextCharFormat(const QTextCharFormat &fmt);
+ QList<OutputLineParser *> lineParsers() const;
#endif
#ifndef WITH_TESTS
@@ -105,11 +170,14 @@ private:
QTextCharFormat charFormat(OutputFormat format) const;
static QTextCharFormat linkFormat(const QTextCharFormat &inputFormat, const QString &href);
+signals:
+ void openInEditorRequested(const FilePath &filePath, int line, int column);
+
private:
void doAppendMessage(const QString &text, OutputFormat format);
- OutputLineParser::Result handleMessage(const QString &text, OutputFormat format);
- void reset();
+ OutputLineParser::Result handleMessage(const QString &text, OutputFormat format,
+ QList<OutputLineParser *> &involvedParsers);
void append(const QString &text, const QTextCharFormat &format);
void initFormats();
@@ -119,8 +187,11 @@ private:
QList<FormattedText> parseAnsi(const QString &text, const QTextCharFormat &format);
const QList<Utils::FormattedText> linkifiedText(const QList<FormattedText> &text,
const OutputLineParser::LinkSpecs &linkSpecs);
+ OutputFormat outputTypeForParser(const OutputLineParser *parser, OutputFormat type) const;
+ void setupLineParser(OutputLineParser *parser);
- Internal::OutputFormatterPrivate *d;
+ class Private;
+ Private * const d;
};