Skip to content

Commit

Permalink
peek - use meta title to classify contents
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 11, 2019
1 parent 336ff85 commit e74086a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 43 deletions.
43 changes: 7 additions & 36 deletions src/vs/editor/contrib/gotoSymbol/goToCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ abstract class SymbolNavigationAction extends EditorAction {

protected abstract _getNoResultFoundMessage(info: IWordAtPosition | null): string;

protected abstract _getMetaTitle(model: ReferencesModel): string;

protected abstract _getAlternativeCommand(): string;

protected abstract _getGoToPreference(editor: IActiveCodeEditor): GoToLocationValues;
Expand Down Expand Up @@ -171,7 +169,7 @@ abstract class SymbolNavigationAction extends EditorAction {
export class DefinitionAction extends SymbolNavigationAction {

protected async _getLocationModel(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<ReferencesModel> {
return new ReferencesModel(await getDefinitionsAtPosition(model, position, token));
return new ReferencesModel(await getDefinitionsAtPosition(model, position, token), nls.localize('def.title', 'Definitions'));
}

protected _getNoResultFoundMessage(info: IWordAtPosition | null): string {
Expand All @@ -180,10 +178,6 @@ export class DefinitionAction extends SymbolNavigationAction {
: nls.localize('generic.noResults', "No definition found");
}

protected _getMetaTitle(model: ReferencesModel): string {
return model.references.length > 1 ? nls.localize('meta.title', " – {0} definitions", model.references.length) : '';
}

protected _getAlternativeCommand(): string {
return 'editor.action.goToReferences';
}
Expand Down Expand Up @@ -295,7 +289,7 @@ registerEditorAction(class PeekDefinitionAction extends DefinitionAction {
class DeclarationAction extends SymbolNavigationAction {

protected async _getLocationModel(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<ReferencesModel> {
return new ReferencesModel(await getDeclarationsAtPosition(model, position, token));
return new ReferencesModel(await getDeclarationsAtPosition(model, position, token), nls.localize('decl.title', 'Declarations'));
}

protected _getNoResultFoundMessage(info: IWordAtPosition | null): string {
Expand All @@ -304,10 +298,6 @@ class DeclarationAction extends SymbolNavigationAction {
: nls.localize('decl.generic.noResults', "No declaration found");
}

protected _getMetaTitle(model: ReferencesModel): string {
return model.references.length > 1 ? nls.localize('decl.meta.title', " – {0} declarations", model.references.length) : '';
}

protected _getAlternativeCommand(): string {
return 'editor.action.goToReferences';
}
Expand Down Expand Up @@ -352,10 +342,6 @@ registerEditorAction(class GoToDeclarationAction extends DeclarationAction {
? nls.localize('decl.noResultWord', "No declaration found for '{0}'", info.word)
: nls.localize('decl.generic.noResults', "No declaration found");
}

protected _getMetaTitle(model: ReferencesModel): string {
return model.references.length > 1 ? nls.localize('decl.meta.title', " – {0} declarations", model.references.length) : '';
}
});

registerEditorAction(class PeekDeclarationAction extends DeclarationAction {
Expand Down Expand Up @@ -384,7 +370,7 @@ registerEditorAction(class PeekDeclarationAction extends DeclarationAction {
class TypeDefinitionAction extends SymbolNavigationAction {

protected async _getLocationModel(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<ReferencesModel> {
return new ReferencesModel(await getTypeDefinitionsAtPosition(model, position, token));
return new ReferencesModel(await getTypeDefinitionsAtPosition(model, position, token), nls.localize('typedef.title', 'Type Definitions'));
}

protected _getNoResultFoundMessage(info: IWordAtPosition | null): string {
Expand All @@ -393,10 +379,6 @@ class TypeDefinitionAction extends SymbolNavigationAction {
: nls.localize('goToTypeDefinition.generic.noResults', "No type definition found");
}

protected _getMetaTitle(model: ReferencesModel): string {
return model.references.length > 1 ? nls.localize('meta.typeDefinitions.title', " – {0} type definitions", model.references.length) : '';
}

protected _getAlternativeCommand(): string {
return 'editor.action.goToReferences';
}
Expand Down Expand Up @@ -470,7 +452,7 @@ registerEditorAction(class PeekTypeDefinitionAction extends TypeDefinitionAction
class ImplementationAction extends SymbolNavigationAction {

protected async _getLocationModel(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<ReferencesModel> {
return new ReferencesModel(await getImplementationsAtPosition(model, position, token));
return new ReferencesModel(await getImplementationsAtPosition(model, position, token), nls.localize('impl.title', 'Implementations'));
}

protected _getNoResultFoundMessage(info: IWordAtPosition | null): string {
Expand All @@ -479,10 +461,6 @@ class ImplementationAction extends SymbolNavigationAction {
: nls.localize('goToImplementation.generic.noResults', "No implementation found");
}

protected _getMetaTitle(model: ReferencesModel): string {
return model.references.length > 1 ? nls.localize('meta.implementations.title', " – {0} implementations", model.references.length) : '';
}

protected _getAlternativeCommand(): string {
return '';
}
Expand Down Expand Up @@ -561,7 +539,7 @@ registerEditorAction(class PeekImplementationAction extends ImplementationAction
class ReferencesAction extends SymbolNavigationAction {

protected async _getLocationModel(model: ITextModel, position: corePosition.Position, token: CancellationToken): Promise<ReferencesModel> {
return new ReferencesModel(await getReferencesAtPosition(model, position, token));
return new ReferencesModel(await getReferencesAtPosition(model, position, token), nls.localize('ref.title', 'References'));
}

protected _getNoResultFoundMessage(info: IWordAtPosition | null): string {
Expand All @@ -570,12 +548,6 @@ class ReferencesAction extends SymbolNavigationAction {
: nls.localize('references.noGeneric', "No references found");
}

protected _getMetaTitle(model: ReferencesModel): string {
return model.references.length > 1
? nls.localize('meta.titleReference', " – {0} references", model.references.length)
: '';
}

protected _getAlternativeCommand(): string {
return '';
}
Expand Down Expand Up @@ -667,7 +639,7 @@ class GenericGoToLocationAction extends SymbolNavigationAction {
}

protected async _getLocationModel(_model: ITextModel, _position: corePosition.Position, _token: CancellationToken): Promise<ReferencesModel | undefined> {
return new ReferencesModel(this._references);
return new ReferencesModel(this._references, nls.localize('generic.title', 'Locations'));
}

protected _getNoResultFoundMessage(info: IWordAtPosition | null): string {
Expand All @@ -678,7 +650,6 @@ class GenericGoToLocationAction extends SymbolNavigationAction {
return this._gotoMultipleBehaviour ?? editor.getOption(EditorOption.gotoLocation).multipleReferences;
}

protected _getMetaTitle() { return ''; }
protected _getAlternativeCommand() { return ''; }
}

Expand Down Expand Up @@ -736,7 +707,7 @@ CommandsRegistry.registerCommand({
return undefined;
}

const references = createCancelablePromise(token => getReferencesAtPosition(control.getModel(), corePosition.Position.lift(position), token).then(references => new ReferencesModel(references)));
const references = createCancelablePromise(token => getReferencesAtPosition(control.getModel(), corePosition.Position.lift(position), token).then(references => new ReferencesModel(references, nls.localize('ref.title', 'References'))));
const range = new Range(position.lineNumber, position.column, position.lineNumber, position.column);
return Promise.resolve(controller.toggleWidget(range, references, false));
});
Expand Down
6 changes: 2 additions & 4 deletions src/vs/editor/contrib/gotoSymbol/peek/referencesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ export abstract class ReferencesController implements editorCommon.IEditorContri
if (this._widget && this._model && this._editor.hasModel()) { // might have been closed

// set title
if (this._model.references.length === 1) {
this._widget.setMetaTitle(nls.localize('metaTitle.1', "1 result"));
} else if (!this._model.isEmpty) {
this._widget.setMetaTitle(nls.localize('metaTitle.N', "{0} results", this._model.references.length));
if (!this._model.isEmpty) {
this._widget.setMetaTitle(nls.localize('metaTitle.N', "{0} ({1})", this._model.title, this._model.references.length));
} else {
this._widget.setMetaTitle('');
}
Expand Down
10 changes: 8 additions & 2 deletions src/vs/editor/contrib/gotoSymbol/referencesModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ export class ReferencesModel implements IDisposable {

private readonly _disposables = new DisposableStore();
private readonly _links: LocationLink[];
private readonly _title: string;

readonly groups: FileReferences[] = [];
readonly references: OneReference[] = [];

readonly _onDidChangeReferenceRange = new Emitter<OneReference>();
readonly onDidChangeReferenceRange: Event<OneReference> = this._onDidChangeReferenceRange.event;

constructor(links: LocationLink[]) {
constructor(links: LocationLink[], title: string) {
this._links = links;
this._title = title;

// grouping and sorting
const [providersFirst] = links;
Expand Down Expand Up @@ -192,7 +194,11 @@ export class ReferencesModel implements IDisposable {
}

clone(): ReferencesModel {
return new ReferencesModel(this._links);
return new ReferencesModel(this._links, this._title);
}

get title(): string {
return this._title;
}

get isEmpty(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ suite('references', function () {
}, {
uri: URI.file('/src/can'),
range: new Range(1, 1, 1, 1)
}]);
}], 'FOO');

let ref = model.nearestReference(URI.file('/src/can'), new Position(1, 1));
assert.equal(ref!.uri.path, '/src/can');
Expand Down

0 comments on commit e74086a

Please sign in to comment.