Skip to content

Commit

Permalink
support modifying existing problem matchers
Browse files Browse the repository at this point in the history
- VS Code supports the possibility of modifying existing problem matchers. With this change, Theia users can define a base problem matcher in which they can further customize the properties `background`, `fileLocation`, `applyTo`, `owner`, `severity`, `pattern`, and `source`.

- resolves #6427

Signed-off-by: Liang Huang <lhuang4@ualberta.ca>
  • Loading branch information
elaihau committed Apr 1, 2020
1 parent 5d20fac commit cf86e86
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
56 changes: 47 additions & 9 deletions packages/task/src/browser/task-problem-matcher-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,22 @@ export class ProblemMatcherRegistry {
* @return the problem matcher
*/
async getProblemMatcherFromContribution(matcher: ProblemMatcherContribution): Promise<ProblemMatcher> {
const { fileLocation, filePrefix } = this.getFileLocationKindAndPrefix(matcher);
let baseMatcher: NamedProblemMatcher | undefined;
if (matcher.base) {
baseMatcher = this.get(matcher.base);
}

let fileLocation: FileLocationKind | undefined;
let filePrefix: string | undefined;
if (matcher.fileLocation === undefined) {
fileLocation = baseMatcher ? baseMatcher.fileLocation : FileLocationKind.Relative;
filePrefix = baseMatcher ? baseMatcher.filePrefix : '${workspaceFolder}';
} else {
const locationAndPrefix = this.getFileLocationKindAndPrefix(matcher);
fileLocation = locationAndPrefix.fileLocation;
filePrefix = locationAndPrefix.filePrefix;
}

const patterns: ProblemPattern[] = [];
if (matcher.pattern) {
if (typeof matcher.pattern === 'string') {
Expand All @@ -128,19 +143,42 @@ export class ProblemMatcherRegistry {
} else {
patterns.push(ProblemPattern.fromProblemPatternContribution(matcher.pattern));
}
} else if (baseMatcher) {
patterns.push(...baseMatcher.pattern);
}

let deprecated: boolean | undefined = matcher.deprecated;
if (deprecated === undefined && baseMatcher) {
deprecated = baseMatcher.deprecated;
}

let applyTo: ApplyToKind | undefined;
if (matcher.applyTo === undefined) {
applyTo = baseMatcher ? baseMatcher.applyTo : ApplyToKind.allDocuments;
} else {
applyTo = ApplyToKind.fromString(matcher.applyTo) || ApplyToKind.allDocuments;
}

let severity: Severity = Severity.fromValue(matcher.severity);
if (matcher.severity === undefined && baseMatcher && baseMatcher.severity !== undefined) {
severity = baseMatcher.severity;
}
let watching: WatchingMatcher | undefined = WatchingMatcher.fromWatchingMatcherContribution(matcher.background || matcher.watching);
if (watching === undefined && baseMatcher) {
watching = baseMatcher.watching;
}
const problemMatcher = {
name: matcher.name,
label: matcher.label,
deprecated: matcher.deprecated,
owner: matcher.owner,
source: matcher.source,
applyTo: ApplyToKind.fromString(matcher.applyTo) || ApplyToKind.allDocuments,
name: matcher.name || (baseMatcher ? baseMatcher.name : undefined),
label: matcher.label || (baseMatcher ? baseMatcher.label : undefined),
deprecated,
owner: matcher.owner || (baseMatcher ? baseMatcher.owner : ''),
source: matcher.source || (baseMatcher ? baseMatcher.source : undefined),
applyTo,
fileLocation,
filePrefix,
pattern: patterns,
severity: Severity.fromValue(matcher.severity),
watching: WatchingMatcher.fromWatchingMatcherContribution(matcher.background || matcher.watching)
severity,
watching
};
return problemMatcher;
}
Expand Down
1 change: 1 addition & 0 deletions packages/task/src/browser/task-schema-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ const problemMatcherObject: IJSONSchema = {
properties: {
base: {
type: 'string',
enum: problemMatcherNames,
description: 'The name of a base problem matcher to use.'
},
owner: {
Expand Down
4 changes: 2 additions & 2 deletions packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ export class TaskService implements TaskConfigurationClient {
const resolvedTask = await this.getResolvedTask(task);
if (resolvedTask) {
// remove problem markers from the same source before running the task
await this.removeProblemMarks(option);
await this.removeProblemMarkers(option);
return this.runResolvedTask(resolvedTask, option);
}
}
Expand Down Expand Up @@ -869,7 +869,7 @@ export class TaskService implements TaskConfigurationClient {
return customizationObject;
}

private async removeProblemMarks(option?: RunTaskOption): Promise<void> {
private async removeProblemMarkers(option?: RunTaskOption): Promise<void> {
if (option && option.customization) {
const matchersFromOption = option.customization.problemMatcher || [];
for (const matcher of matchersFromOption) {
Expand Down
1 change: 1 addition & 0 deletions packages/task/src/common/task-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export interface WatchingMatcherContribution {
}

export interface ProblemMatcherContribution {
base?: string;
name?: string;
label: string;
deprecated?: boolean;
Expand Down

0 comments on commit cf86e86

Please sign in to comment.