提交 9d225146 编写于 作者: M Matt Bierner

Do not display errors in editor for cancelled js/ts code lenses

Fixes #63884

Resolving a code lenses may be cancelled if the document changes. This is normal and should not be displayed as an error in the editor
上级 42145f1f
......@@ -4,11 +4,14 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import * as Proto from '../protocol';
import { ITypeScriptServiceClient, ServerResponse } from '../typescriptService';
import { escapeRegExp } from '../utils/regexp';
import * as typeConverters from '../utils/typeConverters';
const localize = nls.loadMessageBundle();
export class ReferencesCodeLens extends vscode.CodeLens {
constructor(
public document: vscode.Uri,
......@@ -51,6 +54,18 @@ export class CachedResponse<T extends Proto.Response> {
}
export abstract class TypeScriptBaseCodeLensProvider implements vscode.CodeLensProvider {
public static readonly cancelledCommand: vscode.Command = {
// Cancellation is not an error. Just show nothing until we can properly re-compute the code lens
title: '',
command: ''
};
public static readonly errorCommand: vscode.Command = {
title: localize('referenceErrorLabel', 'Could not determine references'),
command: ''
};
private onDidChangeCodeLensesEmitter = new vscode.EventEmitter<void>();
public constructor(
......
......@@ -26,10 +26,9 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip
const args = typeConverters.Position.toFileLocationRequestArgs(codeLens.file, codeLens.range.start);
const response = await this.client.execute('implementation', args, token, /* lowPriority */ true);
if (response.type !== 'response' || !response.body) {
codeLens.command = {
title: localize('implementationsErrorLabel', 'Could not determine implementations'),
command: ''
};
codeLens.command = response.type === 'cancelled'
? TypeScriptBaseCodeLensProvider.cancelledCommand
: TypeScriptBaseCodeLensProvider.errorCommand;
return codeLens;
}
......
......@@ -22,10 +22,9 @@ class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvide
const args = typeConverters.Position.toFileLocationRequestArgs(codeLens.file, codeLens.range.start);
const response = await this.client.execute('references', args, token, /* lowPriority */ true);
if (response.type !== 'response' || !response.body) {
codeLens.command = {
title: localize('referenceErrorLabel', 'Could not determine references'),
command: ''
};
codeLens.command = response.type === 'cancelled'
? TypeScriptBaseCodeLensProvider.cancelledCommand
: TypeScriptBaseCodeLensProvider.errorCommand;
return codeLens;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册