From dc47417f54ffb411d88f12f548dfc9ef8efb30cc Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Fri, 7 Sep 2018 16:45:42 -0700 Subject: [PATCH] Delegate js/ts code lenses back to vs code Fixes #43574 --- .../src/features/implementationsCodeLens.ts | 23 ++------------- .../src/features/referencesCodeLens.ts | 29 ++++++++----------- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/extensions/typescript-language-features/src/features/implementationsCodeLens.ts b/extensions/typescript-language-features/src/features/implementationsCodeLens.ts index 5b4ef7b0eb0..32559e09e21 100644 --- a/extensions/typescript-language-features/src/features/implementationsCodeLens.ts +++ b/extensions/typescript-language-features/src/features/implementationsCodeLens.ts @@ -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 { 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.executeImplementationProvider', codeLens.document, codeLens.range.start); + if (locations) { codeLens.command = this.getCommand(locations, codeLens); return codeLens; } diff --git a/extensions/typescript-language-features/src/features/referencesCodeLens.ts b/extensions/typescript-language-features/src/features/referencesCodeLens.ts index e243e0d0e37..ea227ac99c1 100644 --- a/extensions/typescript-language-features/src/features/referencesCodeLens.ts +++ b/extensions/typescript-language-features/src/features/referencesCodeLens.ts @@ -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 { + public resolveCodeLens(inputCodeLens: vscode.CodeLens, _token: vscode.CancellationToken): Thenable { 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.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: ''