Skip to content

Commit

Permalink
Prototype Support for TSServer Request Cancelation
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Mar 20, 2017
1 parent 1b90e9d commit ad1f465
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
18 changes: 18 additions & 0 deletions extensions/typescript/src/typescriptServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.`);
}
Expand Down
13 changes: 9 additions & 4 deletions extensions/typescript/src/utils/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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

Expand Down

0 comments on commit ad1f465

Please sign in to comment.