提交 6d075f77 编写于 作者: M Matt Bierner

Cleaning up implementations code lens

- Make async
- extract some methods
上级 06ea138f
......@@ -16,13 +16,15 @@ const localize = nls.loadMessageBundle();
export default class TypeScriptImplementationsCodeLensProvider extends TypeScriptBaseCodeLensProvider {
public resolveCodeLens(inputCodeLens: vscode.CodeLens, token: vscode.CancellationToken): Promise<vscode.CodeLens> {
public async resolveCodeLens(
inputCodeLens: vscode.CodeLens,
token: vscode.CancellationToken,
): Promise<vscode.CodeLens> {
const codeLens = inputCodeLens as ReferencesCodeLens;
const args = typeConverters.Position.toFileLocationRequestArgs(codeLens.file, codeLens.range.start);
return this.client.execute('implementation', args, token).then(response => {
if (!response || !response.body) {
throw codeLens;
}
try {
const response = await this.client.execute('implementation', args, token);
if (response && response.body) {
const locations = response.body
.map(reference =>
......@@ -39,21 +41,32 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip
location.range.start.line === codeLens.range.start.line &&
location.range.start.character === codeLens.range.start.character));
codeLens.command = {
title: locations.length === 1
? localize('oneImplementationLabel', '1 implementation')
: localize('manyImplementationLabel', '{0} implementations', locations.length),
command: locations.length ? 'editor.action.showReferences' : '',
arguments: [codeLens.document, codeLens.range.start, locations]
};
codeLens.command = this.getCommand(locations, codeLens);
return codeLens;
}).catch(() => {
}
} catch {
// noop
}
codeLens.command = {
title: localize('implementationsErrorLabel', 'Could not determine implementations'),
command: ''
};
return codeLens;
});
}
private getCommand(locations: vscode.Location[], codeLens: ReferencesCodeLens): vscode.Command | undefined {
return {
title: this.getTitle(locations),
command: locations.length ? 'editor.action.showReferences' : '',
arguments: [codeLens.document, codeLens.range.start, locations]
};
}
private getTitle(locations: vscode.Location[]): string {
return locations.length === 1
? localize('oneImplementationLabel', '1 implementation')
: localize('manyImplementationLabel', '{0} implementations', locations.length);
}
protected extractSymbol(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册