diff --git a/extensions/typescript/src/features/implementationsCodeLensProvider.ts b/extensions/typescript/src/features/implementationsCodeLensProvider.ts index 7377913a184..b9d4c74f422 100644 --- a/extensions/typescript/src/features/implementationsCodeLensProvider.ts +++ b/extensions/typescript/src/features/implementationsCodeLensProvider.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { CodeLens, CancellationToken, TextDocument, Range, Location, ProviderResult, workspace } from 'vscode'; +import { CodeLens, CancellationToken, TextDocument, Range, Location, workspace } from 'vscode'; import * as Proto from '../protocol'; import * as PConst from '../protocol.const'; @@ -27,14 +27,14 @@ export default class TypeScriptImplementationsCodeLensProvider extends TypeScrip this.setEnabled(config.get('implementationsCodeLens.enabled', false)); } - provideCodeLenses(document: TextDocument, token: CancellationToken): ProviderResult { + public async provideCodeLenses(document: TextDocument, token: CancellationToken): Promise { if (!this.client.apiVersion.has220Features()) { return []; } return super.provideCodeLenses(document, token); } - resolveCodeLens(inputCodeLens: CodeLens, token: CancellationToken): Promise { + public resolveCodeLens(inputCodeLens: CodeLens, token: CancellationToken): Promise { const codeLens = inputCodeLens as ReferencesCodeLens; const args = vsPositionToTsFileLocation(codeLens.file, codeLens.range.start); return this.client.execute('implementation', args, token).then(response => { diff --git a/extensions/typescript/src/features/referenceProvider.ts b/extensions/typescript/src/features/referenceProvider.ts index f2413816fed..a5892d0accd 100644 --- a/extensions/typescript/src/features/referenceProvider.ts +++ b/extensions/typescript/src/features/referenceProvider.ts @@ -12,22 +12,27 @@ export default class TypeScriptReferenceSupport implements ReferenceProvider { public constructor( private client: ITypeScriptServiceClient) { } - public async provideReferences(document: TextDocument, position: Position, options: { includeDeclaration: boolean }, token: CancellationToken): Promise { + public async provideReferences( + document: TextDocument, + position: Position, + options: { includeDeclaration: boolean }, + token: CancellationToken + ): Promise { const filepath = this.client.normalizePath(document.uri); if (!filepath) { return []; } + const args = vsPositionToTsFileLocation(filepath, position); - const apiVersion = this.client.apiVersion; - return this.client.execute('references', args, token).then((msg) => { - const result: Location[] = []; + try { + const msg = await this.client.execute('references', args, token); if (!msg.body) { - return result; + return []; } - const refs = msg.body.refs; - for (let i = 0; i < refs.length; i++) { - const ref = refs[i]; - if (!options.includeDeclaration && apiVersion.has203Features() && ref.isDefinition) { + const result: Location[] = []; + const has203Features = this.client.apiVersion.has203Features(); + for (const ref of msg.body.refs) { + if (!options.includeDeclaration && has203Features && ref.isDefinition) { continue; } const url = this.client.asUrl(ref.file); @@ -35,8 +40,8 @@ export default class TypeScriptReferenceSupport implements ReferenceProvider { result.push(location); } return result; - }, () => { + } catch { return []; - }); + } } } \ No newline at end of file diff --git a/extensions/typescript/src/features/referencesCodeLensProvider.ts b/extensions/typescript/src/features/referencesCodeLensProvider.ts index 016913a3217..d643c9c34b8 100644 --- a/extensions/typescript/src/features/referencesCodeLensProvider.ts +++ b/extensions/typescript/src/features/referencesCodeLensProvider.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { CodeLens, CancellationToken, TextDocument, Range, Location, ProviderResult, workspace } from 'vscode'; +import { CodeLens, CancellationToken, TextDocument, Range, Location, workspace } from 'vscode'; import * as Proto from '../protocol'; import * as PConst from '../protocol.const'; @@ -27,14 +27,14 @@ export default class TypeScriptReferencesCodeLensProvider extends TypeScriptBase this.setEnabled(config.get('referencesCodeLens.enabled', false)); } - provideCodeLenses(document: TextDocument, token: CancellationToken): ProviderResult { + async provideCodeLenses(document: TextDocument, token: CancellationToken): Promise { if (!this.client.apiVersion.has206Features()) { return []; } return super.provideCodeLenses(document, token); } - resolveCodeLens(inputCodeLens: CodeLens, token: CancellationToken): Promise { + public resolveCodeLens(inputCodeLens: CodeLens, token: CancellationToken): Promise { const codeLens = inputCodeLens as ReferencesCodeLens; const args = vsPositionToTsFileLocation(codeLens.file, codeLens.range.start); return this.client.execute('references', args, token).then(response => {