Definition link API (#52230)

* Definition link

Add a new `DefinitionLink` type. This type allows definition providers to return additional metadata about a definition, such as the defining span.

Hook up this new provider for typescript

This PR replaces #48001

* Correctly mark field optional

* Small code fixes

- Use lift
- Remove unused param

* Adding documentation
This commit is contained in:
Matt Bierner
2018-06-20 11:52:47 -07:00
committed by GitHub
parent 04c1ad98b3
commit 0532c31e4c
11 changed files with 169 additions and 22 deletions

View File

@@ -150,18 +150,33 @@ class DefinitionAdapter {
private readonly _provider: vscode.DefinitionProvider
) { }
provideDefinition(resource: URI, position: IPosition): TPromise<modes.Definition> {
provideDefinition(resource: URI, position: IPosition): TPromise<modes.DefinitionLink[]> {
let doc = this._documents.getDocumentData(resource).document;
let pos = typeConvert.Position.to(position);
return asWinJsPromise(token => this._provider.provideDefinition(doc, pos, token)).then(value => {
return asWinJsPromise(token => this._provider.provideDefinition2 ? this._provider.provideDefinition2(doc, pos, token) : this._provider.provideDefinition(doc, pos, token)).then((value): modes.DefinitionLink[] => {
if (Array.isArray(value)) {
return value.map(typeConvert.location.from);
return (value as (vscode.DefinitionLink | vscode.Location)[]).map(x => DefinitionAdapter.convertDefinitionLink(x));
} else if (value) {
return typeConvert.location.from(value);
return [DefinitionAdapter.convertDefinitionLink(value)];
}
return undefined;
});
}
private static convertDefinitionLink(value: vscode.Location | vscode.DefinitionLink): modes.DefinitionLink {
const definitionLink = <vscode.DefinitionLink>value;
return {
origin: definitionLink.origin
? typeConvert.Range.from(definitionLink.origin)
: undefined,
uri: value.uri,
range: typeConvert.Range.from(value.range),
selectionRange: definitionLink.selectionRange
? typeConvert.Range.from(definitionLink.selectionRange)
: undefined,
};
}
}
class ImplementationAdapter {
@@ -974,7 +989,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
return this._createDisposable(handle);
}
$provideDefinition(handle: number, resource: UriComponents, position: IPosition): TPromise<modes.Definition> {
$provideDefinition(handle: number, resource: UriComponents, position: IPosition): TPromise<modes.DefinitionLink[]> {
return this._withAdapter(handle, DefinitionAdapter, adapter => adapter.provideDefinition(URI.revive(resource), position));
}