Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PPromise usage from task world #53875

Merged
merged 1 commit into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/vs/base/node/processes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as path from 'path';
import * as cp from 'child_process';
import { fork } from 'vs/base/node/stdFork';
import * as nls from 'vs/nls';
import { PPromise, TPromise, TValueCallback, TProgressCallback, ErrorCallback } from 'vs/base/common/winjs.base';
import { TPromise, TValueCallback, ErrorCallback } from 'vs/base/common/winjs.base';
import * as Types from 'vs/base/common/types';
import { IStringDictionary } from 'vs/base/common/collections';
import URI from 'vs/base/common/uri';
Expand All @@ -19,6 +19,8 @@ import { LineDecoder } from 'vs/base/node/decoder';
import { CommandOptions, ForkOptions, SuccessData, Source, TerminateResponse, TerminateResponseCode, Executable } from 'vs/base/common/processes';
export { CommandOptions, ForkOptions, SuccessData, Source, TerminateResponse, TerminateResponseCode };

export type TProgressCallback<T> = (progress: T) => void;

export interface LineData {
line: string;
source: Source;
Expand Down Expand Up @@ -152,18 +154,16 @@ export abstract class AbstractProcess<TProgressData> {
return 'other';
}

public start(): PPromise<SuccessData, TProgressData> {
public start(pp: TProgressCallback<TProgressData>): TPromise<SuccessData> {
if (Platform.isWindows && ((this.options && this.options.cwd && TPath.isUNC(this.options.cwd)) || !this.options && !this.options.cwd && TPath.isUNC(process.cwd()))) {
return TPromise.wrapError(new Error(nls.localize('TaskRunner.UNC', 'Can\'t execute a shell command on a UNC drive.')));
}
return this.useExec().then((useExec) => {
let cc: TValueCallback<SuccessData>;
let ee: ErrorCallback;
let pp: TProgressCallback<TProgressData>;
let result = new PPromise<any, TProgressData>((c, e, p) => {
let result = new TPromise<any>((c, e) => {
cc = c;
ee = e;
pp = p;
});

if (useExec) {
Expand Down
27 changes: 15 additions & 12 deletions src/vs/workbench/parts/tasks/node/processRunnerDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as Strings from 'vs/base/common/strings';
import * as Collections from 'vs/base/common/collections';

import { CommandOptions, Source, ErrorData } from 'vs/base/common/processes';
import { LineProcess } from 'vs/base/node/processes';
import { LineProcess, LineData } from 'vs/base/node/processes';

import { IFileService } from 'vs/platform/files/common/files';

Expand Down Expand Up @@ -269,7 +269,20 @@ export class ProcessRunnerDetector {
private runDetection(process: LineProcess, command: string, isShellCommand: boolean, matcher: TaskDetectorMatcher, problemMatchers: string[], list: boolean): TPromise<DetectorResult> {
let tasks: string[] = [];
matcher.init();
return process.start().then((success) => {

const onProgress = (progress: LineData) => {
if (progress.source === Source.stderr) {
this._stderr.push(progress.line);
return;
}
let line = Strings.removeAnsiEscapeCodes(progress.line);
let matches = matcher.match(tasks, line);
if (matches && matches.length > 0) {
tasks.push(matches[1]);
}
};

return process.start(onProgress).then((success) => {
if (tasks.length === 0) {
if (success.cmdCode !== 0) {
if (command === 'gulp') {
Expand Down Expand Up @@ -305,16 +318,6 @@ export class ProcessRunnerDetector {
this._stderr.push(nls.localize('TaskSystemDetector.noProgram', 'Program {0} was not found. Message is {1}', command, error.message));
}
return { config: null, stdout: this._stdout, stderr: this._stderr };
}, (progress) => {
if (progress.source === Source.stderr) {
this._stderr.push(progress.line);
return;
}
let line = Strings.removeAnsiEscapeCodes(progress.line);
let matches = matcher.match(tasks, line);
if (matches && matches.length > 0) {
tasks.push(matches[1]);
}
});
}

Expand Down
40 changes: 21 additions & 19 deletions src/vs/workbench/parts/tasks/node/processTaskSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,21 @@ export class ProcessTaskSystem implements ITaskSystem {
this.activeTask = task;
const inactiveEvent = TaskEvent.create(TaskEventKind.Inactive, task);
let processStartedSignaled: boolean = false;
const startPromise = this.childProcess.start();
const onProgress = (progress: LineData) => {
let line = Strings.removeAnsiEscapeCodes(progress.line);
this.outputChannel.append(line + '\n');
watchingProblemMatcher.processLine(line);
if (delayer === null) {
delayer = new Async.Delayer(3000);
}
delayer.trigger(() => {
watchingProblemMatcher.forceDelivery();
return null;
}).then(() => {
delayer = null;
});
};
const startPromise = this.childProcess.start(onProgress);
this.childProcess.pid.then(pid => {
if (pid !== -1) {
processStartedSignaled = true;
Expand Down Expand Up @@ -287,19 +301,6 @@ export class ProcessTaskSystem implements ITaskSystem {
}
eventCounter = 0;
return this.handleError(task, error);
}, (progress: LineData) => {
let line = Strings.removeAnsiEscapeCodes(progress.line);
this.outputChannel.append(line + '\n');
watchingProblemMatcher.processLine(line);
if (delayer === null) {
delayer = new Async.Delayer(3000);
}
delayer.trigger(() => {
watchingProblemMatcher.forceDelivery();
return null;
}).then(() => {
delayer = null;
});
});
let result: ITaskExecuteResult = (<any>task).tscWatch
? { kind: TaskExecuteKind.Started, started: { restartOnFileChanges: '**/*.ts' }, promise: this.activeTaskPromise }
Expand All @@ -312,7 +313,12 @@ export class ProcessTaskSystem implements ITaskSystem {
this.activeTask = task;
const inactiveEvent = TaskEvent.create(TaskEventKind.Inactive, task);
let processStartedSignaled: boolean = false;
const startPromise = this.childProcess.start();
const onProgress = (progress) => {
let line = Strings.removeAnsiEscapeCodes(progress.line);
this.outputChannel.append(line + '\n');
startStopProblemMatcher.processLine(line);
};
const startPromise = this.childProcess.start(onProgress);
this.childProcess.pid.then(pid => {
if (pid !== -1) {
processStartedSignaled = true;
Expand Down Expand Up @@ -340,10 +346,6 @@ export class ProcessTaskSystem implements ITaskSystem {
this._onDidStateChange.fire(inactiveEvent);
this._onDidStateChange.fire(TaskEvent.create(TaskEventKind.End, task));
return this.handleError(task, error);
}, (progress) => {
let line = Strings.removeAnsiEscapeCodes(progress.line);
this.outputChannel.append(line + '\n');
startStopProblemMatcher.processLine(line);
});
return { kind: TaskExecuteKind.Started, started: {}, promise: this.activeTaskPromise };
}
Expand Down