Skip to content

extension: add debug menu for var show in doc #3818

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
add type annotations
  • Loading branch information
MistaTwista committed Aug 10, 2025
commit 004c8105807e112eb835ef8d8746e5a1c3753754
17 changes: 17 additions & 0 deletions extension/src/goDebugCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const sessions = new Map<string, vscode.DebugSession>();
vscode.debug.onDidStartDebugSession((s) => sessions.set(s.id, s));
vscode.debug.onDidTerminateDebugSession((s) => sessions.delete(s.id));

/**
* Registers commands to improve the debugging experience for Go.
*
* Currently, it adds a command to open a variable in a new text document.
*/
export function registerGoDebugCommands(ctx: vscode.ExtensionContext) {
class VariableContentProvider implements vscode.TextDocumentContentProvider {
static uriForRef(ref: VariableRef) {
Expand Down Expand Up @@ -85,18 +90,27 @@ export function registerGoDebugCommands(ctx: vscode.ExtensionContext) {
})
);

/**
* A reference to a variable, used to pass data between commands.
*/
interface VariableRef {
sessionId: string;
container: Container;
variable: Variable;
}

/**
* A container for variables, used to pass data between commands.
*/
interface Container {
name: string;
variablesReference: number;
expensive: boolean;
}

/**
* A variable, used to pass data between commands.
*/
interface Variable {
name: string;
value: string;
Expand All @@ -111,6 +125,9 @@ export function registerGoDebugCommands(ctx: vscode.ExtensionContext) {
t: '\t'
};

/**
* Parses a variable value, unescaping special characters.
*/
function parseVariable(variable: Variable) {
let raw = variable.value.trim();
try {
Expand Down