mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 11:08:51 +01:00
Finalize definition link (#54424)
Finalize the definition link api - Gives fields more explicit names (target and origin) - Moves api to vscode.d.ts - Makes other definition providers (such as type definition provider and implementation provider) also return definition links Fixes #54101
This commit is contained in:
@@ -812,8 +812,8 @@ export interface ExtHostLanguageFeaturesShape {
|
||||
$provideCodeLenses(handle: number, resource: UriComponents): TPromise<modes.ICodeLensSymbol[]>;
|
||||
$resolveCodeLens(handle: number, resource: UriComponents, symbol: modes.ICodeLensSymbol): TPromise<modes.ICodeLensSymbol>;
|
||||
$provideDefinition(handle: number, resource: UriComponents, position: IPosition): TPromise<DefinitionLinkDto[]>;
|
||||
$provideImplementation(handle: number, resource: UriComponents, position: IPosition): TPromise<LocationDto | LocationDto[]>;
|
||||
$provideTypeDefinition(handle: number, resource: UriComponents, position: IPosition): TPromise<LocationDto | LocationDto[]>;
|
||||
$provideImplementation(handle: number, resource: UriComponents, position: IPosition): TPromise<DefinitionLinkDto[]>;
|
||||
$provideTypeDefinition(handle: number, resource: UriComponents, position: IPosition): TPromise<DefinitionLinkDto[]>;
|
||||
$provideHover(handle: number, resource: UriComponents, position: IPosition): TPromise<modes.Hover>;
|
||||
$provideDocumentHighlights(handle: number, resource: UriComponents, position: IPosition): TPromise<modes.DocumentHighlight[]>;
|
||||
$provideReferences(handle: number, resource: UriComponents, position: IPosition, context: modes.ReferenceContext): TPromise<LocationDto[]>;
|
||||
|
||||
@@ -143,6 +143,15 @@ class CodeLensAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
function convertToDefinitionLinks(value: vscode.Definition): modes.DefinitionLink[] {
|
||||
if (Array.isArray(value)) {
|
||||
return (value as (vscode.DefinitionLink | vscode.Location)[]).map(typeConvert.DefinitionLink.from);
|
||||
} else if (value) {
|
||||
return [typeConvert.DefinitionLink.from(value)];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
class DefinitionAdapter {
|
||||
|
||||
constructor(
|
||||
@@ -153,29 +162,7 @@ class DefinitionAdapter {
|
||||
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.provideDefinition2 ? this._provider.provideDefinition2(doc, pos, token) : this._provider.provideDefinition(doc, pos, token)).then((value): modes.DefinitionLink[] => {
|
||||
if (Array.isArray(value)) {
|
||||
return (value as (vscode.DefinitionLink | vscode.Location)[]).map(x => DefinitionAdapter.convertDefinitionLink(x));
|
||||
} else if (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,
|
||||
};
|
||||
return asWinJsPromise(token => this._provider.provideDefinition(doc, pos, token)).then(convertToDefinitionLinks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,17 +173,10 @@ class ImplementationAdapter {
|
||||
private readonly _provider: vscode.ImplementationProvider
|
||||
) { }
|
||||
|
||||
provideImplementation(resource: URI, position: IPosition): TPromise<modes.Definition> {
|
||||
provideImplementation(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.provideImplementation(doc, pos, token)).then(value => {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(typeConvert.location.from);
|
||||
} else if (value) {
|
||||
return typeConvert.location.from(value);
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
return asWinJsPromise(token => this._provider.provideImplementation(doc, pos, token)).then(convertToDefinitionLinks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,17 +187,10 @@ class TypeDefinitionAdapter {
|
||||
private readonly _provider: vscode.TypeDefinitionProvider
|
||||
) { }
|
||||
|
||||
provideTypeDefinition(resource: URI, position: IPosition): TPromise<modes.Definition> {
|
||||
provideTypeDefinition(resource: URI, position: IPosition): TPromise<modes.DefinitionLink[]> {
|
||||
const doc = this._documents.getDocumentData(resource).document;
|
||||
const pos = typeConvert.Position.to(position);
|
||||
return asWinJsPromise(token => this._provider.provideTypeDefinition(doc, pos, token)).then(value => {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map(typeConvert.location.from);
|
||||
} else if (value) {
|
||||
return typeConvert.location.from(value);
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
return asWinJsPromise(token => this._provider.provideTypeDefinition(doc, pos, token)).then(convertToDefinitionLinks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -999,7 +972,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
|
||||
$provideImplementation(handle: number, resource: UriComponents, position: IPosition): TPromise<modes.Definition> {
|
||||
$provideImplementation(handle: number, resource: UriComponents, position: IPosition): TPromise<modes.DefinitionLink[]> {
|
||||
return this._withAdapter(handle, ImplementationAdapter, adapter => adapter.provideImplementation(URI.revive(resource), position));
|
||||
}
|
||||
|
||||
@@ -1009,7 +982,7 @@ export class ExtHostLanguageFeatures implements ExtHostLanguageFeaturesShape {
|
||||
return this._createDisposable(handle);
|
||||
}
|
||||
|
||||
$provideTypeDefinition(handle: number, resource: UriComponents, position: IPosition): TPromise<modes.Definition> {
|
||||
$provideTypeDefinition(handle: number, resource: UriComponents, position: IPosition): TPromise<modes.DefinitionLink[]> {
|
||||
return this._withAdapter(handle, TypeDefinitionAdapter, adapter => adapter.provideTypeDefinition(URI.revive(resource), position));
|
||||
}
|
||||
|
||||
|
||||
@@ -413,6 +413,23 @@ export const location = {
|
||||
}
|
||||
};
|
||||
|
||||
export namespace DefinitionLink {
|
||||
export function from(value: vscode.Location | vscode.DefinitionLink): modes.DefinitionLink {
|
||||
const definitionLink = <vscode.DefinitionLink>value;
|
||||
const location = <vscode.Location>value;
|
||||
return {
|
||||
origin: definitionLink.originSelectionRange
|
||||
? Range.from(definitionLink.originSelectionRange)
|
||||
: undefined,
|
||||
uri: definitionLink.targetUri ? definitionLink.targetUri : location.uri,
|
||||
range: Range.from(definitionLink.targetRange ? definitionLink.targetRange : location.range),
|
||||
selectionRange: definitionLink.targetSelectionRange
|
||||
? Range.from(definitionLink.targetSelectionRange)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export namespace Hover {
|
||||
export function from(hover: vscode.Hover): modes.Hover {
|
||||
return <modes.Hover>{
|
||||
|
||||
Reference in New Issue
Block a user