Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug settings for changing variable editor #197458

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/vs/workbench/contrib/debug/browser/debug.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,16 @@ configurationRegistry.registerConfiguration({
type: 'boolean',
markdownDescription: nls.localize({ comment: ['This is the description for a setting'], key: 'debug.hideLauncherWhileDebugging' }, "Hide 'Start Debugging' control in title bar of 'Run and Debug' view while debugging is active. Only relevant when `{0}` is not `docked`.", '#debug.toolBarLocation#'),
default: false
}
},
'debug.variableEditorExtensionId': {
type: 'string',
description: nls.localize('debug.variableEditorExtensionId', "ID of extension to use for viewing debug variables."),
default: 'ms-vscode.hexeditor'
},
'debug.variableEditorEditorId': {
type: 'string',
description: nls.localize('debug.variableEditorEditorId', "ID of editor to use for viewing debug variables."),
default: 'hexEditor.hexedit'
},
}
});
25 changes: 13 additions & 12 deletions src/vs/workbench/contrib/debug/browser/variablesView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewl
import { IViewDescriptorService } from 'vs/workbench/common/views';
import { AbstractExpressionsRenderer, IExpressionTemplateData, IInputBoxOptions, renderVariable, renderViewTree } from 'vs/workbench/contrib/debug/browser/baseDebugView';
import { LinkDetector } from 'vs/workbench/contrib/debug/browser/linkDetector';
import { CONTEXT_BREAK_WHEN_VALUE_CHANGES_SUPPORTED, CONTEXT_BREAK_WHEN_VALUE_IS_ACCESSED_SUPPORTED, CONTEXT_BREAK_WHEN_VALUE_IS_READ_SUPPORTED, CONTEXT_CAN_VIEW_MEMORY, CONTEXT_DEBUG_PROTOCOL_VARIABLE_MENU_CONTEXT, CONTEXT_VARIABLES_FOCUSED, CONTEXT_VARIABLE_EVALUATE_NAME_PRESENT, CONTEXT_VARIABLE_IS_READONLY, IDataBreakpointInfoResponse, IDebugService, IExpression, IScope, IStackFrame, VARIABLES_VIEW_ID } from 'vs/workbench/contrib/debug/common/debug';
import { CONTEXT_BREAK_WHEN_VALUE_CHANGES_SUPPORTED, CONTEXT_BREAK_WHEN_VALUE_IS_ACCESSED_SUPPORTED, CONTEXT_BREAK_WHEN_VALUE_IS_READ_SUPPORTED, CONTEXT_CAN_VIEW_MEMORY, CONTEXT_DEBUG_PROTOCOL_VARIABLE_MENU_CONTEXT, CONTEXT_VARIABLES_FOCUSED, CONTEXT_VARIABLE_EVALUATE_NAME_PRESENT, CONTEXT_VARIABLE_IS_READONLY, IDataBreakpointInfoResponse, IDebugService, IExpression, IScope, IStackFrame, VARIABLES_VIEW_ID, IDebugConfiguration } from 'vs/workbench/contrib/debug/common/debug';
import { ErrorScope, Expression, getUriForDebugMemory, Scope, StackFrame, Variable } from 'vs/workbench/contrib/debug/common/debugModel';
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
Expand Down Expand Up @@ -525,9 +525,6 @@ CommandsRegistry.registerCommand({

export const VIEW_MEMORY_ID = 'workbench.debug.viewlet.action.viewMemory';

const HEX_EDITOR_EXTENSION_ID = 'ms-vscode.hexeditor';
const HEX_EDITOR_EDITOR_ID = 'hexEditor.hexedit';

CommandsRegistry.registerCommand({
id: VIEW_MEMORY_ID,
handler: async (accessor: ServicesAccessor, arg: IVariablesContext | IExpression, ctx?: (Variable | Expression)[]) => {
Expand Down Expand Up @@ -559,9 +556,11 @@ CommandsRegistry.registerCommand({
const progressService = accessor.get(IProgressService);
const extensionService = accessor.get(IExtensionService);
const telemetryService = accessor.get(ITelemetryService);
const configurationService = accessor.get(IConfigurationService);

const ext = await extensionService.getExtension(HEX_EDITOR_EXTENSION_ID);
if (ext || await tryInstallHexEditor(notifications, progressService, extensionService, commandService)) {
const extensionId = configurationService.getValue<IDebugConfiguration>('debug').variableEditorExtensionId;
const ext = await extensionService.getExtension(extensionId);
if (ext || await tryInstallVariableEditor(notifications, progressService, extensionService, commandService, configurationService)) {
/* __GDPR__
"debug/didViewMemory" : {
"owner": "connor4312",
Expand All @@ -572,24 +571,25 @@ CommandsRegistry.registerCommand({
debugType: debugService.getModel().getSession(sessionId)?.configuration.type,
});

const editorId = configurationService.getValue<IDebugConfiguration>('debug').variableEditorEditorId;
await editorService.openEditor({
resource: getUriForDebugMemory(sessionId, memoryReference),
options: {
revealIfOpened: true,
override: HEX_EDITOR_EDITOR_ID,
override: editorId,
},
}, SIDE_GROUP);
}
}
});

function tryInstallHexEditor(notifications: INotificationService, progressService: IProgressService, extensionService: IExtensionService, commandService: ICommandService) {
function tryInstallVariableEditor(notifications: INotificationService, progressService: IProgressService, extensionService: IExtensionService, commandService: ICommandService, configurationService: IConfigurationService) {
return new Promise<boolean>(resolve => {
let installing = false;

const handle = notifications.prompt(
Severity.Info,
localize("viewMemory.prompt", "Inspecting binary data requires the Hex Editor extension. Would you like to install it now?"), [
localize("viewMemory.prompt", "Inspecting binary data requires an appropiate extension. Would you like to install one now?"), [
{
label: localize("cancel", "Cancel"),
run: () => resolve(false),
Expand All @@ -602,13 +602,14 @@ function tryInstallHexEditor(notifications: INotificationService, progressServic
await progressService.withProgress(
{
location: ProgressLocation.Notification,
title: localize("viewMemory.install.progress", "Installing the Hex Editor..."),
title: localize("viewMemory.install.progress", "Installing..."),
},
async () => {
await commandService.executeCommand('workbench.extensions.installExtension', HEX_EDITOR_EXTENSION_ID);
const extensionId = configurationService.getValue<IDebugConfiguration>('debug').variableEditorExtensionId;
await commandService.executeCommand('workbench.extensions.installExtension', extensionId);
// it seems like the extension is not registered immediately on install --
// wait for it to appear before returning.
while (!(await extensionService.getExtension(HEX_EDITOR_EXTENSION_ID))) {
while (!(await extensionService.getExtension(extensionId))) {
await timeout(30);
}
},
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/debug/common/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,8 @@ export interface IDebugConfiguration {
};
autoExpandLazyVariables: boolean;
enableStatusBarColor: boolean;
variableEditorExtensionId: string;
variableEditorEditorId: string;
}

export interface IGlobalConfig {
Expand Down