Skip to content

Commit

Permalink
feat: add canViewMemory contextkey
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricbet committed May 16, 2022
1 parent 0e6ccc9 commit 89495dc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CONTEXT_SET_VARIABLE_SUPPORTED,
CONTEXT_RESTART_FRAME_SUPPORTED,
CONTEXT_DEBUG_PROTOCOL_VARIABLE_MENU_CONTEXT,
CONTEXT_CAN_VIEW_MEMORY,
} from './../../common/constants';

@Injectable()
Expand All @@ -29,6 +30,7 @@ export class DebugContextKey {
public readonly contextSetVariableSupported: IContextKey<boolean>;
public readonly contextRestartFrameSupported: IContextKey<boolean>;
public readonly contextDebugProtocolVariableMenu: IContextKey<string>;
public readonly contextCanViewMemory: IContextKey<boolean>;

constructor(@Optional() dom?: HTMLElement) {
this._contextKeyService = this.globalContextKeyService.createScoped(dom);
Expand All @@ -40,6 +42,7 @@ export class DebugContextKey {
this.contextSetVariableSupported = CONTEXT_SET_VARIABLE_SUPPORTED.bind(this.contextKeyScoped);
this.contextRestartFrameSupported = CONTEXT_RESTART_FRAME_SUPPORTED.bind(this.contextKeyScoped);
this.contextDebugProtocolVariableMenu = CONTEXT_DEBUG_PROTOCOL_VARIABLE_MENU_CONTEXT.bind(this.contextKeyScoped);
this.contextCanViewMemory = CONTEXT_CAN_VIEW_MEMORY.bind(this.contextKeyScoped);
}

public get contextKeyScoped(): IScopedContextKeyService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ export class DebugVariablesModelService {
);
}

// 决定某一变量是否允许以十六进制视图查看
if (expression.session?.capabilities.supportsReadMemoryRequest && expression.memoryReference !== undefined) {
this.debugContextKey.contextCanViewMemory.set(true);
} else {
this.debugContextKey.contextCanViewMemory.set(false);
}

const menus = this.contextMenuService.createMenu({
id: MenuId.DebugVariablesContext,
contextKeyService: this.debugContextKey.contextKeyScoped,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
CONTEXT_IN_DEBUG_MODE,
CONTEXT_SET_VARIABLE_SUPPORTED,
DEBUG_MEMORY_SCHEME,
CONTEXT_CAN_VIEW_MEMORY,
} from './../../../common/constants';
import { DebugWatchModelService } from './../watch/debug-watch-tree.model.service';
import { DebugVariablesModelService } from './debug-variables-tree.model.service';
Expand Down Expand Up @@ -154,7 +155,6 @@ export class VariablesPanelContribution implements BrowserEditorContribution, Me
path: '/' + encodeURIComponent(memoryReference || '') + '/memory.bin',
}),
{
split: EditorGroupSplitAction.Right,
disableNavigate: true,
preview: true,
forceOpenType: {
Expand Down Expand Up @@ -235,7 +235,9 @@ export class VariablesPanelContribution implements BrowserEditorContribution, Me
id: DEBUG_COMMANDS.VIEW_MEMORY_ID.id,
label: localize('debug.variables.view.memory'),
},
type: 'checkbox',
iconClass: '',
when: `${CONTEXT_CAN_VIEW_MEMORY.equalsTo(true)} && ${CONTEXT_IN_DEBUG_MODE.equalsTo(true)}`,
type: 'icon',
});
}
}
1 change: 1 addition & 0 deletions packages/debug/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ export const CONTEXT_VARIABLE_EVALUATE_NAME_PRESENT = new RawContextKey<boolean>
export const CONTEXT_EXCEPTION_WIDGET_VISIBLE = new RawContextKey<boolean>('exceptionWidgetVisible', false);
export const CONTEXT_MULTI_SESSION_REPL = new RawContextKey<boolean>('multiSessionRepl', false);
export const CONTEXT_MULTI_SESSION_DEBUG = new RawContextKey<boolean>('multiSessionDebug', false);
export const CONTEXT_CAN_VIEW_MEMORY = new RawContextKey<boolean>('canViewMemory', undefined);

0 comments on commit 89495dc

Please sign in to comment.