diff --git a/src/vs/editor/contrib/suggest/browser/suggest.ts b/src/vs/editor/contrib/suggest/browser/suggest.ts index 89f4c9cc52a6a9143371da0bb3970b9925710cd2..705c6b265d2509a5e25d5037402b4cdd3aa958b9 100644 --- a/src/vs/editor/contrib/suggest/browser/suggest.ts +++ b/src/vs/editor/contrib/suggest/browser/suggest.ts @@ -157,7 +157,7 @@ export class SuggestController implements EditorCommon.IEditorContribution { } } - public hideSuggestWidget(): void { + public cancelSuggestWidget(): void { if (this.widget) { this.widget.cancel(); } @@ -225,7 +225,7 @@ CommonEditorRegistry.registerEditorCommand(ACCEPT_SELECTED_SUGGESTION_CMD, weigh }); CommonEditorRegistry.registerEditorCommand('hideSuggestWidget', weight, { primary: KeyCode.Escape }, true, CONTEXT_SUGGEST_WIDGET_VISIBLE, (ctx, editor, args) => { const controller = SuggestController.getSuggestController(editor); - controller.hideSuggestWidget(); + controller.cancelSuggestWidget(); }); CommonEditorRegistry.registerEditorCommand('selectNextSuggestion', weight, { primary: KeyCode.DownArrow }, true, CONTEXT_SUGGEST_WIDGET_VISIBLE, (ctx, editor, args) => { const controller = SuggestController.getSuggestController(editor); diff --git a/src/vs/editor/contrib/suggest/browser/suggestWidget.ts b/src/vs/editor/contrib/suggest/browser/suggestWidget.ts index 2bb3c7b020b61dc9e9afb3ecbee9f78e4199f132..118bc65ea0e6f84dbecf370c863e49c2e380fcd4 100644 --- a/src/vs/editor/contrib/suggest/browser/suggestWidget.ts +++ b/src/vs/editor/contrib/suggest/browser/suggestWidget.ts @@ -30,6 +30,7 @@ import { ISuggestResult2 } from '../common/suggest'; import URI from 'vs/base/common/uri'; import { isFalsyOrEmpty } from 'vs/base/common/arrays'; import { onUnexpectedError, isPromiseCanceledError, illegalArgument } from 'vs/base/common/errors'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; class CompletionItem { @@ -267,7 +268,15 @@ interface ISuggestionTemplateData { class Renderer implements Tree.IRenderer { - constructor(private widget: SuggestWidget) {} + private triggerKeybindingLabel: string; + + constructor( + private widget: SuggestWidget, + @IKeybindingService keybindingService: IKeybindingService + ) { + const keybindings = keybindingService.lookupKeybindings('editor.action.triggerSuggest'); + this.triggerKeybindingLabel = keybindings.length === 0 ? '' : ` (${keybindingService.getLabelFor(keybindings[0])})`; + } public getHeight(tree: Tree.ITree, element: any): number { if (element instanceof CompletionItem) { @@ -304,7 +313,7 @@ class Renderer implements Tree.IRenderer { const docs = append(text, $('.docs')); data.documentation = append(docs, $('span.docs-text')); data.documentationDetails = append(docs, $('span.docs-details.octicon.octicon-info')); - data.documentationDetails.title = nls.localize('readMore', "Read More..."); + data.documentationDetails.title = nls.localize('readMore', "Read More...{0}", this.triggerKeybindingLabel); return data; } @@ -405,6 +414,7 @@ class SuggestionDetails { const header = append(this.el, $('.header')); this.title = append(header, $('span.title')); this.back = append(header, $('span.go-back.octicon.octicon-x')); + this.back.title = nls.localize('goback', "Go back"); this.body = append(this.el, $('.body')); this.type = append(this.body, $('p.type')); this.docs = append(this.body, $('p.docs')); @@ -493,7 +503,8 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable private editor: EditorBrowser.ICodeEditor, private model: SuggestModel, @IKeybindingService keybindingService: IKeybindingService, - @ITelemetryService telemetryService: ITelemetryService + @ITelemetryService telemetryService: ITelemetryService, + @IInstantiationService instantiationService: IInstantiationService ) { this.isAuto = false; this.oldFocus = null; @@ -514,9 +525,10 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable this.messageElement = append(this.element, $('.message')); this.treeElement = append(this.element, $('.tree')); this.details = new SuggestionDetails(this.element, this); + this.renderer = instantiationService.createInstance(Renderer, this); const configuration = { - renderer: this.renderer = new Renderer(this), + renderer: this.renderer, dataSource: new DataSource(), controller: new Controller(), filter: new Filter(() => this.state), @@ -947,7 +959,11 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable } public cancel(): void { - this.model.cancel(); + if (this.state === State.Details) { + this.toggleDetails(); + } else { + this.model.cancel(); + } } public getPosition(): EditorBrowser.IContentWidgetPosition {