From 5c8135a03b690473721f75073b2a6cfa921e4eae Mon Sep 17 00:00:00 2001 From: piperr Date: Tue, 12 Nov 2024 17:08:01 +0100 Subject: [PATCH] Disable editing of read only variables The debug UI allows to change the variable content. The DAP server provides information if the variable is editable. If the variable is not editable, we disable the functionality in the UI. Signed-off-by: Roman Piper --- packages/debug/src/browser/console/debug-console-items.tsx | 6 +++++- .../src/browser/debug-frontend-application-contribution.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/debug/src/browser/console/debug-console-items.tsx b/packages/debug/src/browser/console/debug-console-items.tsx index c920e4a27fab6..afc5032b32a85 100644 --- a/packages/debug/src/browser/console/debug-console-items.tsx +++ b/packages/debug/src/browser/console/debug-console-items.tsx @@ -161,6 +161,10 @@ export class DebugVariable extends ExpressionContainer { return this._value || this.variable.value; } + get readOnly(): boolean { + return this.variable.presentationHint?.attributes?.includes('readOnly') ?? false; + } + override render(): React.ReactNode { const { type, value, name } = this; return
@@ -234,7 +238,7 @@ export class DebugVariable extends ExpressionContainer { protected setNameRef = (nameRef: HTMLSpanElement | null) => this.nameRef = nameRef || undefined; async open(): Promise { - if (!this.supportSetVariable) { + if (!this.supportSetVariable || this.readOnly) { return; } const input = new SingleTextInputDialog({ diff --git a/packages/debug/src/browser/debug-frontend-application-contribution.ts b/packages/debug/src/browser/debug-frontend-application-contribution.ts index 51401d39a53ec..62a58db074a0e 100644 --- a/packages/debug/src/browser/debug-frontend-application-contribution.ts +++ b/packages/debug/src/browser/debug-frontend-application-contribution.ts @@ -856,7 +856,7 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi registry.registerCommand(DebugCommands.SET_VARIABLE_VALUE, { execute: () => this.selectedVariable && this.selectedVariable.open(), - isEnabled: () => !!this.selectedVariable && this.selectedVariable.supportSetVariable, + isEnabled: () => !!this.selectedVariable && this.selectedVariable.supportSetVariable && !this.selectedVariable.readOnly, isVisible: () => !!this.selectedVariable && this.selectedVariable.supportSetVariable }); registry.registerCommand(DebugCommands.COPY_VARIABLE_VALUE, {