1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "ioutputparser.h"
#include "task.h"
#include "taskhub.h"
#include <coreplugin/outputwindow.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditorsettings.h>
#include <utils/algorithm.h>
#include <utils/ansiescapecodehandler.h>
#include <QPlainTextEdit>
#include <numeric>
/*!
\class ProjectExplorer::OutputTaskParser
\brief The OutputTaskParser class provides an interface for an output parser
that emits issues (tasks).
\sa ProjectExplorer::Task
*/
/*!
\fn ProjectExplorer::OutputTaskParser::Status ProjectExplorer::OutputTaskParser::handleLine(const QString &line, Utils::OutputFormat type)
Called once for each line of standard output or standard error to parse.
*/
/*!
\fn bool ProjectExplorer::OutputTaskParser::hasFatalErrors() const
This is mainly a Symbian specific quirk.
*/
/*!
\fn void ProjectExplorer::OutputTaskParser::addTask(const ProjectExplorer::Task &task)
Should be emitted for each task seen in the output.
*/
/*!
\fn void ProjectExplorer::OutputTaskParser::flush()
Instructs a parser to flush its state.
Parsers may have state (for example, because they need to aggregate several
lines into one task). This
function is called when this state needs to be flushed out to be visible.
*/
namespace ProjectExplorer {
class OutputTaskParser::Private
{
public:
QList<TaskInfo> scheduledTasks;
Task currentTask;
LinkSpecs linkSpecs;
QString origin;
int lineCount = 0;
bool targetLinkFixed = false;
};
OutputTaskParser::OutputTaskParser() : d(new Private) { }
OutputTaskParser::~OutputTaskParser() { delete d; }
const QList<OutputTaskParser::TaskInfo> OutputTaskParser::taskInfo() const
{
return d->scheduledTasks;
}
void OutputTaskParser::scheduleTask(const Task &task, int outputLines, int skippedLines)
{
TaskInfo ts(task, outputLines, skippedLines);
if (ts.task.isError() && demoteErrorsToWarnings())
ts.task.setType(Task::Warning);
d->scheduledTasks << ts;
QTC_CHECK(d->scheduledTasks.size() <= 2);
}
void OutputTaskParser::setDetailsFormat(Task &task, const LinkSpecs &linkSpecs)
{
task.setFormats({});
addDetailsFormat(task, linkSpecs);
}
void OutputTaskParser::addDetailsFormat(Task &task, const LinkSpecs &linkSpecs)
{
if (!task.hasDetails())
return;
Utils::FormattedText monospacedText(task.details().join('\n'));
monospacedText.format.setFont(TextEditor::TextEditorSettings::fontSettings().font());
monospacedText.format.setFontStyleHint(QFont::Monospace);
const QList<Utils::FormattedText> linkifiedText
= Utils::OutputFormatter::linkifiedText({monospacedText}, linkSpecs);
QList<QTextLayout::FormatRange> formats;
int offset = task.summary().size() + 1;
for (const Utils::FormattedText &ft : linkifiedText) {
formats << QTextLayout::FormatRange{offset, int(ft.text.size()), ft.format};
offset += ft.text.size();
}
task.setFormats(task.formats() + formats);
}
void OutputTaskParser::fixTargetLink()
{
d->targetLinkFixed = true;
}
void OutputTaskParser::runPostPrintActions(QPlainTextEdit *edit)
{
int offset = 0;
if (const auto ow = qobject_cast<Core::OutputWindow *>(edit)) {
Utils::reverseForeach(taskInfo(), [ow, &offset](const TaskInfo &ti) {
ow->registerPositionOf(
ti.task.id(),
ti.linkedLines,
ti.skippedLines,
offset,
Core::OutputWindow::TaskSource::Parsed);
offset += ti.linkedLines;
});
}
for (const TaskInfo &t : std::as_const(d->scheduledTasks))
TaskHub::addTask(t.task);
d->scheduledTasks.clear();
}
void OutputTaskParser::createOrAmendTask(
Task::TaskType type,
const QString &description,
const QString &originalLine,
bool forceAmend,
const Utils::FilePath &file,
int line,
int column,
const LinkSpecs &linkSpecs)
{
const bool amend = !d->currentTask.isNull() && (forceAmend || isContinuation(originalLine));
if (!amend) {
flush();
d->currentTask = CompileTask(type, description, file, line, column);
d->currentTask.addToDetails(originalLine);
d->currentTask.setOrigin(d->origin);
d->linkSpecs = linkSpecs;
d->lineCount = 1;
return;
}
LinkSpecs adaptedLinkSpecs = linkSpecs;
const int offset = std::accumulate(
d->currentTask.details().cbegin(),
d->currentTask.details().cend(),
0,
[](int total, const QString &line) { return total + line.size() + 1; });
for (LinkSpec &ls : adaptedLinkSpecs)
ls.startPos += offset;
d->linkSpecs << adaptedLinkSpecs;
d->currentTask.addToDetails(originalLine);
// Check whether the new line is more relevant than the previous ones.
if ((!d->currentTask.isError() && type == Task::Error)
|| (!d->currentTask.hasKnownType() && type != Task::Unknown)) {
d->currentTask.setType(type);
d->currentTask.setSummary(description);
if (!file.isEmpty() && !d->targetLinkFixed) {
d->currentTask.setFile(file);
d->currentTask.setLine(line);
d->currentTask.setColumn(column);
}
}
++d->lineCount;
}
void OutputTaskParser::setCurrentTask(const Task &task)
{
flush();
d->currentTask = task;
d->lineCount = 1;
}
Task &OutputTaskParser::currentTask()
{
return d->currentTask;
}
const Task &OutputTaskParser::currentTask() const
{
return d->currentTask;
}
bool OutputTaskParser::isContinuation(const QString &line) const
{
Q_UNUSED(line)
return false;
}
void OutputTaskParser::flush()
{
if (d->currentTask.isNull())
return;
// If there is only one line of details, then it is the line that we generated
// the summary from. Remove it, because it does not add any information.
if (d->currentTask.details().count() == 1)
d->currentTask.clearDetails();
setDetailsFormat(d->currentTask, d->linkSpecs);
Task t = d->currentTask;
d->currentTask.clear();
d->linkSpecs.clear();
scheduleTask(t, d->lineCount, 1);
d->lineCount = 0;
d->targetLinkFixed = false;
}
void OutputTaskParser::setOrigin(const QString &source)
{
d->origin = source;
}
} // namespace ProjectExplorer
|