Expose the contribution.menus for Variable view

fixes #70377
This commit is contained in:
isidor 2020-08-28 15:07:25 +02:00
parent 2a9a512ee4
commit 489672365e
4 changed files with 36 additions and 4 deletions

View file

@ -61,7 +61,12 @@ const apiMenus: IAPIMenu[] = [
{
key: 'debug/callstack/context',
id: MenuId.DebugCallStackContext,
description: localize('menus.debugCallstackContext', "The debug callstack context menu")
description: localize('menus.debugCallstackContext', "The debug callstack view context menu")
},
{
key: 'debug/variables/context',
id: MenuId.DebugVariablesContext,
description: localize('menus.debugVariablesContext', "The debug variables view context menu")
},
{
key: 'debug/toolBar',

View file

@ -21,7 +21,6 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { registerThemingParticipant, IThemeService, Themable } from 'vs/platform/theme/common/themeService';
import { registerColor, contrastBorder, widgetShadow } from 'vs/platform/theme/common/colorRegistry';
import { localize } from 'vs/nls';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { RunOnceScheduler } from 'vs/base/common/async';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@ -58,7 +57,6 @@ export class DebugToolBar extends Themable implements IWorkbenchContribution {
@IThemeService themeService: IThemeService,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IMenuService menuService: IMenuService,
@IContextMenuService contextMenuService: IContextMenuService,
@IContextKeyService contextKeyService: IContextKeyService
) {
super(themeService);

View file

@ -34,6 +34,8 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { withUndefinedAsNull } from 'vs/base/common/types';
import { IMenuService, IMenu, MenuId } from 'vs/platform/actions/common/actions';
import { createAndFillInContextMenuActions } from 'vs/platform/actions/browser/menuEntryActionViewItem';
const $ = dom.$;
let forgetScopes = true;
@ -47,6 +49,7 @@ export class VariablesView extends ViewPane {
private tree!: WorkbenchAsyncDataTree<IStackFrame | null, IExpression | IScope, FuzzyScore>;
private savedViewState = new Map<string, IAsyncDataTreeViewState>();
private autoExpandedScopes = new Set<string>();
private menu: IMenu;
constructor(
options: IViewletViewOptions,
@ -61,9 +64,13 @@ export class VariablesView extends ViewPane {
@IOpenerService openerService: IOpenerService,
@IThemeService themeService: IThemeService,
@ITelemetryService telemetryService: ITelemetryService,
@IMenuService menuService: IMenuService
) {
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService);
this.menu = menuService.createMenu(MenuId.DebugVariablesContext, contextKeyService);
this._register(this.menu);
// Use scheduler to prevent unnecessary flashing
this.onFocusStackFrameScheduler = new RunOnceScheduler(async () => {
const stackFrame = this.debugService.getViewModel().focusedStackFrame;
@ -213,11 +220,17 @@ export class VariablesView extends ViewPane {
}
}
const context = {
container: (variable.parent as (Variable | Scope)).toDebugProtocolObject(),
variable: variable.toDebugProtocolObject()
};
const actionsDisposable = createAndFillInContextMenuActions(this.menu, { arg: context, shouldForwardArgs: false }, actions, this.contextMenuService);
this.contextMenuService.showContextMenu({
getAnchor: () => e.anchor,
getActions: () => actions,
getActionsContext: () => variable,
onHide: () => dispose(actions)
onHide: () => dispose(actionsDisposable)
});
}
}

View file

@ -247,6 +247,14 @@ export class Variable extends ExpressionContainer implements IExpression {
toString(): string {
return `${this.name}: ${this.value}`;
}
toDebugProtocolObject(): DebugProtocol.Variable {
return {
name: this.name,
variablesReference: this.reference || 0,
value: this.value
};
}
}
export class Scope extends ExpressionContainer implements IScope {
@ -267,6 +275,14 @@ export class Scope extends ExpressionContainer implements IScope {
toString(): string {
return this.name;
}
toDebugProtocolObject(): DebugProtocol.Scope {
return {
name: this.name,
variablesReference: this.reference || 0,
expensive: this.expensive
};
}
}
export class ErrorScope extends Scope {