mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
Clean up TypeScriptReferenceSupport
- Use await - Use for of
This commit is contained in:
@@ -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<CodeLens[]> {
|
||||
public async provideCodeLenses(document: TextDocument, token: CancellationToken): Promise<CodeLens[]> {
|
||||
if (!this.client.apiVersion.has220Features()) {
|
||||
return [];
|
||||
}
|
||||
return super.provideCodeLenses(document, token);
|
||||
}
|
||||
|
||||
resolveCodeLens(inputCodeLens: CodeLens, token: CancellationToken): Promise<CodeLens> {
|
||||
public resolveCodeLens(inputCodeLens: CodeLens, token: CancellationToken): Promise<CodeLens> {
|
||||
const codeLens = inputCodeLens as ReferencesCodeLens;
|
||||
const args = vsPositionToTsFileLocation(codeLens.file, codeLens.range.start);
|
||||
return this.client.execute('implementation', args, token).then(response => {
|
||||
|
||||
@@ -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<Location[]> {
|
||||
public async provideReferences(
|
||||
document: TextDocument,
|
||||
position: Position,
|
||||
options: { includeDeclaration: boolean },
|
||||
token: CancellationToken
|
||||
): Promise<Location[]> {
|
||||
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 [];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<CodeLens[]> {
|
||||
async provideCodeLenses(document: TextDocument, token: CancellationToken): Promise<CodeLens[]> {
|
||||
if (!this.client.apiVersion.has206Features()) {
|
||||
return [];
|
||||
}
|
||||
return super.provideCodeLenses(document, token);
|
||||
}
|
||||
|
||||
resolveCodeLens(inputCodeLens: CodeLens, token: CancellationToken): Promise<CodeLens> {
|
||||
public resolveCodeLens(inputCodeLens: CodeLens, token: CancellationToken): Promise<CodeLens> {
|
||||
const codeLens = inputCodeLens as ReferencesCodeLens;
|
||||
const args = vsPositionToTsFileLocation(codeLens.file, codeLens.range.start);
|
||||
return this.client.execute('references', args, token).then(response => {
|
||||
|
||||
Reference in New Issue
Block a user