-
Notifications
You must be signed in to change notification settings - Fork 29.5k
/
problemMatcher.ts
2011 lines (1813 loc) · 63 KB
/
problemMatcher.ts
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from 'vs/nls';
import * as Objects from 'vs/base/common/objects';
import * as Strings from 'vs/base/common/strings';
import * as Assert from 'vs/base/common/assert';
import { join, normalize } from 'vs/base/common/path';
import * as Types from 'vs/base/common/types';
import * as UUID from 'vs/base/common/uuid';
import * as Platform from 'vs/base/common/platform';
import Severity from 'vs/base/common/severity';
import { URI } from 'vs/base/common/uri';
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { ValidationStatus, ValidationState, IProblemReporter, Parser } from 'vs/base/common/parsers';
import { IStringDictionary } from 'vs/base/common/collections';
import { asArray } from 'vs/base/common/arrays';
import { Schemas as NetworkSchemas } from 'vs/base/common/network';
import { IMarkerData, MarkerSeverity } from 'vs/platform/markers/common/markers';
import { ExtensionsRegistry, ExtensionMessageCollector } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { Event, Emitter } from 'vs/base/common/event';
import { FileType, IFileService, IFileStatWithPartialMetadata, IFileSystemProvider } from 'vs/platform/files/common/files';
export enum FileLocationKind {
Default,
Relative,
Absolute,
AutoDetect,
Search
}
export module FileLocationKind {
export function fromString(value: string): FileLocationKind | undefined {
value = value.toLowerCase();
if (value === 'absolute') {
return FileLocationKind.Absolute;
} else if (value === 'relative') {
return FileLocationKind.Relative;
} else if (value === 'autodetect') {
return FileLocationKind.AutoDetect;
} else if (value === 'search') {
return FileLocationKind.Search;
} else {
return undefined;
}
}
}
export enum ProblemLocationKind {
File,
Location
}
export module ProblemLocationKind {
export function fromString(value: string): ProblemLocationKind | undefined {
value = value.toLowerCase();
if (value === 'file') {
return ProblemLocationKind.File;
} else if (value === 'location') {
return ProblemLocationKind.Location;
} else {
return undefined;
}
}
}
export interface IProblemPattern {
regexp: RegExp;
kind?: ProblemLocationKind;
file?: number;
message?: number;
location?: number;
line?: number;
character?: number;
endLine?: number;
endCharacter?: number;
code?: number;
severity?: number;
loop?: boolean;
}
export interface INamedProblemPattern extends IProblemPattern {
name: string;
}
export type MultiLineProblemPattern = IProblemPattern[];
export interface IWatchingPattern {
regexp: RegExp;
file?: number;
}
export interface IWatchingMatcher {
activeOnStart: boolean;
beginsPattern: IWatchingPattern;
endsPattern: IWatchingPattern;
}
export enum ApplyToKind {
allDocuments,
openDocuments,
closedDocuments
}
export module ApplyToKind {
export function fromString(value: string): ApplyToKind | undefined {
value = value.toLowerCase();
if (value === 'alldocuments') {
return ApplyToKind.allDocuments;
} else if (value === 'opendocuments') {
return ApplyToKind.openDocuments;
} else if (value === 'closeddocuments') {
return ApplyToKind.closedDocuments;
} else {
return undefined;
}
}
}
export interface ProblemMatcher {
owner: string;
source?: string;
applyTo: ApplyToKind;
fileLocation: FileLocationKind;
filePrefix?: string | Config.SearchFileLocationArgs;
pattern: IProblemPattern | IProblemPattern[];
severity?: Severity;
watching?: IWatchingMatcher;
uriProvider?: (path: string) => URI;
}
export interface INamedProblemMatcher extends ProblemMatcher {
name: string;
label: string;
deprecated?: boolean;
}
export interface INamedMultiLineProblemPattern {
name: string;
label: string;
patterns: MultiLineProblemPattern;
}
export function isNamedProblemMatcher(value: ProblemMatcher | undefined): value is INamedProblemMatcher {
return value && Types.isString((<INamedProblemMatcher>value).name) ? true : false;
}
interface ILocation {
startLineNumber: number;
startCharacter: number;
endLineNumber: number;
endCharacter: number;
}
interface IProblemData {
kind?: ProblemLocationKind;
file?: string;
location?: string;
line?: string;
character?: string;
endLine?: string;
endCharacter?: string;
message?: string;
severity?: string;
code?: string;
}
export interface IProblemMatch {
resource: Promise<URI>;
marker: IMarkerData;
description: ProblemMatcher;
}
export interface IHandleResult {
match: IProblemMatch | null;
continue: boolean;
}
export async function getResource(filename: string, matcher: ProblemMatcher, fileService?: IFileService): Promise<URI> {
const kind = matcher.fileLocation;
let fullPath: string | undefined;
if (kind === FileLocationKind.Absolute) {
fullPath = filename;
} else if ((kind === FileLocationKind.Relative) && matcher.filePrefix && Types.isString(matcher.filePrefix)) {
fullPath = join(matcher.filePrefix, filename);
} else if (kind === FileLocationKind.AutoDetect) {
const matcherClone = Objects.deepClone(matcher);
matcherClone.fileLocation = FileLocationKind.Relative;
if (fileService) {
const relative = await getResource(filename, matcherClone);
let stat: IFileStatWithPartialMetadata | undefined = undefined;
try {
stat = await fileService.stat(relative);
} catch (ex) {
// Do nothing, we just need to catch file resolution errors.
}
if (stat) {
return relative;
}
}
matcherClone.fileLocation = FileLocationKind.Absolute;
return getResource(filename, matcherClone);
} else if (kind === FileLocationKind.Search && fileService) {
const fsProvider = fileService.getProvider(NetworkSchemas.file);
if (fsProvider) {
const uri = await searchForFileLocation(filename, fsProvider, matcher.filePrefix as Config.SearchFileLocationArgs);
fullPath = uri?.path;
}
if (!fullPath) {
const absoluteMatcher = Objects.deepClone(matcher);
absoluteMatcher.fileLocation = FileLocationKind.Absolute;
return getResource(filename, absoluteMatcher);
}
}
if (fullPath === undefined) {
throw new Error('FileLocationKind is not actionable. Does the matcher have a filePrefix? This should never happen.');
}
fullPath = normalize(fullPath);
fullPath = fullPath.replace(/\\/g, '/');
if (fullPath[0] !== '/') {
fullPath = '/' + fullPath;
}
if (matcher.uriProvider !== undefined) {
return matcher.uriProvider(fullPath);
} else {
return URI.file(fullPath);
}
}
async function searchForFileLocation(filename: string, fsProvider: IFileSystemProvider, args: Config.SearchFileLocationArgs): Promise<URI | undefined> {
const exclusions = new Set(asArray(args.exclude || []).map(x => URI.file(x).path));
async function search(dir: URI): Promise<URI | undefined> {
if (exclusions.has(dir.path)) {
return undefined;
}
const entries = await fsProvider.readdir(dir);
const subdirs: URI[] = [];
for (const [name, fileType] of entries) {
if (fileType === FileType.Directory) {
subdirs.push(URI.joinPath(dir, name));
continue;
}
if (fileType === FileType.File) {
/**
* Note that sometimes the given `filename` could be a relative
* path (not just the "name.ext" part). For example, the
* `filename` can be "/subdir/name.ext". So, just comparing
* `name` as `filename` is not sufficient. The workaround here
* is to form the URI with `dir` and `name` and check if it ends
* with the given `filename`.
*/
const fullUri = URI.joinPath(dir, name);
if (fullUri.path.endsWith(filename)) {
return fullUri;
}
}
}
for (const subdir of subdirs) {
const result = await search(subdir);
if (result) {
return result;
}
}
return undefined;
}
for (const dir of asArray(args.include || [])) {
const hit = await search(URI.file(dir));
if (hit) {
return hit;
}
}
return undefined;
}
export interface ILineMatcher {
matchLength: number;
next(line: string): IProblemMatch | null;
handle(lines: string[], start?: number): IHandleResult;
}
export function createLineMatcher(matcher: ProblemMatcher, fileService?: IFileService): ILineMatcher {
const pattern = matcher.pattern;
if (Array.isArray(pattern)) {
return new MultiLineMatcher(matcher, fileService);
} else {
return new SingleLineMatcher(matcher, fileService);
}
}
const endOfLine: string = Platform.OS === Platform.OperatingSystem.Windows ? '\r\n' : '\n';
abstract class AbstractLineMatcher implements ILineMatcher {
private matcher: ProblemMatcher;
private fileService?: IFileService;
constructor(matcher: ProblemMatcher, fileService?: IFileService) {
this.matcher = matcher;
this.fileService = fileService;
}
public handle(lines: string[], start: number = 0): IHandleResult {
return { match: null, continue: false };
}
public next(line: string): IProblemMatch | null {
return null;
}
public abstract get matchLength(): number;
protected fillProblemData(data: IProblemData | undefined, pattern: IProblemPattern, matches: RegExpExecArray): data is IProblemData {
if (data) {
this.fillProperty(data, 'file', pattern, matches, true);
this.appendProperty(data, 'message', pattern, matches, true);
this.fillProperty(data, 'code', pattern, matches, true);
this.fillProperty(data, 'severity', pattern, matches, true);
this.fillProperty(data, 'location', pattern, matches, true);
this.fillProperty(data, 'line', pattern, matches);
this.fillProperty(data, 'character', pattern, matches);
this.fillProperty(data, 'endLine', pattern, matches);
this.fillProperty(data, 'endCharacter', pattern, matches);
return true;
} else {
return false;
}
}
private appendProperty(data: IProblemData, property: keyof IProblemData, pattern: IProblemPattern, matches: RegExpExecArray, trim: boolean = false): void {
const patternProperty = pattern[property];
if (Types.isUndefined(data[property])) {
this.fillProperty(data, property, pattern, matches, trim);
}
else if (!Types.isUndefined(patternProperty) && patternProperty < matches.length) {
let value = matches[patternProperty];
if (trim) {
value = Strings.trim(value)!;
}
(data as any)[property] += endOfLine + value;
}
}
private fillProperty(data: IProblemData, property: keyof IProblemData, pattern: IProblemPattern, matches: RegExpExecArray, trim: boolean = false): void {
const patternAtProperty = pattern[property];
if (Types.isUndefined(data[property]) && !Types.isUndefined(patternAtProperty) && patternAtProperty < matches.length) {
let value = matches[patternAtProperty];
if (value !== undefined) {
if (trim) {
value = Strings.trim(value)!;
}
(data as any)[property] = value;
}
}
}
protected getMarkerMatch(data: IProblemData): IProblemMatch | undefined {
try {
const location = this.getLocation(data);
if (data.file && location && data.message) {
const marker: IMarkerData = {
severity: this.getSeverity(data),
startLineNumber: location.startLineNumber,
startColumn: location.startCharacter,
endLineNumber: location.endLineNumber,
endColumn: location.endCharacter,
message: data.message
};
if (data.code !== undefined) {
marker.code = data.code;
}
if (this.matcher.source !== undefined) {
marker.source = this.matcher.source;
}
return {
description: this.matcher,
resource: this.getResource(data.file),
marker: marker
};
}
} catch (err) {
console.error(`Failed to convert problem data into match: ${JSON.stringify(data)}`);
}
return undefined;
}
protected getResource(filename: string): Promise<URI> {
return getResource(filename, this.matcher, this.fileService);
}
private getLocation(data: IProblemData): ILocation | null {
if (data.kind === ProblemLocationKind.File) {
return this.createLocation(0, 0, 0, 0);
}
if (data.location) {
return this.parseLocationInfo(data.location);
}
if (!data.line) {
return null;
}
const startLine = parseInt(data.line);
const startColumn = data.character ? parseInt(data.character) : undefined;
const endLine = data.endLine ? parseInt(data.endLine) : undefined;
const endColumn = data.endCharacter ? parseInt(data.endCharacter) : undefined;
return this.createLocation(startLine, startColumn, endLine, endColumn);
}
private parseLocationInfo(value: string): ILocation | null {
if (!value || !value.match(/(\d+|\d+,\d+|\d+,\d+,\d+,\d+)/)) {
return null;
}
const parts = value.split(',');
const startLine = parseInt(parts[0]);
const startColumn = parts.length > 1 ? parseInt(parts[1]) : undefined;
if (parts.length > 3) {
return this.createLocation(startLine, startColumn, parseInt(parts[2]), parseInt(parts[3]));
} else {
return this.createLocation(startLine, startColumn, undefined, undefined);
}
}
private createLocation(startLine: number, startColumn: number | undefined, endLine: number | undefined, endColumn: number | undefined): ILocation {
if (startColumn !== undefined && endColumn !== undefined) {
return { startLineNumber: startLine, startCharacter: startColumn, endLineNumber: endLine || startLine, endCharacter: endColumn };
}
if (startColumn !== undefined) {
return { startLineNumber: startLine, startCharacter: startColumn, endLineNumber: startLine, endCharacter: startColumn };
}
return { startLineNumber: startLine, startCharacter: 1, endLineNumber: startLine, endCharacter: 2 ** 31 - 1 }; // See https://github.com/microsoft/vscode/issues/80288#issuecomment-650636442 for discussion
}
private getSeverity(data: IProblemData): MarkerSeverity {
let result: Severity | null = null;
if (data.severity) {
const value = data.severity;
if (value) {
result = Severity.fromValue(value);
if (result === Severity.Ignore) {
if (value === 'E') {
result = Severity.Error;
} else if (value === 'W') {
result = Severity.Warning;
} else if (value === 'I') {
result = Severity.Info;
} else if (Strings.equalsIgnoreCase(value, 'hint')) {
result = Severity.Info;
} else if (Strings.equalsIgnoreCase(value, 'note')) {
result = Severity.Info;
}
}
}
}
if (result === null || result === Severity.Ignore) {
result = this.matcher.severity || Severity.Error;
}
return MarkerSeverity.fromSeverity(result);
}
}
class SingleLineMatcher extends AbstractLineMatcher {
private pattern: IProblemPattern;
constructor(matcher: ProblemMatcher, fileService?: IFileService) {
super(matcher, fileService);
this.pattern = <IProblemPattern>matcher.pattern;
}
public get matchLength(): number {
return 1;
}
public override handle(lines: string[], start: number = 0): IHandleResult {
Assert.ok(lines.length - start === 1);
const data: IProblemData = Object.create(null);
if (this.pattern.kind !== undefined) {
data.kind = this.pattern.kind;
}
const matches = this.pattern.regexp.exec(lines[start]);
if (matches) {
this.fillProblemData(data, this.pattern, matches);
const match = this.getMarkerMatch(data);
if (match) {
return { match: match, continue: false };
}
}
return { match: null, continue: false };
}
public override next(line: string): IProblemMatch | null {
return null;
}
}
class MultiLineMatcher extends AbstractLineMatcher {
private patterns: IProblemPattern[];
private data: IProblemData | undefined;
constructor(matcher: ProblemMatcher, fileService?: IFileService) {
super(matcher, fileService);
this.patterns = <IProblemPattern[]>matcher.pattern;
}
public get matchLength(): number {
return this.patterns.length;
}
public override handle(lines: string[], start: number = 0): IHandleResult {
Assert.ok(lines.length - start === this.patterns.length);
this.data = Object.create(null);
let data = this.data!;
data.kind = this.patterns[0].kind;
for (let i = 0; i < this.patterns.length; i++) {
const pattern = this.patterns[i];
const matches = pattern.regexp.exec(lines[i + start]);
if (!matches) {
return { match: null, continue: false };
} else {
// Only the last pattern can loop
if (pattern.loop && i === this.patterns.length - 1) {
data = Objects.deepClone(data);
}
this.fillProblemData(data, pattern, matches);
}
}
const loop = !!this.patterns[this.patterns.length - 1].loop;
if (!loop) {
this.data = undefined;
}
const markerMatch = data ? this.getMarkerMatch(data) : null;
return { match: markerMatch ? markerMatch : null, continue: loop };
}
public override next(line: string): IProblemMatch | null {
const pattern = this.patterns[this.patterns.length - 1];
Assert.ok(pattern.loop === true && this.data !== null);
const matches = pattern.regexp.exec(line);
if (!matches) {
this.data = undefined;
return null;
}
const data = Objects.deepClone(this.data);
let problemMatch: IProblemMatch | undefined;
if (this.fillProblemData(data, pattern, matches)) {
problemMatch = this.getMarkerMatch(data);
}
return problemMatch ? problemMatch : null;
}
}
export namespace Config {
export interface IProblemPattern {
/**
* The regular expression to find a problem in the console output of an
* executed task.
*/
regexp?: string;
/**
* Whether the pattern matches a whole file, or a location (file/line)
*
* The default is to match for a location. Only valid on the
* first problem pattern in a multi line problem matcher.
*/
kind?: string;
/**
* The match group index of the filename.
* If omitted 1 is used.
*/
file?: number;
/**
* The match group index of the problem's location. Valid location
* patterns are: (line), (line,column) and (startLine,startColumn,endLine,endColumn).
* If omitted the line and column properties are used.
*/
location?: number;
/**
* The match group index of the problem's line in the source file.
*
* Defaults to 2.
*/
line?: number;
/**
* The match group index of the problem's column in the source file.
*
* Defaults to 3.
*/
column?: number;
/**
* The match group index of the problem's end line in the source file.
*
* Defaults to undefined. No end line is captured.
*/
endLine?: number;
/**
* The match group index of the problem's end column in the source file.
*
* Defaults to undefined. No end column is captured.
*/
endColumn?: number;
/**
* The match group index of the problem's severity.
*
* Defaults to undefined. In this case the problem matcher's severity
* is used.
*/
severity?: number;
/**
* The match group index of the problem's code.
*
* Defaults to undefined. No code is captured.
*/
code?: number;
/**
* The match group index of the message. If omitted it defaults
* to 4 if location is specified. Otherwise it defaults to 5.
*/
message?: number;
/**
* Specifies if the last pattern in a multi line problem matcher should
* loop as long as it does match a line consequently. Only valid on the
* last problem pattern in a multi line problem matcher.
*/
loop?: boolean;
}
export interface ICheckedProblemPattern extends IProblemPattern {
/**
* The regular expression to find a problem in the console output of an
* executed task.
*/
regexp: string;
}
export namespace CheckedProblemPattern {
export function is(value: any): value is ICheckedProblemPattern {
const candidate: IProblemPattern = value as IProblemPattern;
return candidate && Types.isString(candidate.regexp);
}
}
export interface INamedProblemPattern extends IProblemPattern {
/**
* The name of the problem pattern.
*/
name: string;
/**
* A human readable label
*/
label?: string;
}
export namespace NamedProblemPattern {
export function is(value: any): value is INamedProblemPattern {
const candidate: INamedProblemPattern = value as INamedProblemPattern;
return candidate && Types.isString(candidate.name);
}
}
export interface INamedCheckedProblemPattern extends INamedProblemPattern {
/**
* The regular expression to find a problem in the console output of an
* executed task.
*/
regexp: string;
}
export namespace NamedCheckedProblemPattern {
export function is(value: any): value is INamedCheckedProblemPattern {
const candidate: INamedProblemPattern = value as INamedProblemPattern;
return candidate && NamedProblemPattern.is(candidate) && Types.isString(candidate.regexp);
}
}
export type MultiLineProblemPattern = IProblemPattern[];
export namespace MultiLineProblemPattern {
export function is(value: any): value is MultiLineProblemPattern {
return value && Array.isArray(value);
}
}
export type MultiLineCheckedProblemPattern = ICheckedProblemPattern[];
export namespace MultiLineCheckedProblemPattern {
export function is(value: any): value is MultiLineCheckedProblemPattern {
if (!MultiLineProblemPattern.is(value)) {
return false;
}
for (const element of value) {
if (!Config.CheckedProblemPattern.is(element)) {
return false;
}
}
return true;
}
}
export interface INamedMultiLineCheckedProblemPattern {
/**
* The name of the problem pattern.
*/
name: string;
/**
* A human readable label
*/
label?: string;
/**
* The actual patterns
*/
patterns: MultiLineCheckedProblemPattern;
}
export namespace NamedMultiLineCheckedProblemPattern {
export function is(value: any): value is INamedMultiLineCheckedProblemPattern {
const candidate = value as INamedMultiLineCheckedProblemPattern;
return candidate && Types.isString(candidate.name) && Array.isArray(candidate.patterns) && MultiLineCheckedProblemPattern.is(candidate.patterns);
}
}
export type NamedProblemPatterns = (Config.INamedProblemPattern | Config.INamedMultiLineCheckedProblemPattern)[];
/**
* A watching pattern
*/
export interface IWatchingPattern {
/**
* The actual regular expression
*/
regexp?: string;
/**
* The match group index of the filename. If provided the expression
* is matched for that file only.
*/
file?: number;
}
/**
* A description to track the start and end of a watching task.
*/
export interface IBackgroundMonitor {
/**
* If set to true the watcher is in active mode when the task
* starts. This is equals of issuing a line that matches the
* beginsPattern.
*/
activeOnStart?: boolean;
/**
* If matched in the output the start of a watching task is signaled.
*/
beginsPattern?: string | IWatchingPattern;
/**
* If matched in the output the end of a watching task is signaled.
*/
endsPattern?: string | IWatchingPattern;
}
/**
* A description of a problem matcher that detects problems
* in build output.
*/
export interface ProblemMatcher {
/**
* The name of a base problem matcher to use. If specified the
* base problem matcher will be used as a template and properties
* specified here will replace properties of the base problem
* matcher
*/
base?: string;
/**
* The owner of the produced VSCode problem. This is typically
* the identifier of a VSCode language service if the problems are
* to be merged with the one produced by the language service
* or a generated internal id. Defaults to the generated internal id.
*/
owner?: string;
/**
* A human-readable string describing the source of this problem.
* E.g. 'typescript' or 'super lint'.
*/
source?: string;
/**
* Specifies to which kind of documents the problems found by this
* matcher are applied. Valid values are:
*
* "allDocuments": problems found in all documents are applied.
* "openDocuments": problems found in documents that are open
* are applied.
* "closedDocuments": problems found in closed documents are
* applied.
*/
applyTo?: string;
/**
* The severity of the VSCode problem produced by this problem matcher.
*
* Valid values are:
* "error": to produce errors.
* "warning": to produce warnings.
* "info": to produce infos.
*
* The value is used if a pattern doesn't specify a severity match group.
* Defaults to "error" if omitted.
*/
severity?: string;
/**
* Defines how filename reported in a problem pattern
* should be read. Valid values are:
* - "absolute": the filename is always treated absolute.
* - "relative": the filename is always treated relative to
* the current working directory. This is the default.
* - ["relative", "path value"]: the filename is always
* treated relative to the given path value.
* - "autodetect": the filename is treated relative to
* the current workspace directory, and if the file
* does not exist, it is treated as absolute.
* - ["autodetect", "path value"]: the filename is treated
* relative to the given path value, and if it does not
* exist, it is treated as absolute.
* - ["search", { include?: "" | []; exclude?: "" | [] }]: The filename
* needs to be searched under the directories named by the "include"
* property and their nested subdirectories. With "exclude" property
* present, the directories should be removed from the search. When
* `include` is not unprovided, the current workspace directory should
* be used as the default.
*/
fileLocation?: string | string[] | ['search', SearchFileLocationArgs];
/**
* The name of a predefined problem pattern, the inline definition
* of a problem pattern or an array of problem patterns to match
* problems spread over multiple lines.
*/
pattern?: string | IProblemPattern | IProblemPattern[];
/**
* A regular expression signaling that a watched tasks begins executing
* triggered through file watching.
*/
watchedTaskBeginsRegExp?: string;
/**
* A regular expression signaling that a watched tasks ends executing.
*/
watchedTaskEndsRegExp?: string;
/**
* @deprecated Use background instead.
*/
watching?: IBackgroundMonitor;
background?: IBackgroundMonitor;
}
export type SearchFileLocationArgs = {
include?: string | string[];
exclude?: string | string[];
};
export type ProblemMatcherType = string | ProblemMatcher | Array<string | ProblemMatcher>;
export interface INamedProblemMatcher extends ProblemMatcher {
/**
* This name can be used to refer to the
* problem matcher from within a task.
*/
name: string;
/**
* A human readable label.
*/
label?: string;
}
export function isNamedProblemMatcher(value: ProblemMatcher): value is INamedProblemMatcher {
return Types.isString((<INamedProblemMatcher>value).name);
}
}
export class ProblemPatternParser extends Parser {
constructor(logger: IProblemReporter) {
super(logger);
}
public parse(value: Config.IProblemPattern): IProblemPattern;
public parse(value: Config.MultiLineProblemPattern): MultiLineProblemPattern;
public parse(value: Config.INamedProblemPattern): INamedProblemPattern;
public parse(value: Config.INamedMultiLineCheckedProblemPattern): INamedMultiLineProblemPattern;
public parse(value: Config.IProblemPattern | Config.MultiLineProblemPattern | Config.INamedProblemPattern | Config.INamedMultiLineCheckedProblemPattern): any {
if (Config.NamedMultiLineCheckedProblemPattern.is(value)) {
return this.createNamedMultiLineProblemPattern(value);
} else if (Config.MultiLineCheckedProblemPattern.is(value)) {
return this.createMultiLineProblemPattern(value);
} else if (Config.NamedCheckedProblemPattern.is(value)) {
const result = this.createSingleProblemPattern(value) as INamedProblemPattern;
result.name = value.name;
return result;
} else if (Config.CheckedProblemPattern.is(value)) {
return this.createSingleProblemPattern(value);
} else {
this.error(localize('ProblemPatternParser.problemPattern.missingRegExp', 'The problem pattern is missing a regular expression.'));
return null;
}
}
private createSingleProblemPattern(value: Config.ICheckedProblemPattern): IProblemPattern | null {
const result = this.doCreateSingleProblemPattern(value, true);
if (result === undefined) {
return null;
} else if (result.kind === undefined) {
result.kind = ProblemLocationKind.Location;
}
return this.validateProblemPattern([result]) ? result : null;
}
private createNamedMultiLineProblemPattern(value: Config.INamedMultiLineCheckedProblemPattern): INamedMultiLineProblemPattern | null {
const validPatterns = this.createMultiLineProblemPattern(value.patterns);
if (!validPatterns) {
return null;
}
const result = {
name: value.name,
label: value.label ? value.label : value.name,
patterns: validPatterns
};
return result;
}
private createMultiLineProblemPattern(values: Config.MultiLineCheckedProblemPattern): MultiLineProblemPattern | null {
const result: MultiLineProblemPattern = [];
for (let i = 0; i < values.length; i++) {
const pattern = this.doCreateSingleProblemPattern(values[i], false);
if (pattern === undefined) {
return null;
}
if (i < values.length - 1) {
if (!Types.isUndefined(pattern.loop) && pattern.loop) {
pattern.loop = false;
this.error(localize('ProblemPatternParser.loopProperty.notLast', 'The loop property is only supported on the last line matcher.'));
}
}
result.push(pattern);
}
if (result[0].kind === undefined) {
result[0].kind = ProblemLocationKind.Location;
}
return this.validateProblemPattern(result) ? result : null;
}
private doCreateSingleProblemPattern(value: Config.ICheckedProblemPattern, setDefaults: boolean): IProblemPattern | undefined {
const regexp = this.createRegularExpression(value.regexp);
if (regexp === undefined) {
return undefined;
}