Skip to content

Commit

Permalink
renames, #58649
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jan 11, 2019
1 parent ae5078f commit 14ce518
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 78 deletions.
38 changes: 25 additions & 13 deletions src/vs/editor/common/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,20 +715,32 @@ export interface Location {
*/
range: IRange;
}
/**
* The definition of a symbol represented as one or many [locations](#Location).
* For most programming languages there is only one location at which a symbol is
* defined.
*/
export type Definition = Location | Location[];

export interface DefinitionLink {
origin?: IRange;
export interface LocationLink {
/**
* A range to select where this link originates from.
*/
originSelectionRange?: IRange;

/**
* The target uri this link points to.
*/
uri: URI;

/**
* The full range this link points to.
*/
range: IRange;
selectionRange?: IRange;

/**
* A range to select this link points to. Must be contained
* in `LocationLink.range`.
*/
targetSelectionRange?: IRange;
}

export type Definition = Location | Location[] | LocationLink[];

/**
* The definition provider interface defines the contract between extensions and
* the [go to definition](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-definition)
Expand All @@ -738,7 +750,7 @@ export interface DefinitionProvider {
/**
* Provide the definition of the symbol at the given position and document.
*/
provideDefinition(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>;
provideDefinition(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;

This comment has been minimized.

Copy link
@KamasamaK

KamasamaK Jan 11, 2019

Is this necessary since the type definition of Definition includes LocationLink[]?

}

/**
Expand All @@ -750,7 +762,7 @@ export interface DeclarationProvider {
/**
* Provide the declaration of the symbol at the given position and document.
*/
provideDeclaration(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>;
provideDeclaration(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
}

/**
Expand All @@ -761,7 +773,7 @@ export interface ImplementationProvider {
/**
* Provide the implementation of the symbol at the given position and document.
*/
provideImplementation(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>;
provideImplementation(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
}

/**
Expand All @@ -772,7 +784,7 @@ export interface TypeDefinitionProvider {
/**
* Provide the type definition of the symbol at the given position and document.
*/
provideTypeDefinition(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>;
provideTypeDefinition(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/vs/editor/contrib/goToDefinition/goToDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import { onUnexpectedExternalError } from 'vs/base/common/errors';
import { registerDefaultLanguageCommand } from 'vs/editor/browser/editorExtensions';
import { Position } from 'vs/editor/common/core/position';
import { ITextModel } from 'vs/editor/common/model';
import { DefinitionLink, DefinitionProviderRegistry, ImplementationProviderRegistry, TypeDefinitionProviderRegistry, DeclarationProviderRegistry, ProviderResult } from 'vs/editor/common/modes';
import { LocationLink, DefinitionProviderRegistry, ImplementationProviderRegistry, TypeDefinitionProviderRegistry, DeclarationProviderRegistry, ProviderResult } from 'vs/editor/common/modes';
import { LanguageFeatureRegistry } from 'vs/editor/common/modes/languageFeatureRegistry';


function getDefinitions<T>(
model: ITextModel,
position: Position,
registry: LanguageFeatureRegistry<T>,
provide: (provider: T, model: ITextModel, position: Position) => ProviderResult<DefinitionLink | DefinitionLink[]>
): Promise<DefinitionLink[]> {
provide: (provider: T, model: ITextModel, position: Position) => ProviderResult<LocationLink | LocationLink[]>
): Promise<LocationLink[]> {
const provider = registry.ordered(model);

// get results
const promises = provider.map((provider): Promise<DefinitionLink | DefinitionLink[] | null | undefined> => {
const promises = provider.map((provider): Promise<LocationLink | LocationLink[] | null | undefined> => {
return Promise.resolve(provide(provider, model, position)).then(undefined, err => {
onUnexpectedExternalError(err);
return null;
Expand All @@ -34,25 +34,25 @@ function getDefinitions<T>(
}


export function getDefinitionsAtPosition(model: ITextModel, position: Position, token: CancellationToken): Promise<DefinitionLink[]> {
export function getDefinitionsAtPosition(model: ITextModel, position: Position, token: CancellationToken): Promise<LocationLink[]> {
return getDefinitions(model, position, DefinitionProviderRegistry, (provider, model, position) => {
return provider.provideDefinition(model, position, token);
});
}

export function getDeclarationsAtPosition(model: ITextModel, position: Position, token: CancellationToken): Promise<DefinitionLink[]> {
export function getDeclarationsAtPosition(model: ITextModel, position: Position, token: CancellationToken): Promise<LocationLink[]> {
return getDefinitions(model, position, DeclarationProviderRegistry, (provider, model, position) => {
return provider.provideDeclaration(model, position, token);
});
}

export function getImplementationsAtPosition(model: ITextModel, position: Position, token: CancellationToken): Promise<DefinitionLink[]> {
export function getImplementationsAtPosition(model: ITextModel, position: Position, token: CancellationToken): Promise<LocationLink[]> {
return getDefinitions(model, position, ImplementationProviderRegistry, (provider, model, position) => {
return provider.provideImplementation(model, position, token);
});
}

export function getTypeDefinitionsAtPosition(model: ITextModel, position: Position, token: CancellationToken): Promise<DefinitionLink[]> {
export function getTypeDefinitionsAtPosition(model: ITextModel, position: Position, token: CancellationToken): Promise<LocationLink[]> {
return getDefinitions(model, position, TypeDefinitionProviderRegistry, (provider, model, position) => {
return provider.provideTypeDefinition(model, position, token);
});
Expand Down
12 changes: 6 additions & 6 deletions src/vs/editor/contrib/goToDefinition/goToDefinitionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as corePosition from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { ITextModel, IWordAtPosition } from 'vs/editor/common/model';
import { DefinitionLink, Location } from 'vs/editor/common/modes';
import { LocationLink, Location } from 'vs/editor/common/modes';
import { MessageController } from 'vs/editor/contrib/message/messageController';
import { PeekContext } from 'vs/editor/contrib/referenceSearch/peekViewWidget';
import { ReferencesController } from 'vs/editor/contrib/referenceSearch/referencesController';
Expand Down Expand Up @@ -69,7 +69,7 @@ export class DefinitionAction extends EditorAction {
// * remove falsy references
// * find reference at the current pos
let idxOfCurrent = -1;
const result: DefinitionLink[] = [];
const result: LocationLink[] = [];
for (const reference of references) {
if (!reference || !reference.range) {
continue;
Expand Down Expand Up @@ -113,7 +113,7 @@ export class DefinitionAction extends EditorAction {
return definitionPromise;
}

protected _getTargetLocationForPosition(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<DefinitionLink[]> {
protected _getTargetLocationForPosition(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<LocationLink[]> {
return getDefinitionsAtPosition(model, position, token);
}

Expand Down Expand Up @@ -256,7 +256,7 @@ export class PeekDefinitionAction extends DefinitionAction {

export class DeclarationAction extends DefinitionAction {

protected _getTargetLocationForPosition(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<DefinitionLink[]> {
protected _getTargetLocationForPosition(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<LocationLink[]> {
return getDeclarationsAtPosition(model, position, token);
}

Expand Down Expand Up @@ -320,7 +320,7 @@ export class PeekDeclarationAction extends DeclarationAction {
}

export class ImplementationAction extends DefinitionAction {
protected _getTargetLocationForPosition(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<DefinitionLink[]> {
protected _getTargetLocationForPosition(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<LocationLink[]> {
return getImplementationsAtPosition(model, position, token);
}

Expand Down Expand Up @@ -378,7 +378,7 @@ export class PeekImplementationAction extends ImplementationAction {
}

export class TypeDefinitionAction extends DefinitionAction {
protected _getTargetLocationForPosition(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<DefinitionLink[]> {
protected _getTargetLocationForPosition(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<LocationLink[]> {
return getTypeDefinitionsAtPosition(model, position, token);
}

Expand Down
10 changes: 5 additions & 5 deletions src/vs/editor/contrib/goToDefinition/goToDefinitionMouse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MarkdownString } from 'vs/base/common/htmlContent';
import { IModeService } from 'vs/editor/common/services/modeService';
import { Range } from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { DefinitionProviderRegistry, DefinitionLink } from 'vs/editor/common/modes';
import { DefinitionProviderRegistry, LocationLink } from 'vs/editor/common/modes';
import { ICodeEditor, IMouseTarget, MouseTargetType } from 'vs/editor/browser/editorBrowser';
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { getDefinitionsAtPosition } from './goToDefinition';
Expand All @@ -35,7 +35,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
private toUnhook: IDisposable[];
private decorations: string[];
private currentWordUnderMouse: IWordAtPosition;
private previousPromise: CancelablePromise<DefinitionLink[]>;
private previousPromise: CancelablePromise<LocationLink[]>;

constructor(
editor: ICodeEditor,
Expand Down Expand Up @@ -152,8 +152,8 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
const previewValue = this.getPreviewValue(textEditorModel, startLineNumber);

let wordRange: Range;
if (result.origin) {
wordRange = Range.lift(result.origin);
if (result.originSelectionRange) {
wordRange = Range.lift(result.originSelectionRange);
} else {
wordRange = new Range(position.lineNumber, word.startColumn, position.lineNumber, word.endColumn);
}
Expand Down Expand Up @@ -281,7 +281,7 @@ class GotoDefinitionWithMouseEditorContribution implements editorCommon.IEditorC
DefinitionProviderRegistry.has(this.editor.getModel());
}

private findDefinition(target: IMouseTarget, token: CancellationToken): Promise<DefinitionLink[] | null> {
private findDefinition(target: IMouseTarget, token: CancellationToken): Promise<LocationLink[] | null> {
const model = this.editor.getModel();
if (!model) {
return Promise.resolve(null);
Expand Down
36 changes: 22 additions & 14 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5018,20 +5018,28 @@ declare namespace monaco.languages {
range: IRange;
}

/**
* The definition of a symbol represented as one or many [locations](#Location).
* For most programming languages there is only one location at which a symbol is
* defined.
*/
export type Definition = Location | Location[];

export interface DefinitionLink {
origin?: IRange;
export interface LocationLink {
/**
* A range to select where this link originates from.
*/
originSelectionRange?: IRange;
/**
* The target uri this link points to.
*/
uri: Uri;
/**
* The full range this link points to.
*/
range: IRange;
selectionRange?: IRange;
/**
* A range to select this link points to. Must be contained
* in `LocationLink.range`.
*/
targetSelectionRange?: IRange;
}

export type Definition = Location | Location[] | LocationLink[];

/**
* The definition provider interface defines the contract between extensions and
* the [go to definition](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-definition)
Expand All @@ -5041,7 +5049,7 @@ declare namespace monaco.languages {
/**
* Provide the definition of the symbol at the given position and document.
*/
provideDefinition(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>;
provideDefinition(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
}

/**
Expand All @@ -5053,7 +5061,7 @@ declare namespace monaco.languages {
/**
* Provide the declaration of the symbol at the given position and document.
*/
provideDeclaration(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>;
provideDeclaration(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
}

/**
Expand All @@ -5064,7 +5072,7 @@ declare namespace monaco.languages {
/**
* Provide the implementation of the symbol at the given position and document.
*/
provideImplementation(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>;
provideImplementation(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
}

/**
Expand All @@ -5075,7 +5083,7 @@ declare namespace monaco.languages {
/**
* Provide the type definition of the symbol at the given position and document.
*/
provideTypeDefinition(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>;
provideTypeDefinition(model: editor.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
}

/**
Expand Down
28 changes: 14 additions & 14 deletions src/vs/workbench/api/electron-browser/mainThreadLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha
}
}

private static _reviveDefinitionLinkDto(data: DefinitionLinkDto): modes.DefinitionLink;
private static _reviveDefinitionLinkDto(data: DefinitionLinkDto[]): modes.DefinitionLink[];
private static _reviveDefinitionLinkDto(data: DefinitionLinkDto | DefinitionLinkDto[]): modes.DefinitionLink | modes.DefinitionLink[] {
private static _reviveLocationLinkDto(data: DefinitionLinkDto): modes.LocationLink;
private static _reviveLocationLinkDto(data: DefinitionLinkDto[]): modes.LocationLink[];
private static _reviveLocationLinkDto(data: DefinitionLinkDto | DefinitionLinkDto[]): modes.LocationLink | modes.LocationLink[] {
if (!data) {
return <modes.DefinitionLink>data;
return <modes.LocationLink>data;
} else if (Array.isArray(data)) {
data.forEach(l => MainThreadLanguageFeatures._reviveDefinitionLinkDto(l));
return <modes.DefinitionLink[]>data;
data.forEach(l => MainThreadLanguageFeatures._reviveLocationLinkDto(l));
return <modes.LocationLink[]>data;
} else {
data.uri = URI.revive(data.uri);
return <modes.DefinitionLink>data;
return <modes.LocationLink>data;
}
}

Expand Down Expand Up @@ -150,32 +150,32 @@ export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesSha

$registerDefinitionSupport(handle: number, selector: ISerializedDocumentFilter[]): void {
this._registrations[handle] = modes.DefinitionProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.DefinitionProvider>{
provideDefinition: (model, position, token): Promise<modes.DefinitionLink[]> => {
return this._proxy.$provideDefinition(handle, model.uri, position, token).then(MainThreadLanguageFeatures._reviveDefinitionLinkDto);
provideDefinition: (model, position, token): Promise<modes.LocationLink[]> => {
return this._proxy.$provideDefinition(handle, model.uri, position, token).then(MainThreadLanguageFeatures._reviveLocationLinkDto);
}
});
}

$registerDeclarationSupport(handle: number, selector: ISerializedDocumentFilter[]): void {
this._registrations[handle] = modes.DeclarationProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.DeclarationProvider>{
provideDeclaration: (model, position, token) => {
return this._proxy.$provideDeclaration(handle, model.uri, position, token).then(MainThreadLanguageFeatures._reviveDefinitionLinkDto);
return this._proxy.$provideDeclaration(handle, model.uri, position, token).then(MainThreadLanguageFeatures._reviveLocationLinkDto);
}
});
}

$registerImplementationSupport(handle: number, selector: ISerializedDocumentFilter[]): void {
this._registrations[handle] = modes.ImplementationProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.ImplementationProvider>{
provideImplementation: (model, position, token): Promise<modes.Definition> => {
return this._proxy.$provideImplementation(handle, model.uri, position, token).then(MainThreadLanguageFeatures._reviveDefinitionLinkDto);
provideImplementation: (model, position, token): Promise<modes.LocationLink[]> => {
return this._proxy.$provideImplementation(handle, model.uri, position, token).then(MainThreadLanguageFeatures._reviveLocationLinkDto);
}
});
}

$registerTypeDefinitionSupport(handle: number, selector: ISerializedDocumentFilter[]): void {
this._registrations[handle] = modes.TypeDefinitionProviderRegistry.register(typeConverters.LanguageSelector.from(selector), <modes.TypeDefinitionProvider>{
provideTypeDefinition: (model, position, token): Promise<modes.Definition> => {
return this._proxy.$provideTypeDefinition(handle, model.uri, position, token).then(MainThreadLanguageFeatures._reviveDefinitionLinkDto);
provideTypeDefinition: (model, position, token): Promise<modes.LocationLink[]> => {
return this._proxy.$provideTypeDefinition(handle, model.uri, position, token).then(MainThreadLanguageFeatures._reviveLocationLinkDto);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,10 +804,10 @@ export interface LocationDto {
}

export interface DefinitionLinkDto {
origin?: IRange;
originSelectionRange?: IRange;
uri: UriComponents;
range: IRange;
selectionRange?: IRange;
targetSelectionRange?: IRange;
}

export interface WorkspaceSymbolDto extends IdObject {
Expand Down
Loading

0 comments on commit 14ce518

Please sign in to comment.