Skip to content

Conversation

mjbvz
Copy link
Collaborator

@mjbvz mjbvz commented Apr 16, 2018

Problem
#10037 again.

Proposal
Add a new SymbolDefinition type to the VSCode API. This bundles up set of definitions and the span of the defining symbol

This PR supersedes #45249 and returns to the approach from #40045

@mjbvz mjbvz self-assigned this Apr 16, 2018
@mjbvz mjbvz requested a review from jrieken April 16, 2018 20:27
**Problem**
See microsoft#10037

**Proposal**
Add a new `SymbolDefinition` class to the VSCode API. This bundles up a location and the span of the defining symbol
@mjbvz mjbvz force-pushed the symbol-definition-api branch from b15156a to bfa410f Compare April 16, 2018 20:29
// get results
const promises = provider.map((provider, idx): TPromise<Location | Location[]> => {
return asWinJsPromise((token) => {
return provide(provider, model, position, token);
}).then(undefined, err => {
}).then(result => {
if (result && (result as any).definitions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use any, use TypeScript

//#region Defintion symbol range: mjbvz

export interface SymbolDefinition {
definingSpan?: Location;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs better name...

export interface SymbolDefinition {
definingSpan?: Location;

definitions: Location[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs room for a target range, e.g. the full range of the target vs the navigate-to-target. That's needed for the source preview hover (can be delayed but must happen before making this 'real' api)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative could also be to let SymbolDefinition talk about just one link and use it as array. So instead of definitions: Location[]; return SymbolDefinition[]. I assume that would help with additional metadata for a single link, e.g. the actual symbol ranges etc

@@ -520,6 +520,10 @@ export interface Location {
*/
range: IRange;
}
export interface SymbolDefinition {
definingSpan?: Location;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this optional is like return Definitions... I'd be in favour of strict, return either a 'normal' definition or a rich definition

data.definingSpan = this._reviveLocationDto(data.definingSpan);
}

data.definitions = data.definitions.map(x => this._reviveLocationDto(x));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to map or assign because revive changes objects in-place (for the sake of avoiding garbage). Same on line 80

return wireCancellationToken(token, this._proxy.$provideDefinition(handle, model.uri, position)).then(MainThreadLanguageFeatures._reviveLocationDto);
provideDefinition: (model, position, token): Thenable<modes.Definition | modes.SymbolDefinition> => {
return wireCancellationToken(token, this._proxy.$provideDefinition(handle, model.uri, position)).then(x => {
if ((x as any).definitions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use TypeScript


if (Array.isArray(value)) {
return value.map(TypeConverters.location.from);
} else if ((value as any).definitions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use TypeScript

provide: (provider: T, model: ITextModel, position: Position, token: CancellationToken) => Location | Location[] | Thenable<Location | Location[]>
): TPromise<Location[]> {
provide: (provider: T, model: ITextModel, position: Position, token: CancellationToken) => Location | Location[] | SymbolDefinition | Thenable<Location | Location[] | SymbolDefinition>
): TPromise<SymbolDefinition> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes how the corresponding API-command works. We should update the doc around that and inform live share folks


//#region Defintion symbol range: mjbvz

export interface SymbolDefinition {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a class

@mjbvz mjbvz mentioned this pull request Jun 18, 2018
@mjbvz
Copy link
Collaborator Author

mjbvz commented Jun 18, 2018

Replaced by #52230

@mjbvz mjbvz closed this Jun 18, 2018
mjbvz added a commit that referenced this pull request Jun 19, 2018
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
mjbvz added a commit to mjbvz/vscode that referenced this pull request Jun 20, 2018
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 microsoft#48001
mjbvz added a commit that referenced this pull request Jun 20, 2018
* 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
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants