Adds menu 'editor/inlineCompletions/actions' that extensions can contribute to.

This commit is contained in:
Henning Dieterichs 2021-05-28 14:30:21 +02:00
parent 098dfd56e3
commit a2d1bd0d15
No known key found for this signature in database
GPG key ID: 771381EFFDB9EC06
3 changed files with 32 additions and 7 deletions

View file

@ -11,9 +11,10 @@ import { IModelDecoration } from 'vs/editor/common/model';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { GhostTextController, ShowNextInlineCompletionAction, ShowPreviousInlineCompletionAction } from 'vs/editor/contrib/inlineCompletions/ghostTextController';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions/common/actions';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
export class InlineCompletionsHover implements IHoverPart {
constructor(
public readonly owner: IEditorHoverParticipant<InlineCompletionsHover>,
public readonly range: Range
@ -25,15 +26,15 @@ export class InlineCompletionsHover implements IHoverPart {
&& this.range.endColumn >= hoverRange.endColumn
);
}
}
export class InlineCompletionsHoverParticipant implements IEditorHoverParticipant<InlineCompletionsHover> {
constructor(
private readonly _editor: ICodeEditor,
hover: IEditorHover,
@ICommandService private readonly _commandService: ICommandService,
@IMenuService private readonly _menuService: IMenuService,
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
) { }
computeSync(hoverRange: Range, lineDecorations: IModelDecoration[]): InlineCompletionsHover[] {
@ -45,17 +46,34 @@ export class InlineCompletionsHoverParticipant implements IEditorHoverParticipan
}
renderHoverParts(hoverParts: InlineCompletionsHover[], fragment: DocumentFragment, statusBar: EditorHoverStatusBar): IDisposable {
const menu = this._menuService.createMenu(
MenuId.InlineCompletionsActions,
this._contextKeyService
);
statusBar.addAction({
label: nls.localize('showPreviousInlineCompletion', "⬅️ Previous"),
label: nls.localize('showPreviousInlineCompletion', "Previous"),
commandId: ShowPreviousInlineCompletionAction.ID,
run: () => this._commandService.executeCommand(ShowPreviousInlineCompletionAction.ID)
});
statusBar.addAction({
label: nls.localize('showNextInlineCompletion', "Next ➡️"),
label: nls.localize('showNextInlineCompletion', "Next"),
commandId: ShowNextInlineCompletionAction.ID,
run: () => this._commandService.executeCommand(ShowNextInlineCompletionAction.ID)
});
for (const [_, group] of menu.getActions()) {
for (const action of group) {
if (action instanceof MenuItemAction) {
statusBar.addAction({
label: action.label,
commandId: action.item.id,
run: () => this._commandService.executeCommand(action.item.id)
});
}
}
}
return Disposable.None;
}
}

View file

@ -171,6 +171,7 @@ export class MenuId {
static readonly TerminalTabEmptyAreaContext = new MenuId('TerminalTabEmptyAreaContext');
static readonly TerminalInlineTabContext = new MenuId('TerminalInlineTabContext');
static readonly WebviewContext = new MenuId('WebviewContext');
static readonly InlineCompletionsActions = new MenuId('InlineCompletionsActions');
readonly id: number;
readonly _debugName: string;

View file

@ -229,7 +229,13 @@ const apiMenus: IAPIMenu[] = [
key: 'ports/item/port/inline',
id: MenuId.TunnelPortInline,
description: localize('view.tunnelPortInline', "The Ports view item port inline menu")
}
},
{
key: 'editor/inlineCompletions/actions',
id: MenuId.InlineCompletionsActions,
description: localize('inlineCompletions.actions', "The actions shown when hovering on an inline completion"),
supportsSubmenus: false
},
];
namespace schema {