Clean up definition provider

This commit is contained in:
Matt Bierner
2017-10-26 14:55:10 -07:00
parent 1ec4ea3ea8
commit ade3609d02
4 changed files with 8 additions and 22 deletions

View File

@@ -5,16 +5,11 @@
import { DefinitionProvider, TextDocument, Position, CancellationToken, Definition } from 'vscode';
import { ITypescriptServiceClient } from '../typescriptService';
import DefinitionProviderBase from './definitionProviderBase';
export default class TypeScriptDefinitionProvider extends DefinitionProviderBase implements DefinitionProvider {
constructor(client: ITypescriptServiceClient) {
super(client);
}
public provideDefinition(document: TextDocument, position: Position, token: CancellationToken | boolean): Promise<Definition | null> {
public provideDefinition(document: TextDocument, position: Position, token: CancellationToken | boolean): Promise<Definition | undefined> {
return this.getSymbolLocations('definition', document, position, token);
}
}

View File

@@ -18,10 +18,10 @@ export default class TypeScriptDefinitionProviderBase {
document: TextDocument,
position: Position,
token: CancellationToken | boolean
): Promise<Location[] | null> {
): Promise<Location[] | undefined> {
const filepath = this.client.normalizePath(document.uri);
if (!filepath) {
return null;
return undefined;
}
const args = vsPositionToTsFileLocation(filepath, position);
@@ -33,9 +33,9 @@ export default class TypeScriptDefinitionProviderBase {
}
return locations.map(location => {
const resource = this.client.asUrl(location.file);
return !resource
? null
: new Location(resource, tsTextSpanToVsRange(location));
return resource
? new Location(resource, tsTextSpanToVsRange(location))
: undefined;
}).filter(x => x) as Location[];
} catch {
return [];

View File

@@ -5,16 +5,11 @@
import { ImplementationProvider, TextDocument, Position, CancellationToken, Definition } from 'vscode';
import { ITypescriptServiceClient } from '../typescriptService';
import DefinitionProviderBase from './definitionProviderBase';
export default class TypeScriptImplementationProvider extends DefinitionProviderBase implements ImplementationProvider {
constructor(client: ITypescriptServiceClient) {
super(client);
}
public provideImplementation(document: TextDocument, position: Position, token: CancellationToken | boolean): Promise<Definition | null> {
public provideImplementation(document: TextDocument, position: Position, token: CancellationToken | boolean): Promise<Definition | undefined> {
return this.getSymbolLocations('implementation', document, position, token);
}
}

View File

@@ -5,15 +5,11 @@
import { TypeDefinitionProvider, TextDocument, Position, CancellationToken, Definition } from 'vscode';
import { ITypescriptServiceClient } from '../typescriptService';
import DefinitionProviderBase from './definitionProviderBase';
export default class TypeScriptTypeDefinitionProvider extends DefinitionProviderBase implements TypeDefinitionProvider {
constructor(client: ITypescriptServiceClient) {
super(client);
}
public provideTypeDefinition(document: TextDocument, position: Position, token: CancellationToken | boolean): Promise<Definition | null> {
public provideTypeDefinition(document: TextDocument, position: Position, token: CancellationToken | boolean): Promise<Definition | undefined> {
return this.getSymbolLocations('typeDefinition', document, position, token);
}
}