problemMatcher.ts 56.4 KB
Newer Older
E
Erich Gamma 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import { localize } from 'vs/nls';
E
Erich Gamma 已提交
7 8 9 10

import * as Objects from 'vs/base/common/objects';
import * as Strings from 'vs/base/common/strings';
import * as Assert from 'vs/base/common/assert';
11
import { join } from 'vs/base/common/path';
E
Erich Gamma 已提交
12
import * as Types from 'vs/base/common/types';
13
import * as UUID from 'vs/base/common/uuid';
14
import * as Platform from 'vs/base/common/platform';
E
Erich Gamma 已提交
15
import Severity from 'vs/base/common/severity';
16
import { URI } from 'vs/base/common/uri';
17 18
import { IJSONSchema } from 'vs/base/common/jsonSchema';
import { ValidationStatus, ValidationState, IProblemReporter, Parser } from 'vs/base/common/parsers';
E
Erich Gamma 已提交
19 20
import { IStringDictionary } from 'vs/base/common/collections';

J
Johannes Rieken 已提交
21
import { IMarkerData, MarkerSeverity } from 'vs/platform/markers/common/markers';
22
import { ExtensionsRegistry, ExtensionMessageCollector } from 'vs/workbench/services/extensions/common/extensionsRegistry';
23
import { Event, Emitter } from 'vs/base/common/event';
E
Erich Gamma 已提交
24 25 26 27 28 29 30 31

export enum FileLocationKind {
	Auto,
	Relative,
	Absolute
}

export module FileLocationKind {
32
	export function fromString(value: string): FileLocationKind | undefined {
E
Erich Gamma 已提交
33 34 35 36 37 38 39 40 41 42 43
		value = value.toLowerCase();
		if (value === 'absolute') {
			return FileLocationKind.Absolute;
		} else if (value === 'relative') {
			return FileLocationKind.Relative;
		} else {
			return undefined;
		}
	}
}

44 45 46 47 48 49
export enum ProblemLocationKind {
	File,
	Location
}

export module ProblemLocationKind {
50
	export function fromString(value: string): ProblemLocationKind | undefined {
51 52 53 54 55 56 57 58 59 60 61
		value = value.toLowerCase();
		if (value === 'file') {
			return ProblemLocationKind.File;
		} else if (value === 'location') {
			return ProblemLocationKind.Location;
		} else {
			return undefined;
		}
	}
}

E
Erich Gamma 已提交
62 63 64
export interface ProblemPattern {
	regexp: RegExp;

65 66
	kind?: ProblemLocationKind;

E
Erich Gamma 已提交
67 68 69 70 71 72 73 74
	file?: number;

	message?: number;

	location?: number;

	line?: number;

75
	character?: number;
E
Erich Gamma 已提交
76 77 78

	endLine?: number;

79
	endCharacter?: number;
E
Erich Gamma 已提交
80 81 82 83 84 85 86 87

	code?: number;

	severity?: number;

	loop?: boolean;
}

88 89 90 91
export interface NamedProblemPattern extends ProblemPattern {
	name: string;
}

92
export type MultiLineProblemPattern = ProblemPattern[];
E
Erich Gamma 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

export interface WatchingPattern {
	regexp: RegExp;
	file?: number;
}

export interface WatchingMatcher {
	activeOnStart: boolean;
	beginsPattern: WatchingPattern;
	endsPattern: WatchingPattern;
}

export enum ApplyToKind {
	allDocuments,
	openDocuments,
	closedDocuments
}

export module ApplyToKind {
112
	export function fromString(value: string): ApplyToKind | undefined {
E
Erich Gamma 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
		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;
128
	source?: string;
E
Erich Gamma 已提交
129 130 131 132
	applyTo: ApplyToKind;
	fileLocation: FileLocationKind;
	filePrefix?: string;
	pattern: ProblemPattern | ProblemPattern[];
D
Dirk Baeumer 已提交
133
	severity?: Severity;
E
Erich Gamma 已提交
134
	watching?: WatchingMatcher;
135
	uriProvider?: (path: string) => URI;
E
Erich Gamma 已提交
136 137 138 139
}

export interface NamedProblemMatcher extends ProblemMatcher {
	name: string;
140
	label: string;
141
	deprecated?: boolean;
E
Erich Gamma 已提交
142 143
}

144 145
export interface NamedMultiLineProblemPattern {
	name: string;
146
	label: string;
147 148 149
	patterns: MultiLineProblemPattern;
}

A
Alex Ross 已提交
150
export function isNamedProblemMatcher(value: ProblemMatcher | undefined): value is NamedProblemMatcher {
151
	return value && Types.isString((<NamedProblemMatcher>value).name) ? true : false;
E
Erich Gamma 已提交
152 153 154 155
}

interface Location {
	startLineNumber: number;
156
	startCharacter: number;
E
Erich Gamma 已提交
157
	endLineNumber: number;
158
	endCharacter: number;
E
Erich Gamma 已提交
159 160 161
}

interface ProblemData {
162
	kind?: ProblemLocationKind;
E
Erich Gamma 已提交
163
	file?: string;
D
Dirk Baeumer 已提交
164
	location?: string;
E
Erich Gamma 已提交
165
	line?: string;
166
	character?: string;
E
Erich Gamma 已提交
167
	endLine?: string;
168
	endCharacter?: string;
E
Erich Gamma 已提交
169 170 171 172 173 174 175 176 177 178 179 180
	message?: string;
	severity?: string;
	code?: string;
}

export interface ProblemMatch {
	resource: URI;
	marker: IMarkerData;
	description: ProblemMatcher;
}

export interface HandleResult {
181
	match: ProblemMatch | null;
E
Erich Gamma 已提交
182 183 184
	continue: boolean;
}

D
Dirk Baeumer 已提交
185
export function getResource(filename: string, matcher: ProblemMatcher): URI {
E
Erich Gamma 已提交
186
	let kind = matcher.fileLocation;
187
	let fullPath: string | undefined;
E
Erich Gamma 已提交
188 189
	if (kind === FileLocationKind.Absolute) {
		fullPath = filename;
190
	} else if ((kind === FileLocationKind.Relative) && matcher.filePrefix) {
191
		fullPath = join(matcher.filePrefix, filename);
E
Erich Gamma 已提交
192
	}
R
Rob Lourens 已提交
193
	if (fullPath === undefined) {
194 195
		throw new Error('FileLocationKind is not actionable. Does the matcher have a filePrefix? This should never happen.');
	}
E
Erich Gamma 已提交
196 197 198 199
	fullPath = fullPath.replace(/\\/g, '/');
	if (fullPath[0] !== '/') {
		fullPath = '/' + fullPath;
	}
R
Rob Lourens 已提交
200
	if (matcher.uriProvider !== undefined) {
201
		return matcher.uriProvider(fullPath);
202 203 204
	} else {
		return URI.file(fullPath);
	}
E
Erich Gamma 已提交
205 206 207 208
}

export interface ILineMatcher {
	matchLength: number;
209
	next(line: string): ProblemMatch | null;
E
Erich Gamma 已提交
210 211 212 213 214 215 216 217 218 219 220 221
	handle(lines: string[], start?: number): HandleResult;
}

export function createLineMatcher(matcher: ProblemMatcher): ILineMatcher {
	let pattern = matcher.pattern;
	if (Types.isArray(pattern)) {
		return new MultiLineMatcher(matcher);
	} else {
		return new SingleLineMatcher(matcher);
	}
}

222 223
const endOfLine: string = Platform.OS === Platform.OperatingSystem.Windows ? '\r\n' : '\n';

224
abstract class AbstractLineMatcher implements ILineMatcher {
E
Erich Gamma 已提交
225 226 227 228 229 230 231 232 233 234
	private matcher: ProblemMatcher;

	constructor(matcher: ProblemMatcher) {
		this.matcher = matcher;
	}

	public handle(lines: string[], start: number = 0): HandleResult {
		return { match: null, continue: false };
	}

235
	public next(line: string): ProblemMatch | null {
E
Erich Gamma 已提交
236 237 238
		return null;
	}

239
	public abstract get matchLength(): number;
E
Erich Gamma 已提交
240

241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
	protected fillProblemData(data: ProblemData | null, pattern: ProblemPattern, matches: RegExpExecArray): data is ProblemData {
		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;
		}
E
Erich Gamma 已提交
256 257
	}

258
	private appendProperty(data: ProblemData, property: keyof ProblemData, pattern: ProblemPattern, matches: RegExpExecArray, trim: boolean = false): void {
259
		const patternProperty = pattern[property];
260 261 262
		if (Types.isUndefined(data[property])) {
			this.fillProperty(data, property, pattern, matches, trim);
		}
263 264
		else if (!Types.isUndefined(patternProperty) && patternProperty < matches.length) {
			let value = matches[patternProperty];
265
			if (trim) {
266
				value = Strings.trim(value)!;
267
			}
M
Matt Bierner 已提交
268
			(data as any)[property] += endOfLine + value;
269 270 271
		}
	}

272
	private fillProperty(data: ProblemData, property: keyof ProblemData, pattern: ProblemPattern, matches: RegExpExecArray, trim: boolean = false): void {
273 274 275
		const patternAtProperty = pattern[property];
		if (Types.isUndefined(data[property]) && !Types.isUndefined(patternAtProperty) && patternAtProperty < matches.length) {
			let value = matches[patternAtProperty];
R
Rob Lourens 已提交
276
			if (value !== undefined) {
277
				if (trim) {
278
					value = Strings.trim(value)!;
279
				}
M
Matt Bierner 已提交
280
				(data as any)[property] = value;
E
Erich Gamma 已提交
281 282 283 284
			}
		}
	}

285
	protected getMarkerMatch(data: ProblemData): ProblemMatch | undefined {
286 287 288 289 290 291 292
		try {
			let location = this.getLocation(data);
			if (data.file && location && data.message) {
				let marker: IMarkerData = {
					severity: this.getSeverity(data),
					startLineNumber: location.startLineNumber,
					startColumn: location.startCharacter,
293
					endLineNumber: location.endLineNumber,
294 295 296
					endColumn: location.endCharacter,
					message: data.message
				};
R
Rob Lourens 已提交
297
				if (data.code !== undefined) {
298 299
					marker.code = data.code;
				}
R
Rob Lourens 已提交
300
				if (this.matcher.source !== undefined) {
301 302
					marker.source = this.matcher.source;
				}
303 304 305 306 307
				return {
					description: this.matcher,
					resource: this.getResource(data.file),
					marker: marker
				};
E
Erich Gamma 已提交
308
			}
309 310
		} catch (err) {
			console.error(`Failed to convert problem data into match: ${JSON.stringify(data)}`);
E
Erich Gamma 已提交
311
		}
M
Matt Bierner 已提交
312
		return undefined;
E
Erich Gamma 已提交
313 314
	}

D
Dirk Baeumer 已提交
315
	protected getResource(filename: string): URI {
E
Erich Gamma 已提交
316 317 318
		return getResource(filename, this.matcher);
	}

319
	private getLocation(data: ProblemData): Location | null {
320 321 322
		if (data.kind === ProblemLocationKind.File) {
			return this.createLocation(0, 0, 0, 0);
		}
E
Erich Gamma 已提交
323 324 325 326 327 328 329
		if (data.location) {
			return this.parseLocationInfo(data.location);
		}
		if (!data.line) {
			return null;
		}
		let startLine = parseInt(data.line);
330
		let startColumn = data.character ? parseInt(data.character) : undefined;
E
Erich Gamma 已提交
331
		let endLine = data.endLine ? parseInt(data.endLine) : undefined;
332
		let endColumn = data.endCharacter ? parseInt(data.endCharacter) : undefined;
E
Erich Gamma 已提交
333 334 335
		return this.createLocation(startLine, startColumn, endLine, endColumn);
	}

336
	private parseLocationInfo(value: string): Location | null {
E
Erich Gamma 已提交
337 338 339 340 341 342 343 344 345 346 347 348 349
		if (!value || !value.match(/(\d+|\d+,\d+|\d+,\d+,\d+,\d+)/)) {
			return null;
		}
		let parts = value.split(',');
		let startLine = parseInt(parts[0]);
		let 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);
		}
	}

350
	private createLocation(startLine: number, startColumn: number | undefined, endLine: number | undefined, endColumn: number | undefined): Location {
D
Dirk Baeumer 已提交
351
		if (startColumn !== undefined && endColumn !== undefined) {
352
			return { startLineNumber: startLine, startCharacter: startColumn, endLineNumber: endLine || startLine, endCharacter: endColumn };
E
Erich Gamma 已提交
353
		}
D
Dirk Baeumer 已提交
354
		if (startColumn !== undefined) {
355
			return { startLineNumber: startLine, startCharacter: startColumn, endLineNumber: startLine, endCharacter: startColumn };
E
Erich Gamma 已提交
356
		}
357
		return { startLineNumber: startLine, startCharacter: 1, endLineNumber: startLine, endCharacter: Number.MAX_VALUE };
E
Erich Gamma 已提交
358 359
	}

J
Johannes Rieken 已提交
360
	private getSeverity(data: ProblemData): MarkerSeverity {
361
		let result: Severity | null = null;
E
Erich Gamma 已提交
362 363
		if (data.severity) {
			let value = data.severity;
364
			if (value) {
E
Erich Gamma 已提交
365
				result = Severity.fromValue(value);
366 367 368 369 370 371 372 373 374 375 376 377 378
				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;
					}
				}
E
Erich Gamma 已提交
379 380 381 382 383
			}
		}
		if (result === null || result === Severity.Ignore) {
			result = this.matcher.severity || Severity.Error;
		}
J
Johannes Rieken 已提交
384
		return MarkerSeverity.fromSeverity(result);
E
Erich Gamma 已提交
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
	}
}

class SingleLineMatcher extends AbstractLineMatcher {

	private pattern: ProblemPattern;

	constructor(matcher: ProblemMatcher) {
		super(matcher);
		this.pattern = <ProblemPattern>matcher.pattern;
	}

	public get matchLength(): number {
		return 1;
	}

	public handle(lines: string[], start: number = 0): HandleResult {
		Assert.ok(lines.length - start === 1);
		let data: ProblemData = Object.create(null);
R
Rob Lourens 已提交
404
		if (this.pattern.kind !== undefined) {
405 406
			data.kind = this.pattern.kind;
		}
E
Erich Gamma 已提交
407 408 409 410 411 412 413 414 415 416 417
		let matches = this.pattern.regexp.exec(lines[start]);
		if (matches) {
			this.fillProblemData(data, this.pattern, matches);
			let match = this.getMarkerMatch(data);
			if (match) {
				return { match: match, continue: false };
			}
		}
		return { match: null, continue: false };
	}

418
	public next(line: string): ProblemMatch | null {
E
Erich Gamma 已提交
419 420 421 422 423 424 425
		return null;
	}
}

class MultiLineMatcher extends AbstractLineMatcher {

	private patterns: ProblemPattern[];
426
	private data: ProblemData | null;
E
Erich Gamma 已提交
427 428 429 430 431 432 433 434 435 436 437 438 439

	constructor(matcher: ProblemMatcher) {
		super(matcher);
		this.patterns = <ProblemPattern[]>matcher.pattern;
	}

	public get matchLength(): number {
		return this.patterns.length;
	}

	public handle(lines: string[], start: number = 0): HandleResult {
		Assert.ok(lines.length - start === this.patterns.length);
		this.data = Object.create(null);
440
		let data = this.data!;
441
		data.kind = this.patterns[0].kind;
E
Erich Gamma 已提交
442 443 444 445
		for (let i = 0; i < this.patterns.length; i++) {
			let pattern = this.patterns[i];
			let matches = pattern.regexp.exec(lines[i + start]);
			if (!matches) {
D
Dirk Baeumer 已提交
446
				return { match: null, continue: false };
E
Erich Gamma 已提交
447 448 449
			} else {
				// Only the last pattern can loop
				if (pattern.loop && i === this.patterns.length - 1) {
J
Johannes Rieken 已提交
450
					data = Objects.deepClone(data);
E
Erich Gamma 已提交
451 452 453 454
				}
				this.fillProblemData(data, pattern, matches);
			}
		}
455
		let loop = !!this.patterns[this.patterns.length - 1].loop;
E
Erich Gamma 已提交
456 457 458
		if (!loop) {
			this.data = null;
		}
459 460
		const markerMatch = data ? this.getMarkerMatch(data) : null;
		return { match: markerMatch ? markerMatch : null, continue: loop };
E
Erich Gamma 已提交
461 462
	}

463
	public next(line: string): ProblemMatch | null {
E
Erich Gamma 已提交
464 465 466 467 468 469 470
		let pattern = this.patterns[this.patterns.length - 1];
		Assert.ok(pattern.loop === true && this.data !== null);
		let matches = pattern.regexp.exec(line);
		if (!matches) {
			this.data = null;
			return null;
		}
J
Johannes Rieken 已提交
471
		let data = Objects.deepClone(this.data);
472 473 474 475 476
		let problemMatch: ProblemMatch | undefined;
		if (this.fillProblemData(data, pattern, matches)) {
			problemMatch = this.getMarkerMatch(data);
		}
		return problemMatch ? problemMatch : null;
E
Erich Gamma 已提交
477 478 479 480 481 482 483 484 485 486 487 488 489
	}
}

export namespace Config {

	export interface ProblemPattern {

		/**
		* The regular expression to find a problem in the console output of an
		* executed task.
		*/
		regexp?: string;

490 491 492 493 494 495 496 497
		/**
		* 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;

E
Erich Gamma 已提交
498 499 500 501 502 503 504
		/**
		* The match group index of the filename.
		* If omitted 1 is used.
		*/
		file?: number;

		/**
505
		* The match group index of the problem's location. Valid location
E
Erich Gamma 已提交
506
		* patterns are: (line), (line,column) and (startLine,startColumn,endLine,endColumn).
507
		* If omitted the line and column properties are used.
E
Erich Gamma 已提交
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
		*/
		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;

		/**
548
		* The match group index of the problem's code.
E
Erich Gamma 已提交
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
		*
		* 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;
	}

568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
	export interface CheckedProblemPattern extends ProblemPattern {
		/**
		* 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 CheckedProblemPattern {
			let candidate: ProblemPattern = value as ProblemPattern;
			return candidate && Types.isString(candidate.regexp);
		}
	}

583 584 585 586 587
	export interface NamedProblemPattern extends ProblemPattern {
		/**
		 * The name of the problem pattern.
		 */
		name: string;
588 589 590 591 592

		/**
		 * A human readable label
		 */
		label?: string;
593 594 595
	}

	export namespace NamedProblemPattern {
596
		export function is(value: any): value is NamedProblemPattern {
597 598 599 600 601
			let candidate: NamedProblemPattern = value as NamedProblemPattern;
			return candidate && Types.isString(candidate.name);
		}
	}

602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
	export interface NamedCheckedProblemPattern extends NamedProblemPattern {
		/**
		* 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 NamedCheckedProblemPattern {
			let candidate: NamedProblemPattern = value as NamedProblemPattern;
			return candidate && NamedProblemPattern.is(candidate) && Types.isString(candidate.regexp);
		}
	}

617 618 619 620 621 622 623 624
	export type MultiLineProblemPattern = ProblemPattern[];

	export namespace MultiLineProblemPattern {
		export function is(value: any): value is MultiLineProblemPattern {
			return value && Types.isArray(value);
		}
	}

625 626 627 628
	export type MultiLineCheckedProblemPattern = CheckedProblemPattern[];

	export namespace MultiLineCheckedProblemPattern {
		export function is(value: any): value is MultiLineCheckedProblemPattern {
629 630 631 632 633 634 635
			if (!MultiLineProblemPattern.is(value)) {
				return false;
			}
			for (const element of value) {
				if (!Config.CheckedProblemPattern.is(element)) {
					return false;
				}
636
			}
637
			return true;
638 639 640 641
		}
	}

	export interface NamedMultiLineCheckedProblemPattern {
642 643 644 645 646
		/**
		 * The name of the problem pattern.
		 */
		name: string;

647 648 649 650 651
		/**
		 * A human readable label
		 */
		label?: string;

652 653 654
		/**
		 * The actual patterns
		 */
655
		patterns: MultiLineCheckedProblemPattern;
656 657
	}

658 659 660 661
	export namespace NamedMultiLineCheckedProblemPattern {
		export function is(value: any): value is NamedMultiLineCheckedProblemPattern {
			let candidate = value as NamedMultiLineCheckedProblemPattern;
			return candidate && Types.isString(candidate.name) && Types.isArray(candidate.patterns) && MultiLineCheckedProblemPattern.is(candidate.patterns);
662 663 664
		}
	}

665
	export type NamedProblemPatterns = (Config.NamedProblemPattern | Config.NamedMultiLineCheckedProblemPattern)[];
666

E
Erich Gamma 已提交
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
	/**
	* A watching pattern
	*/
	export interface WatchingPattern {
		/**
		* 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.
	*/
686
	export interface BackgroundMonitor {
E
Erich Gamma 已提交
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

		/**
		* If set to true the watcher is in active mode when the task
		* starts. This is equals of issuing a line that matches the
		* beginPattern.
		*/
		activeOnStart?: boolean;

		/**
		* If matched in the output the start of a watching task is signaled.
		*/
		beginsPattern?: string | WatchingPattern;

		/**
		* If matched in the output the end of a watching task is signaled.
		*/
		endsPattern?: string | WatchingPattern;
	}

	/**
	* A description of a problem matcher that detects problems
	* in build output.
	*/
	export interface ProblemMatcher {

		/**
713 714 715 716 717
		 * 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
		 */
E
Erich Gamma 已提交
718 719 720
		base?: string;

		/**
721 722 723 724 725
		 * 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.
		 */
E
Erich Gamma 已提交
726 727
		owner?: string;

728 729 730 731 732 733
		/**
		 * A human-readable string describing the source of this problem.
		 * E.g. 'typescript' or 'super lint'.
		 */
		source?: string;

E
Erich Gamma 已提交
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
		/**
		* 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.
		*/
		fileLocation?: string | string[];

		/**
		* The name of a predefined problem pattern, the inline definintion
		* of a problem pattern or an array of problem patterns to match
		* problems spread over multiple lines.
		*/
		pattern?: string | ProblemPattern | ProblemPattern[];

		/**
		* 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;

788 789 790 791 792
		/**
		 * @deprecated Use background instead.
		 */
		watching?: BackgroundMonitor;
		background?: BackgroundMonitor;
E
Erich Gamma 已提交
793 794
	}

795
	export type ProblemMatcherType = string | ProblemMatcher | Array<string | ProblemMatcher>;
E
Erich Gamma 已提交
796 797 798

	export interface NamedProblemMatcher extends ProblemMatcher {
		/**
799
		* This name can be used to refer to the
800
		* problem matcher from within a task.
E
Erich Gamma 已提交
801
		*/
802
		name: string;
803 804

		/**
805
		 * A human readable label.
806 807
		 */
		label?: string;
E
Erich Gamma 已提交
808 809 810 811 812 813 814
	}

	export function isNamedProblemMatcher(value: ProblemMatcher): value is NamedProblemMatcher {
		return Types.isString((<NamedProblemMatcher>value).name);
	}
}

815
export class ProblemPatternParser extends Parser {
E
Erich Gamma 已提交
816

817 818 819 820
	constructor(logger: IProblemReporter) {
		super(logger);
	}

821
	public parse(value: Config.ProblemPattern): ProblemPattern;
822
	public parse(value: Config.MultiLineProblemPattern): MultiLineProblemPattern;
823
	public parse(value: Config.NamedProblemPattern): NamedProblemPattern;
824 825 826
	public parse(value: Config.NamedMultiLineCheckedProblemPattern): NamedMultiLineProblemPattern;
	public parse(value: Config.ProblemPattern | Config.MultiLineProblemPattern | Config.NamedProblemPattern | Config.NamedMultiLineCheckedProblemPattern): any {
		if (Config.NamedMultiLineCheckedProblemPattern.is(value)) {
827
			return this.createNamedMultiLineProblemPattern(value);
828
		} else if (Config.MultiLineCheckedProblemPattern.is(value)) {
829
			return this.createMultiLineProblemPattern(value);
830
		} else if (Config.NamedCheckedProblemPattern.is(value)) {
831 832 833
			let result = this.createSingleProblemPattern(value) as NamedProblemPattern;
			result.name = value.name;
			return result;
834
		} else if (Config.CheckedProblemPattern.is(value)) {
835 836
			return this.createSingleProblemPattern(value);
		} else {
837
			this.error(localize('ProblemPatternParser.problemPattern.missingRegExp', 'The problem pattern is missing a regular expression.'));
838 839 840 841
			return null;
		}
	}

842
	private createSingleProblemPattern(value: Config.CheckedProblemPattern): ProblemPattern | null {
843
		let result = this.doCreateSingleProblemPattern(value, true);
844 845 846
		if (result === undefined) {
			return null;
		} else if (result.kind === undefined) {
847 848
			result.kind = ProblemLocationKind.Location;
		}
849 850 851
		return this.validateProblemPattern([result]) ? result : null;
	}

852 853 854 855 856
	private createNamedMultiLineProblemPattern(value: Config.NamedMultiLineCheckedProblemPattern): NamedMultiLineProblemPattern | null {
		const validPatterns = this.createMultiLineProblemPattern(value.patterns);
		if (!validPatterns) {
			return null;
		}
857 858
		let result = {
			name: value.name,
859
			label: value.label ? value.label : value.name,
860
			patterns: validPatterns
861
		};
862
		return result;
863 864
	}

865
	private createMultiLineProblemPattern(values: Config.MultiLineCheckedProblemPattern): MultiLineProblemPattern | null {
866 867 868
		let result: MultiLineProblemPattern = [];
		for (let i = 0; i < values.length; i++) {
			let pattern = this.doCreateSingleProblemPattern(values[i], false);
869 870 871
			if (pattern === undefined) {
				return null;
			}
872 873 874 875 876 877 878 879
			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);
		}
880 881 882
		if (result[0].kind === undefined) {
			result[0].kind = ProblemLocationKind.Location;
		}
883 884 885
		return this.validateProblemPattern(result) ? result : null;
	}

886
	private doCreateSingleProblemPattern(value: Config.CheckedProblemPattern, setDefaults: boolean): ProblemPattern | undefined {
887
		const regexp = this.createRegularExpression(value.regexp);
R
Rob Lourens 已提交
888
		if (regexp === undefined) {
889
			return undefined;
890 891
		}
		let result: ProblemPattern = { regexp };
892 893 894
		if (value.kind) {
			result.kind = ProblemLocationKind.fromString(value.kind);
		}
895 896

		function copyProperty(result: ProblemPattern, source: Config.ProblemPattern, resultKey: keyof ProblemPattern, sourceKey: keyof Config.ProblemPattern) {
M
Matt Bierner 已提交
897
			const value = source[sourceKey];
898
			if (typeof value === 'number') {
M
Matt Bierner 已提交
899
				(result as any)[resultKey] = value;
900
			}
901 902 903 904 905 906 907 908 909 910 911 912 913
		}
		copyProperty(result, value, 'file', 'file');
		copyProperty(result, value, 'location', 'location');
		copyProperty(result, value, 'line', 'line');
		copyProperty(result, value, 'character', 'column');
		copyProperty(result, value, 'endLine', 'endLine');
		copyProperty(result, value, 'endCharacter', 'endColumn');
		copyProperty(result, value, 'severity', 'severity');
		copyProperty(result, value, 'code', 'code');
		copyProperty(result, value, 'message', 'message');
		if (value.loop === true || value.loop === false) {
			result.loop = value.loop;
		}
914
		if (setDefaults) {
915
			if (result.location || result.kind === ProblemLocationKind.File) {
916
				let defaultValue: Partial<ProblemPattern> = {
917 918
					file: 1,
					message: 0
919 920
				};
				result = Objects.mixin(result, defaultValue, false);
921
			} else {
922
				let defaultValue: Partial<ProblemPattern> = {
923 924
					file: 1,
					line: 2,
925
					character: 3,
926
					message: 0
927 928
				};
				result = Objects.mixin(result, defaultValue, false);
929 930 931 932 933 934
			}
		}
		return result;
	}

	private validateProblemPattern(values: ProblemPattern[]): boolean {
935
		let file: boolean = false, message: boolean = false, location: boolean = false, line: boolean = false;
936 937 938 939 940 941
		let locationKind = (values[0].kind === undefined) ? ProblemLocationKind.Location : values[0].kind;

		values.forEach((pattern, i) => {
			if (i !== 0 && pattern.kind) {
				this.error(localize('ProblemPatternParser.problemPattern.kindProperty.notFirst', 'The problem pattern is invalid. The kind property must be provided only in the first element'));
			}
942 943 944 945 946
			file = file || !Types.isUndefined(pattern.file);
			message = message || !Types.isUndefined(pattern.message);
			location = location || !Types.isUndefined(pattern.location);
			line = line || !Types.isUndefined(pattern.line);
		});
947 948 949 950 951 952
		if (!(file && message)) {
			this.error(localize('ProblemPatternParser.problemPattern.missingProperty', 'The problem pattern is invalid. It must have at least have a file and a message.'));
			return false;
		}
		if (locationKind === ProblemLocationKind.Location && !(location || line)) {
			this.error(localize('ProblemPatternParser.problemPattern.missingLocation', 'The problem pattern is invalid. It must either have kind: "file" or have a line or location match group.'));
953 954 955 956 957
			return false;
		}
		return true;
	}

958 959
	private createRegularExpression(value: string): RegExp | undefined {
		let result: RegExp | undefined;
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
		try {
			result = new RegExp(value);
		} catch (err) {
			this.error(localize('ProblemPatternParser.invalidRegexp', 'Error: The string {0} is not a valid regular expression.\n', value));
		}
		return result;
	}
}

export class ExtensionRegistryReporter implements IProblemReporter {
	constructor(private _collector: ExtensionMessageCollector, private _validationStatus: ValidationStatus = new ValidationStatus()) {
	}

	public info(message: string): void {
		this._validationStatus.state = ValidationState.Info;
		this._collector.info(message);
	}

	public warn(message: string): void {
		this._validationStatus.state = ValidationState.Warning;
		this._collector.warn(message);
	}

	public error(message: string): void {
		this._validationStatus.state = ValidationState.Error;
		this._collector.error(message);
	}

	public fatal(message: string): void {
		this._validationStatus.state = ValidationState.Fatal;
		this._collector.error(message);
	}

	public get status(): ValidationStatus {
		return this._validationStatus;
	}
}

export namespace Schemas {

	export const ProblemPattern: IJSONSchema = {
		default: {
			regexp: '^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$',
			file: 1,
			location: 2,
			message: 3
		},
		type: 'object',
		additionalProperties: false,
		properties: {
			regexp: {
				type: 'string',
				description: localize('ProblemPatternSchema.regexp', 'The regular expression to find an error, warning or info in the output.')
			},
1014 1015 1016 1017
			kind: {
				type: 'string',
				description: localize('ProblemPatternSchema.kind', 'whether the pattern matches a location (file and line) or only a file.')
			},
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
			file: {
				type: 'integer',
				description: localize('ProblemPatternSchema.file', 'The match group index of the filename. If omitted 1 is used.')
			},
			location: {
				type: 'integer',
				description: localize('ProblemPatternSchema.location', 'The match group index of the problem\'s location. Valid location patterns are: (line), (line,column) and (startLine,startColumn,endLine,endColumn). If omitted (line,column) is assumed.')
			},
			line: {
				type: 'integer',
				description: localize('ProblemPatternSchema.line', 'The match group index of the problem\'s line. Defaults to 2')
			},
			column: {
				type: 'integer',
				description: localize('ProblemPatternSchema.column', 'The match group index of the problem\'s line character. Defaults to 3')
			},
			endLine: {
				type: 'integer',
				description: localize('ProblemPatternSchema.endLine', 'The match group index of the problem\'s end line. Defaults to undefined')
			},
			endColumn: {
				type: 'integer',
				description: localize('ProblemPatternSchema.endColumn', 'The match group index of the problem\'s end line character. Defaults to undefined')
			},
			severity: {
				type: 'integer',
				description: localize('ProblemPatternSchema.severity', 'The match group index of the problem\'s severity. Defaults to undefined')
			},
			code: {
				type: 'integer',
				description: localize('ProblemPatternSchema.code', 'The match group index of the problem\'s code. Defaults to undefined')
			},
			message: {
				type: 'integer',
				description: localize('ProblemPatternSchema.message', 'The match group index of the message. If omitted it defaults to 4 if location is specified. Otherwise it defaults to 5.')
			},
			loop: {
				type: 'boolean',
				description: localize('ProblemPatternSchema.loop', 'In a multi line matcher loop indicated whether this pattern is executed in a loop as long as it matches. Can only specified on a last pattern in a multi line pattern.')
			}
		}
	};

J
Johannes Rieken 已提交
1061
	export const NamedProblemPattern: IJSONSchema = Objects.deepClone(ProblemPattern);
1062
	NamedProblemPattern.properties = Objects.deepClone(NamedProblemPattern.properties) || {};
1063 1064 1065 1066 1067
	NamedProblemPattern.properties['name'] = {
		type: 'string',
		description: localize('NamedProblemPatternSchema.name', 'The name of the problem pattern.')
	};

S
Sylvain Joyeux 已提交
1068
	export const MultiLineProblemPattern: IJSONSchema = {
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
		type: 'array',
		items: ProblemPattern
	};

	export const NamedMultiLineProblemPattern: IJSONSchema = {
		type: 'object',
		additionalProperties: false,
		properties: {
			name: {
				type: 'string',
				description: localize('NamedMultiLineProblemPatternSchema.name', 'The name of the problem multi line problem pattern.')
			},
			patterns: {
				type: 'array',
				description: localize('NamedMultiLineProblemPatternSchema.patterns', 'The actual patterns.'),
				items: ProblemPattern
			}
		}
	};
}

1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
const problemPatternExtPoint = ExtensionsRegistry.registerExtensionPoint<Config.NamedProblemPatterns>({
	extensionPoint: 'problemPatterns',
	jsonSchema: {
		description: localize('ProblemPatternExtPoint', 'Contributes problem patterns'),
		type: 'array',
		items: {
			anyOf: [
				Schemas.NamedProblemPattern,
				Schemas.NamedMultiLineProblemPattern
			]
		}
1101
	}
1102 1103 1104
});

export interface IProblemPatternRegistry {
D
Dirk Baeumer 已提交
1105
	onReady(): Promise<void>;
1106 1107 1108 1109 1110 1111 1112

	get(key: string): ProblemPattern | MultiLineProblemPattern;
}

class ProblemPatternRegistryImpl implements IProblemPatternRegistry {

	private patterns: IStringDictionary<ProblemPattern | ProblemPattern[]>;
D
Dirk Baeumer 已提交
1113
	private readyPromise: Promise<void>;
1114 1115 1116 1117

	constructor() {
		this.patterns = Object.create(null);
		this.fillDefaults();
D
Dirk Baeumer 已提交
1118
		this.readyPromise = new Promise<void>((resolve, reject) => {
1119
			problemPatternExtPoint.setHandler((extensions, delta) => {
1120 1121
				// We get all statically know extension during startup in one batch
				try {
1122 1123 1124 1125 1126 1127 1128 1129 1130
					delta.removed.forEach(extension => {
						let problemPatterns = extension.value as Config.NamedProblemPatterns;
						for (let pattern of problemPatterns) {
							if (this.patterns[pattern.name]) {
								delete this.patterns[pattern.name];
							}
						}
					});
					delta.added.forEach(extension => {
1131 1132 1133
						let problemPatterns = extension.value as Config.NamedProblemPatterns;
						let parser = new ProblemPatternParser(new ExtensionRegistryReporter(extension.collector));
						for (let pattern of problemPatterns) {
1134
							if (Config.NamedMultiLineCheckedProblemPattern.is(pattern)) {
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
								let result = parser.parse(pattern);
								if (parser.problemReporter.status.state < ValidationState.Error) {
									this.add(result.name, result.patterns);
								} else {
									extension.collector.error(localize('ProblemPatternRegistry.error', 'Invalid problem pattern. The pattern will be ignored.'));
									extension.collector.error(JSON.stringify(pattern, undefined, 4));
								}
							}
							else if (Config.NamedProblemPattern.is(pattern)) {
								let result = parser.parse(pattern);
								if (parser.problemReporter.status.state < ValidationState.Error) {
									this.add(pattern.name, result);
								} else {
									extension.collector.error(localize('ProblemPatternRegistry.error', 'Invalid problem pattern. The pattern will be ignored.'));
									extension.collector.error(JSON.stringify(pattern, undefined, 4));
								}
							}
							parser.reset();
						}
					});
				} catch (error) {
					// Do nothing
				}
				resolve(undefined);
			});
1160
		});
1161 1162
	}

D
Dirk Baeumer 已提交
1163
	public onReady(): Promise<void> {
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
		return this.readyPromise;
	}

	public add(key: string, value: ProblemPattern | ProblemPattern[]): void {
		this.patterns[key] = value;
	}

	public get(key: string): ProblemPattern | ProblemPattern[] {
		return this.patterns[key];
	}

	private fillDefaults(): void {
		this.add('msCompile', {
1177
			regexp: /^(?:\s+\d+\>)?([^\s].*)\((\d+|\d+,\d+|\d+,\d+,\d+,\d+)\)\s*:\s+(error|warning|info)\s+(\w{1,2}\d+)\s*:\s*(.*)$/,
1178
			kind: ProblemLocationKind.Location,
1179 1180 1181 1182 1183 1184 1185 1186
			file: 1,
			location: 2,
			severity: 3,
			code: 4,
			message: 5
		});
		this.add('gulp-tsc', {
			regexp: /^([^\s].*)\((\d+|\d+,\d+|\d+,\d+,\d+,\d+)\):\s+(\d+)\s+(.*)$/,
1187
			kind: ProblemLocationKind.Location,
1188 1189 1190 1191 1192 1193 1194
			file: 1,
			location: 2,
			code: 3,
			message: 4
		});
		this.add('cpp', {
			regexp: /^([^\s].*)\((\d+|\d+,\d+|\d+,\d+,\d+,\d+)\):\s+(error|warning|info)\s+(C\d+)\s*:\s*(.*)$/,
1195
			kind: ProblemLocationKind.Location,
1196 1197 1198 1199 1200 1201 1202 1203
			file: 1,
			location: 2,
			severity: 3,
			code: 4,
			message: 5
		});
		this.add('csc', {
			regexp: /^([^\s].*)\((\d+|\d+,\d+|\d+,\d+,\d+,\d+)\):\s+(error|warning|info)\s+(CS\d+)\s*:\s*(.*)$/,
1204
			kind: ProblemLocationKind.Location,
1205 1206 1207 1208 1209 1210 1211 1212
			file: 1,
			location: 2,
			severity: 3,
			code: 4,
			message: 5
		});
		this.add('vb', {
			regexp: /^([^\s].*)\((\d+|\d+,\d+|\d+,\d+,\d+,\d+)\):\s+(error|warning|info)\s+(BC\d+)\s*:\s*(.*)$/,
1213
			kind: ProblemLocationKind.Location,
1214 1215 1216 1217 1218 1219 1220 1221
			file: 1,
			location: 2,
			severity: 3,
			code: 4,
			message: 5
		});
		this.add('lessCompile', {
			regexp: /^\s*(.*) in file (.*) line no. (\d+)$/,
1222
			kind: ProblemLocationKind.Location,
1223 1224 1225 1226 1227 1228
			message: 1,
			file: 2,
			line: 3
		});
		this.add('jshint', {
			regexp: /^(.*):\s+line\s+(\d+),\s+col\s+(\d+),\s(.+?)(?:\s+\((\w)(\d+)\))?$/,
1229
			kind: ProblemLocationKind.Location,
1230 1231
			file: 1,
			line: 2,
1232
			character: 3,
1233 1234 1235 1236 1237 1238 1239
			message: 4,
			severity: 5,
			code: 6
		});
		this.add('jshint-stylish', [
			{
				regexp: /^(.+)$/,
1240
				kind: ProblemLocationKind.Location,
1241 1242 1243 1244 1245
				file: 1
			},
			{
				regexp: /^\s+line\s+(\d+)\s+col\s+(\d+)\s+(.+?)(?:\s+\((\w)(\d+)\))?$/,
				line: 1,
1246
				character: 2,
1247 1248 1249 1250 1251 1252 1253 1254 1255
				message: 3,
				severity: 4,
				code: 5,
				loop: true
			}
		]);
		this.add('eslint-compact', {
			regexp: /^(.+):\sline\s(\d+),\scol\s(\d+),\s(Error|Warning|Info)\s-\s(.+)\s\((.+)\)$/,
			file: 1,
1256
			kind: ProblemLocationKind.Location,
1257
			line: 2,
1258
			character: 3,
1259 1260 1261 1262 1263 1264 1265
			severity: 4,
			message: 5,
			code: 6
		});
		this.add('eslint-stylish', [
			{
				regexp: /^([^\s].*)$/,
1266
				kind: ProblemLocationKind.Location,
1267 1268 1269
				file: 1
			},
			{
1270
				regexp: /^\s+(\d+):(\d+)\s+(error|warning|info)\s+(.+?)(?:\s\s+(.*))?$/,
1271
				line: 1,
1272
				character: 2,
1273 1274 1275 1276 1277 1278 1279 1280
				severity: 3,
				message: 4,
				code: 5,
				loop: true
			}
		]);
		this.add('go', {
			regexp: /^([^:]*: )?((.:)?[^:]*):(\d+)(:(\d+))?: (.*)$/,
1281
			kind: ProblemLocationKind.Location,
1282 1283
			file: 2,
			line: 4,
1284
			character: 6,
1285 1286 1287 1288 1289 1290
			message: 7
		});
	}
}

export const ProblemPatternRegistry: IProblemPatternRegistry = new ProblemPatternRegistryImpl();
E
Erich Gamma 已提交
1291

1292
export class ProblemMatcherParser extends Parser {
E
Erich Gamma 已提交
1293

1294 1295
	constructor(logger: IProblemReporter) {
		super(logger);
E
Erich Gamma 已提交
1296 1297
	}

A
Alex Ross 已提交
1298
	public parse(json: Config.ProblemMatcher): ProblemMatcher | undefined {
E
Erich Gamma 已提交
1299 1300
		let result = this.createProblemMatcher(json);
		if (!this.checkProblemMatcherValid(json, result)) {
A
Alex Ross 已提交
1301
			return undefined;
E
Erich Gamma 已提交
1302 1303 1304 1305 1306 1307
		}
		this.addWatchingMatcher(json, result);

		return result;
	}

1308
	private checkProblemMatcherValid(externalProblemMatcher: Config.ProblemMatcher, problemMatcher: ProblemMatcher | null): problemMatcher is ProblemMatcher {
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
		if (!problemMatcher) {
			this.error(localize('ProblemMatcherParser.noProblemMatcher', 'Error: the description can\'t be converted into a problem matcher:\n{0}\n', JSON.stringify(externalProblemMatcher, null, 4)));
			return false;
		}
		if (!problemMatcher.pattern) {
			this.error(localize('ProblemMatcherParser.noProblemPattern', 'Error: the description doesn\'t define a valid problem pattern:\n{0}\n', JSON.stringify(externalProblemMatcher, null, 4)));
			return false;
		}
		if (!problemMatcher.owner) {
			this.error(localize('ProblemMatcherParser.noOwner', 'Error: the description doesn\'t define an owner:\n{0}\n', JSON.stringify(externalProblemMatcher, null, 4)));
			return false;
		}
		if (Types.isUndefined(problemMatcher.fileLocation)) {
			this.error(localize('ProblemMatcherParser.noFileLocation', 'Error: the description doesn\'t define a file location:\n{0}\n', JSON.stringify(externalProblemMatcher, null, 4)));
E
Erich Gamma 已提交
1323 1324 1325 1326 1327
			return false;
		}
		return true;
	}

1328
	private createProblemMatcher(description: Config.ProblemMatcher): ProblemMatcher | null {
1329
		let result: ProblemMatcher | null = null;
E
Erich Gamma 已提交
1330

1331
		let owner = Types.isString(description.owner) ? description.owner : UUID.generateUuid();
1332
		let source = Types.isString(description.source) ? description.source : undefined;
E
Erich Gamma 已提交
1333 1334 1335 1336
		let applyTo = Types.isString(description.applyTo) ? ApplyToKind.fromString(description.applyTo) : ApplyToKind.allDocuments;
		if (!applyTo) {
			applyTo = ApplyToKind.allDocuments;
		}
1337 1338
		let fileLocation: FileLocationKind | undefined = undefined;
		let filePrefix: string | undefined = undefined;
E
Erich Gamma 已提交
1339

1340
		let kind: FileLocationKind | undefined;
E
Erich Gamma 已提交
1341 1342
		if (Types.isUndefined(description.fileLocation)) {
			fileLocation = FileLocationKind.Relative;
1343
			filePrefix = '${workspaceFolder}';
E
Erich Gamma 已提交
1344 1345 1346 1347 1348
		} else if (Types.isString(description.fileLocation)) {
			kind = FileLocationKind.fromString(<string>description.fileLocation);
			if (kind) {
				fileLocation = kind;
				if (kind === FileLocationKind.Relative) {
1349
					filePrefix = '${workspaceFolder}';
E
Erich Gamma 已提交
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368
				}
			}
		} else if (Types.isStringArray(description.fileLocation)) {
			let values = <string[]>description.fileLocation;
			if (values.length > 0) {
				kind = FileLocationKind.fromString(values[0]);
				if (values.length === 1 && kind === FileLocationKind.Absolute) {
					fileLocation = kind;
				} else if (values.length === 2 && kind === FileLocationKind.Relative && values[1]) {
					fileLocation = kind;
					filePrefix = values[1];
				}
			}
		}

		let pattern = description.pattern ? this.createProblemPattern(description.pattern) : undefined;

		let severity = description.severity ? Severity.fromValue(description.severity) : undefined;
		if (severity === Severity.Ignore) {
1369
			this.info(localize('ProblemMatcherParser.unknownSeverity', 'Info: unknown severity {0}. Valid values are error, warning and info.\n', description.severity));
E
Erich Gamma 已提交
1370 1371 1372 1373 1374 1375
			severity = Severity.Error;
		}

		if (Types.isString(description.base)) {
			let variableName = <string>description.base;
			if (variableName.length > 1 && variableName[0] === '$') {
1376
				let base = ProblemMatcherRegistry.get(variableName.substring(1));
E
Erich Gamma 已提交
1377
				if (base) {
J
Johannes Rieken 已提交
1378
					result = Objects.deepClone(base);
R
Rob Lourens 已提交
1379
					if (description.owner !== undefined && owner !== undefined) {
E
Erich Gamma 已提交
1380 1381
						result.owner = owner;
					}
R
Rob Lourens 已提交
1382
					if (description.source !== undefined && source !== undefined) {
1383 1384
						result.source = source;
					}
R
Rob Lourens 已提交
1385
					if (description.fileLocation !== undefined && fileLocation !== undefined) {
E
Erich Gamma 已提交
1386 1387 1388
						result.fileLocation = fileLocation;
						result.filePrefix = filePrefix;
					}
R
Rob Lourens 已提交
1389
					if (description.pattern !== undefined && pattern !== undefined && pattern !== null) {
E
Erich Gamma 已提交
1390 1391
						result.pattern = pattern;
					}
R
Rob Lourens 已提交
1392
					if (description.severity !== undefined && severity !== undefined) {
E
Erich Gamma 已提交
1393 1394
						result.severity = severity;
					}
R
Rob Lourens 已提交
1395
					if (description.applyTo !== undefined && applyTo !== undefined) {
1396 1397
						result.applyTo = applyTo;
					}
E
Erich Gamma 已提交
1398 1399
				}
			}
1400
		} else if (fileLocation && pattern) {
E
Erich Gamma 已提交
1401 1402 1403 1404 1405 1406
			result = {
				owner: owner,
				applyTo: applyTo,
				fileLocation: fileLocation,
				pattern: pattern,
			};
1407 1408 1409
			if (source) {
				result.source = source;
			}
E
Erich Gamma 已提交
1410 1411 1412 1413 1414 1415 1416 1417
			if (filePrefix) {
				result.filePrefix = filePrefix;
			}
			if (severity) {
				result.severity = severity;
			}
		}
		if (Config.isNamedProblemMatcher(description)) {
1418 1419
			(result as NamedProblemMatcher).name = description.name;
			(result as NamedProblemMatcher).label = Types.isString(description.label) ? description.label : description.name;
E
Erich Gamma 已提交
1420 1421 1422 1423
		}
		return result;
	}

1424
	private createProblemPattern(value: string | Config.ProblemPattern | Config.MultiLineProblemPattern): ProblemPattern | ProblemPattern[] | null {
E
Erich Gamma 已提交
1425
		if (Types.isString(value)) {
D
Dirk Baeumer 已提交
1426
			let variableName: string = <string>value;
E
Erich Gamma 已提交
1427
			if (variableName.length > 1 && variableName[0] === '$') {
1428 1429
				let result = ProblemPatternRegistry.get(variableName.substring(1));
				if (!result) {
D
Dirk Baeumer 已提交
1430
					this.error(localize('ProblemMatcherParser.noDefinedPatter', 'Error: the pattern with the identifier {0} doesn\'t exist.', variableName));
1431 1432 1433 1434 1435 1436
				}
				return result;
			} else {
				if (variableName.length === 0) {
					this.error(localize('ProblemMatcherParser.noIdentifier', 'Error: the pattern property refers to an empty identifier.'));
				} else {
D
Dirk Baeumer 已提交
1437
					this.error(localize('ProblemMatcherParser.noValidIdentifier', 'Error: the pattern property {0} is not a valid pattern variable name.', variableName));
1438
				}
E
Erich Gamma 已提交
1439
			}
1440 1441
		} else if (value) {
			let problemPatternParser = new ProblemPatternParser(this.problemReporter);
1442 1443 1444 1445 1446
			if (Array.isArray(value)) {
				return problemPatternParser.parse(value);
			} else {
				return problemPatternParser.parse(value);
			}
E
Erich Gamma 已提交
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
		}
		return null;
	}

	private addWatchingMatcher(external: Config.ProblemMatcher, internal: ProblemMatcher): void {
		let oldBegins = this.createRegularExpression(external.watchedTaskBeginsRegExp);
		let oldEnds = this.createRegularExpression(external.watchedTaskEndsRegExp);
		if (oldBegins && oldEnds) {
			internal.watching = {
				activeOnStart: false,
				beginsPattern: { regexp: oldBegins },
				endsPattern: { regexp: oldEnds }
1459
			};
E
Erich Gamma 已提交
1460 1461
			return;
		}
1462 1463
		let backgroundMonitor = external.background || external.watching;
		if (Types.isUndefinedOrNull(backgroundMonitor)) {
E
Erich Gamma 已提交
1464 1465
			return;
		}
1466 1467
		let begins: WatchingPattern | null = this.createWatchingPattern(backgroundMonitor.beginsPattern);
		let ends: WatchingPattern | null = this.createWatchingPattern(backgroundMonitor.endsPattern);
E
Erich Gamma 已提交
1468 1469
		if (begins && ends) {
			internal.watching = {
1470
				activeOnStart: Types.isBoolean(backgroundMonitor.activeOnStart) ? backgroundMonitor.activeOnStart : false,
E
Erich Gamma 已提交
1471 1472
				beginsPattern: begins,
				endsPattern: ends
1473
			};
E
Erich Gamma 已提交
1474 1475 1476
			return;
		}
		if (begins || ends) {
1477
			this.error(localize('ProblemMatcherParser.problemPattern.watchingMatcher', 'A problem matcher must define both a begin pattern and an end pattern for watching.'));
E
Erich Gamma 已提交
1478 1479 1480
		}
	}

1481
	private createWatchingPattern(external: string | Config.WatchingPattern | undefined): WatchingPattern | null {
E
Erich Gamma 已提交
1482 1483 1484
		if (Types.isUndefinedOrNull(external)) {
			return null;
		}
1485 1486
		let regexp: RegExp | null;
		let file: number | undefined;
E
Erich Gamma 已提交
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
		if (Types.isString(external)) {
			regexp = this.createRegularExpression(external);
		} else {
			regexp = this.createRegularExpression(external.regexp);
			if (Types.isNumber(external.file)) {
				file = external.file;
			}
		}
		if (!regexp) {
			return null;
		}
1498
		return file ? { regexp, file } : { regexp, file: 1 };
E
Erich Gamma 已提交
1499 1500
	}

1501
	private createRegularExpression(value: string | undefined): RegExp | null {
1502
		let result: RegExp | null = null;
E
Erich Gamma 已提交
1503 1504 1505 1506 1507 1508
		if (!value) {
			return result;
		}
		try {
			result = new RegExp(value);
		} catch (err) {
1509
			this.error(localize('ProblemMatcherParser.invalidRegexp', 'Error: The string {0} is not a valid regular expression.\n', value));
E
Erich Gamma 已提交
1510 1511 1512 1513 1514
		}
		return result;
	}
}

1515 1516 1517 1518 1519 1520 1521 1522
export namespace Schemas {

	export const WatchingPattern: IJSONSchema = {
		type: 'object',
		additionalProperties: false,
		properties: {
			regexp: {
				type: 'string',
1523
				description: localize('WatchingPatternSchema.regexp', 'The regular expression to detect the begin or end of a background task.')
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
			},
			file: {
				type: 'integer',
				description: localize('WatchingPatternSchema.file', 'The match group index of the filename. Can be omitted.')
			},
		}
	};


	export const PatternType: IJSONSchema = {
		anyOf: [
			{
				type: 'string',
				description: localize('PatternTypeSchema.name', 'The name of a contributed or predefined pattern')
			},
			Schemas.ProblemPattern,
1540
			Schemas.MultiLineProblemPattern
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556
		],
		description: localize('PatternTypeSchema.description', 'A problem pattern or the name of a contributed or predefined problem pattern. Can be omitted if base is specified.')
	};

	export const ProblemMatcher: IJSONSchema = {
		type: 'object',
		additionalProperties: false,
		properties: {
			base: {
				type: 'string',
				description: localize('ProblemMatcherSchema.base', 'The name of a base problem matcher to use.')
			},
			owner: {
				type: 'string',
				description: localize('ProblemMatcherSchema.owner', 'The owner of the problem inside Code. Can be omitted if base is specified. Defaults to \'external\' if omitted and base is not specified.')
			},
1557 1558 1559 1560
			source: {
				type: 'string',
				description: localize('ProblemMatcherSchema.source', 'A human-readable string describing the source of this diagnostic, e.g. \'typescript\' or \'super lint\'.')
			},
1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
			severity: {
				type: 'string',
				enum: ['error', 'warning', 'info'],
				description: localize('ProblemMatcherSchema.severity', 'The default severity for captures problems. Is used if the pattern doesn\'t define a match group for severity.')
			},
			applyTo: {
				type: 'string',
				enum: ['allDocuments', 'openDocuments', 'closedDocuments'],
				description: localize('ProblemMatcherSchema.applyTo', 'Controls if a problem reported on a text document is applied only to open, closed or all documents.')
			},
			pattern: PatternType,
			fileLocation: {
				oneOf: [
					{
						type: 'string',
						enum: ['absolute', 'relative']
					},
					{
						type: 'array',
						items: {
							type: 'string'
						}
					}
				],
				description: localize('ProblemMatcherSchema.fileLocation', 'Defines how file names reported in a problem pattern should be interpreted.')
			},
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
			background: {
				type: 'object',
				additionalProperties: false,
				description: localize('ProblemMatcherSchema.background', 'Patterns to track the begin and end of a matcher active on a background task.'),
				properties: {
					activeOnStart: {
						type: 'boolean',
						description: localize('ProblemMatcherSchema.background.activeOnStart', 'If set to true the background monitor is in active mode when the task starts. This is equals of issuing a line that matches the beginPattern')
					},
					beginsPattern: {
						oneOf: [
							{
								type: 'string'
							},
							Schemas.WatchingPattern
						],
						description: localize('ProblemMatcherSchema.background.beginsPattern', 'If matched in the output the start of a background task is signaled.')
					},
					endsPattern: {
						oneOf: [
							{
								type: 'string'
							},
							Schemas.WatchingPattern
						],
						description: localize('ProblemMatcherSchema.background.endsPattern', 'If matched in the output the end of a background task is signaled.')
					}
				}
			},
1616 1617 1618
			watching: {
				type: 'object',
				additionalProperties: false,
1619 1620
				deprecationMessage: localize('ProblemMatcherSchema.watching.deprecated', 'The watching property is deprecated. Use background instead.'),
				description: localize('ProblemMatcherSchema.watching', 'Patterns to track the begin and end of a watching matcher.'),
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643
				properties: {
					activeOnStart: {
						type: 'boolean',
						description: localize('ProblemMatcherSchema.watching.activeOnStart', 'If set to true the watcher is in active mode when the task starts. This is equals of issuing a line that matches the beginPattern')
					},
					beginsPattern: {
						oneOf: [
							{
								type: 'string'
							},
							Schemas.WatchingPattern
						],
						description: localize('ProblemMatcherSchema.watching.beginsPattern', 'If matched in the output the start of a watching task is signaled.')
					},
					endsPattern: {
						oneOf: [
							{
								type: 'string'
							},
							Schemas.WatchingPattern
						],
						description: localize('ProblemMatcherSchema.watching.endsPattern', 'If matched in the output the end of a watching task is signaled.')
					}
1644
				}
1645 1646 1647 1648
			}
		}
	};

J
Johannes Rieken 已提交
1649
	export const LegacyProblemMatcher: IJSONSchema = Objects.deepClone(ProblemMatcher);
1650
	LegacyProblemMatcher.properties = Objects.deepClone(LegacyProblemMatcher.properties) || {};
1651 1652
	LegacyProblemMatcher.properties['watchedTaskBeginsRegExp'] = {
		type: 'string',
1653 1654
		deprecationMessage: localize('LegacyProblemMatcherSchema.watchedBegin.deprecated', 'This property is deprecated. Use the watching property instead.'),
		description: localize('LegacyProblemMatcherSchema.watchedBegin', 'A regular expression signaling that a watched tasks begins executing triggered through file watching.')
1655 1656 1657
	};
	LegacyProblemMatcher.properties['watchedTaskEndsRegExp'] = {
		type: 'string',
1658 1659
		deprecationMessage: localize('LegacyProblemMatcherSchema.watchedEnd.deprecated', 'This property is deprecated. Use the watching property instead.'),
		description: localize('LegacyProblemMatcherSchema.watchedEnd', 'A regular expression signaling that a watched tasks ends executing.')
1660 1661
	};

J
Johannes Rieken 已提交
1662
	export const NamedProblemMatcher: IJSONSchema = Objects.deepClone(ProblemMatcher);
1663
	NamedProblemMatcher.properties = Objects.deepClone(NamedProblemMatcher.properties) || {};
1664
	NamedProblemMatcher.properties.name = {
1665
		type: 'string',
1666 1667 1668 1669 1670
		description: localize('NamedProblemMatcherSchema.name', 'The name of the problem matcher used to refer to it.')
	};
	NamedProblemMatcher.properties.label = {
		type: 'string',
		description: localize('NamedProblemMatcherSchema.label', 'A human readable label of the problem matcher.')
1671 1672 1673
	};
}

1674 1675 1676 1677 1678 1679 1680
const problemMatchersExtPoint = ExtensionsRegistry.registerExtensionPoint<Config.NamedProblemMatcher[]>({
	extensionPoint: 'problemMatchers',
	deps: [problemPatternExtPoint],
	jsonSchema: {
		description: localize('ProblemMatcherExtPoint', 'Contributes problem matchers'),
		type: 'array',
		items: Schemas.NamedProblemMatcher
1681
	}
1682 1683 1684
});

export interface IProblemMatcherRegistry {
D
Dirk Baeumer 已提交
1685
	onReady(): Promise<void>;
1686
	get(name: string): NamedProblemMatcher;
1687
	keys(): string[];
M
Matt Bierner 已提交
1688
	readonly onMatcherChanged: Event<void>;
1689 1690 1691
}

class ProblemMatcherRegistryImpl implements IProblemMatcherRegistry {
E
Erich Gamma 已提交
1692

1693
	private matchers: IStringDictionary<NamedProblemMatcher>;
D
Dirk Baeumer 已提交
1694
	private readyPromise: Promise<void>;
M
Matt Bierner 已提交
1695
	private readonly _onMatchersChanged: Emitter<void> = new Emitter<void>();
1696 1697
	public get onMatcherChanged(): Event<void> { return this._onMatchersChanged.event; }

E
Erich Gamma 已提交
1698 1699 1700

	constructor() {
		this.matchers = Object.create(null);
1701
		this.fillDefaults();
D
Dirk Baeumer 已提交
1702
		this.readyPromise = new Promise<void>((resolve, reject) => {
1703
			problemMatchersExtPoint.setHandler((extensions, delta) => {
1704
				try {
1705 1706 1707 1708 1709 1710 1711 1712 1713
					delta.removed.forEach(extension => {
						let problemMatchers = extension.value;
						for (let matcher of problemMatchers) {
							if (this.matchers[matcher.name]) {
								delete this.matchers[matcher.name];
							}
						}
					});
					delta.added.forEach(extension => {
1714 1715 1716 1717 1718
						let problemMatchers = extension.value;
						let parser = new ProblemMatcherParser(new ExtensionRegistryReporter(extension.collector));
						for (let matcher of problemMatchers) {
							let result = parser.parse(matcher);
							if (result && isNamedProblemMatcher(result)) {
1719
								this.add(result);
1720 1721 1722
							}
						}
					});
1723 1724 1725
					if ((delta.removed.length > 0) || (delta.added.length > 0)) {
						this._onMatchersChanged.fire();
					}
1726
				} catch (error) {
E
Erich Gamma 已提交
1727
				}
1728 1729 1730 1731 1732
				let matcher = this.get('tsc-watch');
				if (matcher) {
					(<any>matcher).tscWatch = true;
				}
				resolve(undefined);
E
Erich Gamma 已提交
1733
			});
1734
		});
E
Erich Gamma 已提交
1735 1736
	}

D
Dirk Baeumer 已提交
1737
	public onReady(): Promise<void> {
D
Dirk Baeumer 已提交
1738
		ProblemPatternRegistry.onReady();
1739 1740
		return this.readyPromise;
	}
E
Erich Gamma 已提交
1741

1742 1743
	public add(matcher: NamedProblemMatcher): void {
		this.matchers[matcher.name] = matcher;
E
Erich Gamma 已提交
1744 1745
	}

1746
	public get(name: string): NamedProblemMatcher {
E
Erich Gamma 已提交
1747 1748 1749
		return this.matchers[name];
	}

1750 1751 1752 1753
	public keys(): string[] {
		return Object.keys(this.matchers);
	}

1754
	private fillDefaults(): void {
1755 1756 1757
		this.add({
			name: 'msCompile',
			label: localize('msCompile', 'Microsoft compiler problems'),
1758 1759 1760 1761 1762
			owner: 'msCompile',
			applyTo: ApplyToKind.allDocuments,
			fileLocation: FileLocationKind.Absolute,
			pattern: ProblemPatternRegistry.get('msCompile')
		});
E
Erich Gamma 已提交
1763

1764 1765 1766
		this.add({
			name: 'lessCompile',
			label: localize('lessCompile', 'Less problems'),
1767
			deprecated: true,
1768
			owner: 'lessCompile',
1769
			source: 'less',
1770 1771 1772 1773 1774
			applyTo: ApplyToKind.allDocuments,
			fileLocation: FileLocationKind.Absolute,
			pattern: ProblemPatternRegistry.get('lessCompile'),
			severity: Severity.Error
		});
E
Erich Gamma 已提交
1775

1776 1777 1778
		this.add({
			name: 'gulp-tsc',
			label: localize('gulp-tsc', 'Gulp TSC Problems'),
1779
			owner: 'typescript',
1780
			source: 'ts',
1781 1782
			applyTo: ApplyToKind.closedDocuments,
			fileLocation: FileLocationKind.Relative,
1783
			filePrefix: '${workspaceFolder}',
1784 1785
			pattern: ProblemPatternRegistry.get('gulp-tsc')
		});
E
Erich Gamma 已提交
1786

1787 1788 1789
		this.add({
			name: 'jshint',
			label: localize('jshint', 'JSHint problems'),
1790
			owner: 'jshint',
1791
			source: 'jshint',
1792 1793 1794 1795
			applyTo: ApplyToKind.allDocuments,
			fileLocation: FileLocationKind.Absolute,
			pattern: ProblemPatternRegistry.get('jshint')
		});
E
Erich Gamma 已提交
1796

1797 1798 1799
		this.add({
			name: 'jshint-stylish',
			label: localize('jshint-stylish', 'JSHint stylish problems'),
1800
			owner: 'jshint',
1801
			source: 'jshint',
1802 1803 1804 1805
			applyTo: ApplyToKind.allDocuments,
			fileLocation: FileLocationKind.Absolute,
			pattern: ProblemPatternRegistry.get('jshint-stylish')
		});
E
Erich Gamma 已提交
1806

1807 1808 1809
		this.add({
			name: 'eslint-compact',
			label: localize('eslint-compact', 'ESLint compact problems'),
1810
			owner: 'eslint',
1811
			source: 'eslint',
1812
			applyTo: ApplyToKind.allDocuments,
1813
			fileLocation: FileLocationKind.Absolute,
1814
			filePrefix: '${workspaceFolder}',
1815 1816
			pattern: ProblemPatternRegistry.get('eslint-compact')
		});
E
Erich Gamma 已提交
1817

1818 1819 1820
		this.add({
			name: 'eslint-stylish',
			label: localize('eslint-stylish', 'ESLint stylish problems'),
1821
			owner: 'eslint',
1822
			source: 'eslint',
1823 1824 1825 1826
			applyTo: ApplyToKind.allDocuments,
			fileLocation: FileLocationKind.Absolute,
			pattern: ProblemPatternRegistry.get('eslint-stylish')
		});
E
Erich Gamma 已提交
1827

1828 1829 1830
		this.add({
			name: 'go',
			label: localize('go', 'Go problems'),
1831
			owner: 'go',
1832
			source: 'go',
1833 1834
			applyTo: ApplyToKind.allDocuments,
			fileLocation: FileLocationKind.Relative,
1835
			filePrefix: '${workspaceFolder}',
1836 1837 1838 1839
			pattern: ProblemPatternRegistry.get('go')
		});
	}
}
D
Dan Mace 已提交
1840

1841
export const ProblemMatcherRegistry: IProblemMatcherRegistry = new ProblemMatcherRegistryImpl();