Try to interupt getErr request for user opetions

This commit is contained in:
Matt Bierner 2018-07-26 18:34:09 -07:00
parent 1cbd30833b
commit d96cf918b7
5 changed files with 28 additions and 5 deletions

View file

@ -256,6 +256,7 @@ export default class BufferSyncSupport extends Disposable {
if (!syncedBuffer) {
return;
}
this.pendingDiagnostics.delete(resource);
this.syncedBuffers.delete(resource);
syncedBuffer.close();
if (!fs.existsSync(resource.fsPath)) {
@ -264,6 +265,19 @@ export default class BufferSyncSupport extends Disposable {
}
}
public interuptGetErr<R>(f: () => R): R {
console.log('try inter');
if (!this.pendingGetErr) {
return f();
}
this.pendingGetErr.cancel();
this.pendingGetErr = undefined;
const result = f();
this.triggerDiagnostics();
return result;
}
private onDidCloseTextDocument(document: vscode.TextDocument): void {
this.closeResource(document.uri);
}

View file

@ -304,7 +304,7 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider
return null;
}
await this.fileConfigurationManager.ensureConfigurationForDocument(document, token);
await this.client.interuptGetErr(() => this.fileConfigurationManager.ensureConfigurationForDocument(document, token));
const args: Proto.CompletionsRequestArgs = {
...typeConverters.Position.toFileLocationRequestArgs(file, position),
@ -313,19 +313,18 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider
triggerCharacter: context.triggerCharacter as Proto.CompletionsTriggerCharacter
};
let enableCommitCharacters = true;
let msg: ReadonlyArray<Proto.CompletionEntry> | undefined = undefined;
try {
if (this.client.apiVersion.gte(API.v300)) {
const { body } = await this.client.execute('completionInfo', args, token);
const { body } = await this.client.interuptGetErr(() => this.client.execute('completionInfo', args, token));
if (!body) {
return null;
}
enableCommitCharacters = !body.isNewIdentifierLocation;
msg = body.entries;
} else {
const { body } = await this.client.execute('completions', args, token);
const { body } = await this.client.interuptGetErr(() => this.client.execute('completions', args, token));
if (!body) {
return null;
}

View file

@ -25,9 +25,10 @@ class TypeScriptHoverProvider implements vscode.HoverProvider {
if (!filepath) {
return undefined;
}
const args = typeConverters.Position.toFileLocationRequestArgs(filepath, position);
try {
const { body } = await this.client.execute('quickinfo', args, token);
const { body } = await this.client.interuptGetErr(() => this.client.execute('quickinfo', args, token));
if (body) {
return new vscode.Hover(
TypeScriptHoverProvider.getContents(body),

View file

@ -91,4 +91,9 @@ export interface ITypeScriptServiceClient {
executeWithoutWaitingForResponse(command: 'reloadProjects', args: null): void;
executeAsync(command: 'geterr', args: Proto.GeterrRequestArgs, token: vscode.CancellationToken): Promise<any>;
/**
* Cancel on going geterr requests and re-queue them after `f` has been evaluated.
*/
interuptGetErr<R>(f: () => R): R;
}

View file

@ -738,6 +738,10 @@ export default class TypeScriptServiceClient extends Disposable implements IType
return result;
}
public interuptGetErr<R>(f: () => R): R {
return this.bufferSyncSupport.interuptGetErr(f);
}
/**
* Given a `errorText` from a tsserver request indicating failure in handling a request,
* prepares a payload for telemetry-logging.