Skip to content

Commit

Permalink
Tactical fix for watching problem matcher and closed documents
Browse files Browse the repository at this point in the history
Fixes #116760
  • Loading branch information
alexr00 committed Mar 16, 2021
1 parent d1e5c8c commit df97bc3
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/vs/workbench/contrib/tasks/common/problemCollectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export abstract class AbstractProblemCollector implements IDisposable {
private buffer: string[];
private bufferLength: number;
private openModels: IStringDictionary<boolean>;
private readonly modelListeners = new DisposableStore();
protected readonly modelListeners = new DisposableStore();
private tail: Promise<void> | undefined;

// [owner] -> ApplyToKind
Expand All @@ -58,7 +58,7 @@ export abstract class AbstractProblemCollector implements IDisposable {

protected _onDidStateChange: Emitter<ProblemCollectorEvent>;

constructor(problemMatchers: ProblemMatcher[], protected markerService: IMarkerService, private modelService: IModelService, fileService?: IFileService) {
constructor(problemMatchers: ProblemMatcher[], protected markerService: IMarkerService, protected modelService: IModelService, fileService?: IFileService) {
this.matchers = Object.create(null);
this.bufferLength = 1;
problemMatchers.map(elem => createLineMatcher(elem, fileService)).forEach((matcher) => {
Expand Down Expand Up @@ -406,6 +406,8 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
private currentOwner: string | undefined;
private currentResource: string | undefined;

private lines: string[] = [];

constructor(problemMatchers: ProblemMatcher[], markerService: IMarkerService, modelService: IModelService, fileService?: IFileService) {
super(problemMatchers, markerService, modelService, fileService);
this.problemMatchers = problemMatchers;
Expand All @@ -423,6 +425,27 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
});
}
});

this.modelListeners.add(this.modelService.onModelRemoved(modelEvent => {
let markerChanged: IDisposable | undefined =
Event.debounce(this.markerService.onMarkerChanged, (last: readonly URI[] | undefined, e: readonly URI[]) => {
return (last ?? []).concat(e);
}, 500)(async (markerEvent) => {
markerChanged?.dispose();
markerChanged = undefined;
if (!markerEvent.includes(modelEvent.uri)) {
return;
}
const oldLines = Array.from(this.lines);
for (const line of oldLines) {
await this.processLineInternal(line);
}
});
setTimeout(async () => {
markerChanged?.dispose();
markerChanged = undefined;
}, 600);
}));
}

public aboutToStart(): void {
Expand All @@ -439,6 +462,7 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
if (await this.tryBegin(line) || this.tryFinish(line)) {
return;
}
this.lines.push(line);
let markerMatch = this.tryFindMarker(line);
if (!markerMatch) {
return;
Expand Down Expand Up @@ -472,6 +496,8 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
}
this._activeBackgroundMatchers.add(background.key);
result = true;
this.lines = [];
this.lines.push(line);
this._onDidStateChange.fire(ProblemCollectorEvent.create(ProblemCollectorEventKind.BackgroundProcessingBegins));
this.cleanMarkerCaches();
this.resetCurrentResource();
Expand All @@ -498,6 +524,7 @@ export class WatchingProblemCollector extends AbstractProblemCollector implement
this.resetCurrentResource();
this._onDidStateChange.fire(ProblemCollectorEvent.create(ProblemCollectorEventKind.BackgroundProcessingEnds));
result = true;
this.lines.push(line);
let owner = background.matcher.owner;
this.cleanMarkers(owner);
this.cleanMarkerCaches();
Expand Down

0 comments on commit df97bc3

Please sign in to comment.