@opensumi/ide-task 2.21.13 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.js +2 -2
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/parser.js +4 -4
- package/lib/browser/parser.js.map +1 -1
- package/lib/browser/task-config.d.ts +4 -4
- package/lib/browser/task-config.d.ts.map +1 -1
- package/lib/browser/task-config.js +31 -31
- package/lib/browser/task-config.js.map +1 -1
- package/lib/browser/task-executor.d.ts.map +1 -1
- package/lib/browser/task-executor.js +16 -22
- package/lib/browser/task-executor.js.map +1 -1
- package/lib/browser/task-preferences.contribution.js.map +1 -1
- package/lib/browser/task-preferences.provider.d.ts +2 -2
- package/lib/browser/task-preferences.provider.d.ts.map +1 -1
- package/lib/browser/task-preferences.provider.js +2 -2
- package/lib/browser/task-preferences.provider.js.map +1 -1
- package/lib/browser/task.contribution.js.map +1 -1
- package/lib/browser/task.schema.d.ts +2 -2
- package/lib/browser/task.schema.d.ts.map +1 -1
- package/lib/browser/task.schema.js +5 -1
- package/lib/browser/task.schema.js.map +1 -1
- package/lib/browser/task.service.d.ts +3 -1
- package/lib/browser/task.service.d.ts.map +1 -1
- package/lib/browser/task.service.js +10 -5
- package/lib/browser/task.service.js.map +1 -1
- package/lib/browser/terminal-task-system.js +11 -11
- package/lib/browser/terminal-task-system.js.map +1 -1
- package/lib/common/index.d.ts +1 -1
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/task.d.ts +4 -4
- package/lib/common/task.d.ts.map +1 -1
- package/lib/common/task.js +7 -7
- package/lib/common/task.js.map +1 -1
- package/package.json +15 -14
- package/src/browser/index.ts +33 -0
- package/src/browser/parser.ts +944 -0
- package/src/browser/problem-collector.ts +71 -0
- package/src/browser/problem-line-matcher.ts +461 -0
- package/src/browser/task-config.ts +2302 -0
- package/src/browser/task-executor.ts +296 -0
- package/src/browser/task-preferences.contribution.ts +9 -0
- package/src/browser/task-preferences.provider.ts +23 -0
- package/src/browser/task-preferences.ts +14 -0
- package/src/browser/task.contribution.ts +70 -0
- package/src/browser/task.schema.ts +368 -0
- package/src/browser/task.service.ts +504 -0
- package/src/browser/terminal-task-system.ts +340 -0
- package/src/common/index.ts +165 -0
- package/src/common/task.ts +1174 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** ******************************************************************************
|
|
2
|
+
* Copyright (C) 2019 Ericsson and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
// Some code copied and modified from https://github.com/eclipse-theia/theia/tree/v1.14.0/packages/task/src/node/task-problem-collector.ts
|
|
18
|
+
|
|
19
|
+
import { ProblemMatcher, ProblemMatch } from '@opensumi/ide-core-common';
|
|
20
|
+
|
|
21
|
+
import { StartStopLineMatcher, WatchModeLineMatcher, AbstractLineMatcher } from './problem-line-matcher';
|
|
22
|
+
|
|
23
|
+
export function isWatchModeWatcher(matcher: ProblemMatcher): boolean {
|
|
24
|
+
return !!matcher.watching;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class ProblemCollector {
|
|
28
|
+
private lineMatchers: AbstractLineMatcher[] = [];
|
|
29
|
+
|
|
30
|
+
constructor(public problemMatchers: ProblemMatcher[]) {
|
|
31
|
+
for (const matcher of problemMatchers) {
|
|
32
|
+
if (isWatchModeWatcher(matcher)) {
|
|
33
|
+
this.lineMatchers.push(new WatchModeLineMatcher(matcher));
|
|
34
|
+
} else {
|
|
35
|
+
this.lineMatchers.push(new StartStopLineMatcher(matcher));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
processLine(line: string): ProblemMatch[] {
|
|
41
|
+
const markers: ProblemMatch[] = [];
|
|
42
|
+
this.lineMatchers.forEach((lineMatcher) => {
|
|
43
|
+
const match = lineMatcher.match(line);
|
|
44
|
+
if (match) {
|
|
45
|
+
markers.push(match);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return markers;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
isTaskActiveOnStart(): boolean {
|
|
52
|
+
const activeOnStart = this.lineMatchers.some(
|
|
53
|
+
(lineMatcher) => lineMatcher instanceof WatchModeLineMatcher && lineMatcher.activeOnStart,
|
|
54
|
+
);
|
|
55
|
+
return activeOnStart;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
matchBeginMatcher(line: string): boolean {
|
|
59
|
+
const match = this.lineMatchers.some(
|
|
60
|
+
(lineMatcher) => lineMatcher instanceof WatchModeLineMatcher && lineMatcher.matchBegin(line),
|
|
61
|
+
);
|
|
62
|
+
return match;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
matchEndMatcher(line: string): boolean {
|
|
66
|
+
const match = this.lineMatchers.some(
|
|
67
|
+
(lineMatcher) => lineMatcher instanceof WatchModeLineMatcher && lineMatcher.matchEnd(line),
|
|
68
|
+
);
|
|
69
|
+
return match;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
/** ******************************************************************************
|
|
2
|
+
* Copyright (C) 2019 Ericsson and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
// Some code copied and modified from https://github.com/eclipse-theia/theia/tree/v1.14.0/packages/task/src/node/task-abstract-line-matcher.ts
|
|
18
|
+
|
|
19
|
+
import { Diagnostic, DiagnosticSeverity, Range } from 'vscode';
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
isWindows,
|
|
23
|
+
ProblemLocationKind,
|
|
24
|
+
ProblemPattern,
|
|
25
|
+
ProblemMatcher,
|
|
26
|
+
ProblemMatch,
|
|
27
|
+
ProblemMatchData,
|
|
28
|
+
Severity,
|
|
29
|
+
FileLocationKind,
|
|
30
|
+
URI,
|
|
31
|
+
WatchingPattern,
|
|
32
|
+
} from '@opensumi/ide-core-common';
|
|
33
|
+
|
|
34
|
+
const endOfLine: string = isWindows ? '\r\n' : '\n';
|
|
35
|
+
|
|
36
|
+
export interface ProblemData {
|
|
37
|
+
kind?: ProblemLocationKind;
|
|
38
|
+
file?: string;
|
|
39
|
+
location?: string;
|
|
40
|
+
line?: string;
|
|
41
|
+
character?: string;
|
|
42
|
+
endLine?: string;
|
|
43
|
+
endCharacter?: string;
|
|
44
|
+
message?: string;
|
|
45
|
+
severity?: string;
|
|
46
|
+
code?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export abstract class AbstractLineMatcher {
|
|
50
|
+
protected patterns: ProblemPattern[] = [];
|
|
51
|
+
protected activePatternIndex = 0;
|
|
52
|
+
protected activePattern: ProblemPattern | undefined;
|
|
53
|
+
protected cachedProblemData: ProblemData;
|
|
54
|
+
|
|
55
|
+
constructor(protected matcher: ProblemMatcher) {
|
|
56
|
+
if (Array.isArray(matcher.pattern)) {
|
|
57
|
+
this.patterns = matcher.pattern;
|
|
58
|
+
} else {
|
|
59
|
+
this.patterns = [matcher.pattern];
|
|
60
|
+
}
|
|
61
|
+
this.cachedProblemData = this.getEmptyProblemData();
|
|
62
|
+
|
|
63
|
+
if (this.patterns.slice(0, this.patternCount - 1).some((p) => !!p.loop)) {
|
|
64
|
+
// eslint-disable-next-line no-console
|
|
65
|
+
console.error('Problem Matcher: Only the last pattern can loop');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Finds the problem identified by this line matcher.
|
|
71
|
+
*
|
|
72
|
+
* @param line the line of text to find the problem from
|
|
73
|
+
* @return the identified problem. If the problem is not found, `undefined` is returned.
|
|
74
|
+
*/
|
|
75
|
+
abstract match(line: string): ProblemMatch | undefined;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Number of problem patterns that the line matcher uses.
|
|
79
|
+
*/
|
|
80
|
+
get patternCount(): number {
|
|
81
|
+
return this.patterns.length;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected getEmptyProblemData(): ProblemData {
|
|
85
|
+
return Object.create(null) as ProblemData;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
protected fillProblemData(
|
|
89
|
+
data: ProblemData | null,
|
|
90
|
+
pattern: ProblemPattern,
|
|
91
|
+
matches: RegExpExecArray,
|
|
92
|
+
): data is ProblemData {
|
|
93
|
+
if (data) {
|
|
94
|
+
this.fillProperty(data, 'file', pattern, matches, true);
|
|
95
|
+
this.appendProperty(data, 'message', pattern, matches, true);
|
|
96
|
+
this.fillProperty(data, 'code', pattern, matches, true);
|
|
97
|
+
this.fillProperty(data, 'severity', pattern, matches, true);
|
|
98
|
+
this.fillProperty(data, 'location', pattern, matches, true);
|
|
99
|
+
this.fillProperty(data, 'line', pattern, matches);
|
|
100
|
+
this.fillProperty(data, 'character', pattern, matches);
|
|
101
|
+
this.fillProperty(data, 'endLine', pattern, matches);
|
|
102
|
+
this.fillProperty(data, 'endCharacter', pattern, matches);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private appendProperty(
|
|
109
|
+
data: ProblemData,
|
|
110
|
+
property: keyof ProblemData,
|
|
111
|
+
pattern: ProblemPattern,
|
|
112
|
+
matches: RegExpExecArray,
|
|
113
|
+
trim = false,
|
|
114
|
+
): void {
|
|
115
|
+
const patternProperty = pattern[property];
|
|
116
|
+
if (data[property] === undefined) {
|
|
117
|
+
this.fillProperty(data, property, pattern, matches, trim);
|
|
118
|
+
} else if (patternProperty !== undefined && patternProperty < matches.length) {
|
|
119
|
+
let value = matches[patternProperty];
|
|
120
|
+
if (trim) {
|
|
121
|
+
value = value.trim();
|
|
122
|
+
}
|
|
123
|
+
(data[property] as string) += endOfLine + value;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private fillProperty(
|
|
128
|
+
data: ProblemData,
|
|
129
|
+
property: keyof ProblemData,
|
|
130
|
+
pattern: ProblemPattern,
|
|
131
|
+
matches: RegExpExecArray,
|
|
132
|
+
trim = false,
|
|
133
|
+
): void {
|
|
134
|
+
const patternAtProperty = pattern[property];
|
|
135
|
+
if (data[property] === undefined && patternAtProperty !== undefined && patternAtProperty < matches.length) {
|
|
136
|
+
let value = matches[patternAtProperty];
|
|
137
|
+
if (value !== undefined) {
|
|
138
|
+
if (trim) {
|
|
139
|
+
value = value.trim();
|
|
140
|
+
}
|
|
141
|
+
(data[property] as string) = value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
protected getMarkerMatch(data: ProblemData): ProblemMatch | undefined {
|
|
147
|
+
try {
|
|
148
|
+
const location = this.getLocation(data);
|
|
149
|
+
if (data.file && location && data.message) {
|
|
150
|
+
const marker: Diagnostic = {
|
|
151
|
+
severity: this.getSeverity(data),
|
|
152
|
+
range: location,
|
|
153
|
+
message: data.message,
|
|
154
|
+
};
|
|
155
|
+
if (data.code !== undefined) {
|
|
156
|
+
marker.code = data.code;
|
|
157
|
+
}
|
|
158
|
+
if (this.matcher.source !== undefined) {
|
|
159
|
+
marker.source = this.matcher.source;
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
description: this.matcher,
|
|
163
|
+
resource: this.getResource(data.file, this.matcher),
|
|
164
|
+
marker,
|
|
165
|
+
} as ProblemMatchData;
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
description: this.matcher,
|
|
169
|
+
};
|
|
170
|
+
} catch (err) {
|
|
171
|
+
// eslint-disable-next-line no-console
|
|
172
|
+
console.error(`Failed to convert problem data into match: ${JSON.stringify(data)}`);
|
|
173
|
+
}
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private getLocation(data: ProblemData): Range | null {
|
|
178
|
+
if (data.kind === ProblemLocationKind.File) {
|
|
179
|
+
return this.createRange(0, 0, 0, 0);
|
|
180
|
+
}
|
|
181
|
+
if (data.location) {
|
|
182
|
+
return this.parseLocationInfo(data.location);
|
|
183
|
+
}
|
|
184
|
+
if (!data.line) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
const startLine = parseInt(data.line, 10);
|
|
188
|
+
const startColumn = data.character ? parseInt(data.character, 10) : undefined;
|
|
189
|
+
const endLine = data.endLine ? parseInt(data.endLine, 10) : undefined;
|
|
190
|
+
const endColumn = data.endCharacter ? parseInt(data.endCharacter, 10) : undefined;
|
|
191
|
+
return this.createRange(startLine, startColumn, endLine, endColumn);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private parseLocationInfo(value: string): Range | null {
|
|
195
|
+
if (!value || !value.match(/(\d+|\d+,\d+|\d+,\d+,\d+,\d+)/)) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
const parts = value.split(',');
|
|
199
|
+
const startLine = parseInt(parts[0], 10);
|
|
200
|
+
const startColumn = parts.length > 1 ? parseInt(parts[1], 10) : undefined;
|
|
201
|
+
if (parts.length > 3) {
|
|
202
|
+
return this.createRange(startLine, startColumn, parseInt(parts[2], 10), parseInt(parts[3], 10));
|
|
203
|
+
} else {
|
|
204
|
+
return this.createRange(startLine, startColumn, undefined, undefined);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private createRange(
|
|
209
|
+
startLine: number,
|
|
210
|
+
startColumn: number | undefined,
|
|
211
|
+
endLine: number | undefined,
|
|
212
|
+
endColumn: number | undefined,
|
|
213
|
+
): Range {
|
|
214
|
+
let range: Range;
|
|
215
|
+
if (startColumn !== undefined) {
|
|
216
|
+
if (endColumn !== undefined) {
|
|
217
|
+
range = {
|
|
218
|
+
start: { line: startLine, character: startColumn },
|
|
219
|
+
end: { line: endLine || startLine, character: endColumn },
|
|
220
|
+
} as Range;
|
|
221
|
+
} else {
|
|
222
|
+
range = {
|
|
223
|
+
start: { line: startLine, character: startColumn },
|
|
224
|
+
end: { line: startLine, character: startColumn },
|
|
225
|
+
} as Range;
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
range = {
|
|
229
|
+
start: { line: startLine, character: 1 },
|
|
230
|
+
end: { line: startLine, character: Number.MAX_VALUE },
|
|
231
|
+
} as Range;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// range indexes should be zero-based
|
|
235
|
+
return {
|
|
236
|
+
start: {
|
|
237
|
+
line: this.getZeroBasedRangeIndex(range.start.line),
|
|
238
|
+
character: this.getZeroBasedRangeIndex(range.start.character),
|
|
239
|
+
},
|
|
240
|
+
end: {
|
|
241
|
+
line: this.getZeroBasedRangeIndex(range.end.line),
|
|
242
|
+
character: this.getZeroBasedRangeIndex(range.end.character),
|
|
243
|
+
},
|
|
244
|
+
} as Range;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private getZeroBasedRangeIndex(ind: number): number {
|
|
248
|
+
return ind === 0 ? ind : ind - 1;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private getSeverity(data: ProblemData): DiagnosticSeverity {
|
|
252
|
+
let result: Severity | null = null;
|
|
253
|
+
if (data.severity) {
|
|
254
|
+
const value = data.severity;
|
|
255
|
+
if (value) {
|
|
256
|
+
result = Severity.fromValue(value);
|
|
257
|
+
if (result === Severity.Ignore) {
|
|
258
|
+
if (value === 'E') {
|
|
259
|
+
result = Severity.Error;
|
|
260
|
+
} else if (value === 'W') {
|
|
261
|
+
result = Severity.Warning;
|
|
262
|
+
} else if (value === 'I') {
|
|
263
|
+
result = Severity.Info;
|
|
264
|
+
} else if (value.toLowerCase() === 'hint') {
|
|
265
|
+
result = Severity.Info;
|
|
266
|
+
} else if (value.toLowerCase() === 'note') {
|
|
267
|
+
result = Severity.Info;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (result === null || result === Severity.Ignore) {
|
|
273
|
+
if (typeof this.matcher.severity === 'string') {
|
|
274
|
+
result = Severity.fromValue(this.matcher.severity) || Severity.Error;
|
|
275
|
+
} else {
|
|
276
|
+
result = this.matcher.severity || Severity.Error;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return Severity.toDiagnosticSeverity(result as Severity);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private getResource(filename: string, matcher: ProblemMatcher): URI {
|
|
283
|
+
const kind = matcher.fileLocation;
|
|
284
|
+
let fullPath: string | undefined;
|
|
285
|
+
if (kind === FileLocationKind.Absolute) {
|
|
286
|
+
fullPath = filename;
|
|
287
|
+
} else if (kind === FileLocationKind.Relative && matcher.filePrefix) {
|
|
288
|
+
let relativeFileName = filename.replace(/\\/g, '/');
|
|
289
|
+
if (relativeFileName.startsWith('./')) {
|
|
290
|
+
relativeFileName = relativeFileName.slice(2);
|
|
291
|
+
}
|
|
292
|
+
fullPath = new URI(matcher.filePrefix).resolve(relativeFileName).path.toString();
|
|
293
|
+
}
|
|
294
|
+
if (fullPath === undefined) {
|
|
295
|
+
throw new Error(
|
|
296
|
+
'FileLocationKind is not actionable. Does the matcher have a filePrefix? This should never happen.',
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
fullPath = fullPath.replace(/\\/g, '/');
|
|
300
|
+
if (fullPath[0] !== '/') {
|
|
301
|
+
fullPath = '/' + fullPath;
|
|
302
|
+
}
|
|
303
|
+
if (matcher.uriProvider !== undefined) {
|
|
304
|
+
return matcher.uriProvider(fullPath);
|
|
305
|
+
} else {
|
|
306
|
+
return URI.file(fullPath);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
protected resetActivePatternIndex(defaultIndex?: number): void {
|
|
311
|
+
if (defaultIndex === undefined) {
|
|
312
|
+
defaultIndex = 0;
|
|
313
|
+
}
|
|
314
|
+
this.activePatternIndex = defaultIndex;
|
|
315
|
+
this.activePattern = this.patterns[defaultIndex];
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
protected nextProblemPattern(): void {
|
|
319
|
+
this.activePatternIndex++;
|
|
320
|
+
if (this.activePatternIndex > this.patternCount - 1) {
|
|
321
|
+
this.resetActivePatternIndex();
|
|
322
|
+
} else {
|
|
323
|
+
this.activePattern = this.patterns[this.activePatternIndex];
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
protected doOneLineMatch(line: string): boolean {
|
|
328
|
+
if (this.activePattern) {
|
|
329
|
+
const regexp = new RegExp(this.activePattern.regexp!);
|
|
330
|
+
const regexMatches = regexp.exec(line);
|
|
331
|
+
if (regexMatches) {
|
|
332
|
+
if (this.activePattern.kind !== undefined && this.cachedProblemData.kind !== undefined) {
|
|
333
|
+
this.cachedProblemData.kind = this.activePattern.kind;
|
|
334
|
+
}
|
|
335
|
+
return this.fillProblemData(this.cachedProblemData, this.activePattern, regexMatches);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// check if active pattern is the last pattern
|
|
342
|
+
protected isUsingTheLastPattern(): boolean {
|
|
343
|
+
return this.patternCount > 0 && this.activePatternIndex === this.patternCount - 1;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
protected isLastPatternLoop(): boolean {
|
|
347
|
+
return this.patternCount > 0 && !!this.patterns[this.patternCount - 1].loop;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
protected resetCachedProblemData(): void {
|
|
351
|
+
this.cachedProblemData = this.getEmptyProblemData();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export class StartStopLineMatcher extends AbstractLineMatcher {
|
|
356
|
+
constructor(protected matcher: ProblemMatcher) {
|
|
357
|
+
super(matcher);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Finds the problem identified by this line matcher.
|
|
362
|
+
*
|
|
363
|
+
* @param line the line of text to find the problem from
|
|
364
|
+
* @return the identified problem. If the problem is not found, `undefined` is returned.
|
|
365
|
+
*/
|
|
366
|
+
match(line: string): ProblemMatch | undefined {
|
|
367
|
+
if (!this.activePattern) {
|
|
368
|
+
this.resetActivePatternIndex();
|
|
369
|
+
}
|
|
370
|
+
if (this.activePattern) {
|
|
371
|
+
const originalProblemData = Object.assign(this.getEmptyProblemData(), this.cachedProblemData);
|
|
372
|
+
const foundMatch = this.doOneLineMatch(line);
|
|
373
|
+
if (foundMatch) {
|
|
374
|
+
if (this.isUsingTheLastPattern()) {
|
|
375
|
+
const matchResult = this.getMarkerMatch(this.cachedProblemData);
|
|
376
|
+
if (this.isLastPatternLoop()) {
|
|
377
|
+
this.cachedProblemData = originalProblemData;
|
|
378
|
+
} else {
|
|
379
|
+
this.resetCachedProblemData();
|
|
380
|
+
this.resetActivePatternIndex();
|
|
381
|
+
}
|
|
382
|
+
return matchResult;
|
|
383
|
+
} else {
|
|
384
|
+
this.nextProblemPattern();
|
|
385
|
+
}
|
|
386
|
+
} else {
|
|
387
|
+
this.resetCachedProblemData();
|
|
388
|
+
if (this.activePatternIndex !== 0) {
|
|
389
|
+
// if no match, use the first pattern to parse the same line
|
|
390
|
+
this.resetActivePatternIndex();
|
|
391
|
+
return this.match(line);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return undefined;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export class WatchModeLineMatcher extends StartStopLineMatcher {
|
|
400
|
+
private beginsPattern: WatchingPattern;
|
|
401
|
+
private endsPattern: WatchingPattern;
|
|
402
|
+
activeOnStart = false;
|
|
403
|
+
|
|
404
|
+
constructor(protected matcher: ProblemMatcher) {
|
|
405
|
+
super(matcher);
|
|
406
|
+
this.beginsPattern = matcher.watching!.beginsPattern;
|
|
407
|
+
this.endsPattern = matcher.watching!.endsPattern;
|
|
408
|
+
this.activeOnStart = matcher.watching!.activeOnStart === true;
|
|
409
|
+
this.resetActivePatternIndex(this.activeOnStart ? 0 : -1);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Finds the problem identified by this line matcher.
|
|
414
|
+
*
|
|
415
|
+
* @param line the line of text to find the problem from
|
|
416
|
+
* @return the identified problem. If the problem is not found, `undefined` is returned.
|
|
417
|
+
*/
|
|
418
|
+
match(line: string): ProblemMatch | undefined {
|
|
419
|
+
if (this.activeOnStart) {
|
|
420
|
+
this.activeOnStart = false;
|
|
421
|
+
this.resetActivePatternIndex(0);
|
|
422
|
+
this.resetCachedProblemData();
|
|
423
|
+
return super.match(line);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (this.matchBegin(line)) {
|
|
427
|
+
const beginsPatternMatch = this.getMarkerMatch(this.cachedProblemData);
|
|
428
|
+
this.resetCachedProblemData();
|
|
429
|
+
return beginsPatternMatch;
|
|
430
|
+
}
|
|
431
|
+
if (this.matchEnd(line)) {
|
|
432
|
+
this.resetCachedProblemData();
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
if (this.activePattern) {
|
|
436
|
+
return super.match(line);
|
|
437
|
+
}
|
|
438
|
+
return undefined;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
matchBegin(line: string): boolean {
|
|
442
|
+
const beginRegexp = new RegExp(this.beginsPattern.regexp);
|
|
443
|
+
const regexMatches = beginRegexp.exec(line);
|
|
444
|
+
if (regexMatches) {
|
|
445
|
+
this.fillProblemData(this.cachedProblemData, this.beginsPattern, regexMatches);
|
|
446
|
+
this.resetActivePatternIndex(0);
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
matchEnd(line: string): boolean {
|
|
453
|
+
const endRegexp = new RegExp(this.endsPattern.regexp);
|
|
454
|
+
const match = endRegexp.exec(line);
|
|
455
|
+
if (match) {
|
|
456
|
+
this.resetActivePatternIndex(-1);
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
}
|