提交 8c468dfd 编写于 作者: M Matt Bierner 提交者: GitHub

Prototype Support for TSServer Request Cancelation (#22437)

上级 e1acce13
......@@ -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.`);
}
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册