Prototype Support for TSServer Request Cancelation (#22437)

This commit is contained in:
Matt Bierner
2017-03-20 12:03:51 -07:00
committed by GitHub
parent e1acce1342
commit 8c468dfd21
2 changed files with 27 additions and 4 deletions

View File

@@ -112,6 +112,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
private firstStart: number;
private lastStart: number;
private numberRestarts: number;
private cancellationPipeName: string | null = null;
private requestQueue: RequestItem[];
private pendingResponses: number;
@@ -453,6 +454,10 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
if (this.apiVersion.has208Features()) {
args.push('--enableTelemetry');
}
if (this.apiVersion.has220Features()) {
this.cancellationPipeName = electron.getPipeName(`tscancellation-${electron.makeRandomHexString(20)}`);
args.push('--cancellationPipeName', this.cancellationPipeName + '*');
}
electron.fork(modulePath, args, options, (err: any, childProcess: cp.ChildProcess) => {
if (err) {
this.lastError = err;
@@ -795,6 +800,19 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
return true;
}
}
if (this.apiVersion.has220Features() && this.cancellationPipeName) {
if (this.trace !== Trace.Off) {
this.logTrace(`TypeScript Service: trying to cancel ongoing request with sequence number ${seq}`);
}
try {
fs.writeFileSync(this.cancellationPipeName + seq, '');
return true;
} catch (e) {
// noop
}
}
if (this.trace !== Trace.Off) {
this.logTrace(`TypeScript Service: tried to cancel request with sequence number ${seq}. But request got already delivered.`);
}

View File

@@ -17,7 +17,7 @@ export interface IForkOptions {
execArgv?: string[];
}
function makeRandomHexString(length: number): string {
export function makeRandomHexString(length: number): string {
let chars = ['0', '1', '2', '3', '4', '5', '6', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
let result = '';
for (let i = 0; i < length; i++) {
@@ -28,15 +28,20 @@ function makeRandomHexString(length: number): string {
}
function generatePipeName(): string {
var randomName = 'vscode-' + makeRandomHexString(40);
return getPipeName(makeRandomHexString(40));
}
export function getPipeName(name: string): string {
const fullName = 'vscode-' + name;
if (process.platform === 'win32') {
return '\\\\.\\pipe\\' + randomName + '-sock';
return '\\\\.\\pipe\\' + fullName + '-sock';
}
// Mac/Unix: use socket file
return path.join(os.tmpdir(), randomName + '.sock');
return path.join(os.tmpdir(), fullName + '.sock');
}
function generatePatchedEnv(env: any, stdInPipeName: string, stdOutPipeName: string, stdErrPipeName: string): any {
// Set the two unique pipe names and the electron flag as process env