Delegate js/ts code lenses back to vs code

Fixes #43574
This commit is contained in:
Matt Bierner
2018-09-07 16:45:42 -07:00
parent e82498a544
commit dc47417f54
2 changed files with 15 additions and 37 deletions

View File

@@ -10,7 +10,6 @@ import * as PConst from '../protocol.const';
import { ITypeScriptServiceClient } from '../typescriptService';
import API from '../utils/api';
import { ConfigurationDependentRegistration, VersionDependentRegistration } from '../utils/dependentRegistration';
import * as typeConverters from '../utils/typeConverters';
import { CachedNavTreeResponse, ReferencesCodeLens, TypeScriptBaseCodeLensProvider } from './baseCodeLensProvider';
const localize = nls.loadMessageBundle();
@@ -18,28 +17,12 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip
public async resolveCodeLens(
inputCodeLens: vscode.CodeLens,
token: vscode.CancellationToken,
_token: vscode.CancellationToken,
): Promise<vscode.CodeLens> {
const codeLens = inputCodeLens as ReferencesCodeLens;
const args = typeConverters.Position.toFileLocationRequestArgs(codeLens.file, codeLens.range.start);
try {
const { body } = await this.client.execute('implementation', args, token);
if (body) {
const locations = body
.map(reference =>
// Only take first line on implementation: https://github.com/Microsoft/vscode/issues/23924
new vscode.Location(this.client.toResource(reference.file),
reference.start.line === reference.end.line
? typeConverters.Range.fromTextSpan(reference)
: new vscode.Range(
typeConverters.Position.fromLocation(reference.start),
new vscode.Position(reference.start.line, 0))))
// Exclude original from implementations
.filter(location =>
!(location.uri.toString() === codeLens.document.toString() &&
location.range.start.line === codeLens.range.start.line &&
location.range.start.character === codeLens.range.start.character));
const locations: vscode.Location[] | undefined = await vscode.commands.executeCommand<vscode.Location[]>('vscode.executeImplementationProvider', codeLens.document, codeLens.range.start);
if (locations) {
codeLens.command = this.getCommand(locations, codeLens);
return codeLens;
}

View File

@@ -10,38 +10,33 @@ import * as PConst from '../protocol.const';
import { ITypeScriptServiceClient } from '../typescriptService';
import API from '../utils/api';
import { ConfigurationDependentRegistration, VersionDependentRegistration } from '../utils/dependentRegistration';
import * as typeConverters from '../utils/typeConverters';
import { CachedNavTreeResponse, ReferencesCodeLens, TypeScriptBaseCodeLensProvider } from './baseCodeLensProvider';
const localize = nls.loadMessageBundle();
class TypeScriptReferencesCodeLensProvider extends TypeScriptBaseCodeLensProvider {
public resolveCodeLens(inputCodeLens: vscode.CodeLens, token: vscode.CancellationToken): Promise<vscode.CodeLens> {
public resolveCodeLens(inputCodeLens: vscode.CodeLens, _token: vscode.CancellationToken): Thenable<vscode.CodeLens> {
const codeLens = inputCodeLens as ReferencesCodeLens;
const args = typeConverters.Position.toFileLocationRequestArgs(codeLens.file, codeLens.range.start);
return this.client.execute('references', args, token).then(response => {
if (!response.body) {
return vscode.commands.executeCommand<vscode.Location[]>('vscode.executeReferenceProvider', codeLens.document, codeLens.range.start).then((locations: vscode.Location[] | undefined) => {
if (!locations) {
throw codeLens;
}
const locations = response.body.refs
.map(reference =>
typeConverters.Location.fromTextSpan(this.client.toResource(reference.file), reference))
.filter(location =>
// Exclude original definition from references
!(location.uri.toString() === codeLens.document.toString() &&
location.range.start.isEqual(codeLens.range.start)));
const referenceLocations = locations.filter(location =>
// Exclude original definition from references
!(location.uri.toString() === codeLens.document.toString() &&
location.range.start.isEqual(codeLens.range.start)));
codeLens.command = {
title: locations.length === 1
title: referenceLocations.length === 1
? localize('oneReferenceLabel', '1 reference')
: localize('manyReferenceLabel', '{0} references', locations.length),
command: locations.length ? 'editor.action.showReferences' : '',
arguments: [codeLens.document, codeLens.range.start, locations]
: localize('manyReferenceLabel', '{0} references', referenceLocations.length),
command: referenceLocations.length ? 'editor.action.showReferences' : '',
arguments: [codeLens.document, codeLens.range.start, referenceLocations]
};
return codeLens;
}).catch(() => {
}).then(undefined, () => {
codeLens.command = {
title: localize('referenceErrorLabel', 'Could not determine references'),
command: ''