Suzy Mueller submitted this change.
package.json: allow updating hideSystemGoroutines from stack context
Add a command to the callstack context menu that allows users to
toggle between hiding and showing system goroutines. This allows
for easier discovery of the feature.
For golang/vscode-go#1797
Change-Id: I7f085d5e7d50ec3f3ae2a9d515c99b2e935c5d3a
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/534955
Commit-Queue: Suzy Mueller <suz...@golang.org>
TryBot-Result: kokoro <noreply...@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hya...@gmail.com>
---
M docs/commands.md
M package.json
M src/goDebugFactory.ts
M src/goMain.ts
M test/integration/goDebug.test.ts
5 files changed, 109 insertions(+), 2 deletions(-)
diff --git a/docs/commands.md b/docs/commands.md
index 372613a..d071081 100644
--- a/docs/commands.md
+++ b/docs/commands.md
@@ -67,6 +67,10 @@
Runs all unit tests in the package of the current file.
+### `Go: Toggle Hide System Goroutines`
+
+Toggles hiding the system goroutines from the active debug session call stack view.
+
### `Go Test: Refresh`
Refresh a test in the test explorer. Only available as a context menu option in the test explorer.
diff --git a/package.json b/package.json
index 3c9c05c..6a3433b 100644
--- a/package.json
+++ b/package.json
@@ -270,6 +270,11 @@
"description": "Runs all unit tests in the package of the current file."
},
{
+ "command": "go.debug.toggleHideSystemGoroutines",
+ "title": "Go: Toggle Hide System Goroutines",
+ "description": "Toggles hiding the system goroutines from the active debug session call stack view."
+ },
+ {
"command": "go.test.refresh",
"title": "Go Test: Refresh",
"description": "Refresh a test in the test explorer. Only available as a context menu option in the test explorer.",
@@ -2760,6 +2765,12 @@
"when": "false"
}
],
+ "debug/callstack/context": [
+ {
+ "command": "go.debug.toggleHideSystemGoroutines",
+ "when": "debugType == 'go' && callStackItemType == 'stackFrame' || (callStackItemType == 'thread' && callStackItemStopped)"
+ }
+ ],
"editor/context": [
{
"when": "editorTextFocus && config.go.editorContextMenuCommands.toggleTestFile && resourceLangId == go",
diff --git a/src/goDebugFactory.ts b/src/goDebugFactory.ts
index b216290..e57169e 100644
--- a/src/goDebugFactory.ts
+++ b/src/goDebugFactory.ts
@@ -16,8 +16,10 @@
import { DebugProtocol } from 'vscode-debugprotocol';
import { getWorkspaceFolderPath } from './util';
import { getEnvPath, getBinPathFromEnvVar } from './utils/pathUtils';
+import { GoExtensionContext } from './context';
+import { createRegisterCommand } from './commands';
-export function activate(ctx: vscode.ExtensionContext) {
+export function activate(ctx: vscode.ExtensionContext, goCtx: GoExtensionContext) {
const debugOutputChannel = vscode.window.createOutputChannel('Go Debug');
ctx.subscriptions.push(debugOutputChannel);
@@ -32,6 +34,9 @@
if ('dispose' in tracker) {
ctx.subscriptions.push(tracker);
}
+
+ const registerCommand = createRegisterCommand(ctx, goCtx);
+ registerCommand('go.debug.toggleHideSystemGoroutines', () => toggleHideSystemGoroutines);
}
class GoDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescriptorFactory {
@@ -658,3 +663,41 @@
}
return { dlvArgs, dlvPath, dir, env };
}
+
+// toggleHideSystemGoroutineCustomRequest is a helper function extracted
+// for testing the command.
+export async function toggleHideSystemGoroutinesCustomRequest(
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ cr: (command: string, args?: any) => Thenable<any>
+) {
+ const debugConsole = vscode.debug.activeDebugConsole;
+ try {
+ const response = await cr('evaluate', {
+ expression: 'dlv config -list hideSystemGoroutines',
+ context: 'context'
+ });
+ let update = 'false';
+ if (response?.result?.indexOf('false') >= 0) {
+ update = 'true';
+ }
+ await cr('evaluate', {
+ expression: `dlv config hideSystemGoroutines ${update}`,
+ context: 'context'
+ });
+ } catch (err) {
+ if (err instanceof Error && err.message.indexOf('debuggee is running') >= 0) {
+ debugConsole.appendLine('Cannot toggle hideSystemGoroutines while debuggee is running');
+ return;
+ }
+ debugConsole.appendLine(`Error toggling hideSystemGoroutines: ${err}`);
+ }
+}
+
+const toggleHideSystemGoroutines = () => {
+ const ds = vscode.debug.activeDebugSession;
+ if (ds) {
+ toggleHideSystemGoroutinesCustomRequest((command, args) => {
+ return ds.customRequest(command, args);
+ });
+ }
+};
diff --git a/src/goMain.ts b/src/goMain.ts
index 9ea4e5f..cad4893 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -123,7 +123,7 @@
GoRunTestCodeLensProvider.activate(ctx, goCtx);
GoDebugConfigurationProvider.activate(ctx, goCtx);
- GoDebugFactory.activate(ctx);
+ GoDebugFactory.activate(ctx, goCtx);
goCtx.buildDiagnosticCollection = vscode.languages.createDiagnosticCollection('go');
ctx.subscriptions.push(goCtx.buildDiagnosticCollection);
diff --git a/test/integration/goDebug.test.ts b/test/integration/goDebug.test.ts
index 03009d6..dc1df0a 100644
--- a/test/integration/goDebug.test.ts
+++ b/test/integration/goDebug.test.ts
@@ -2251,6 +2251,55 @@
});
});
+ suite('hideSystemGoroutines', () => {
+ if (!isDlvDap) {
+ return;
+ }
+ test('should toggle hiding system goroutines', async () => {
+ const PROGRAM = path.join(DATA_ROOT, 'baseTest');
+
+ const FILE = path.join(DATA_ROOT, 'baseTest', 'test.go');
+ const BREAKPOINT_LINE = 11;
+
+ const config = {
+ name: 'Launch',
+ type: 'go',
+ request: 'launch',
+ mode: 'debug',
+ program: PROGRAM,
+ hideSystemGoroutines: false
+ };
+ const debugConfig = await initializeDebugConfig(config);
+ await dc.hitBreakpoint(debugConfig, getBreakpointLocation(FILE, BREAKPOINT_LINE));
+ let threadsResponse = await dc.threadsRequest();
+ assert.ok(threadsResponse.success);
+ assert.ok(threadsResponse.body.threads.length > 1);
+
+ const toggle = () =>
+ Promise.all([
+ proxy.toggleHideSystemGoroutinesCustomRequest(async (command: string, args?: any) => {
+ return dc.customRequest(command, args).then((rsp) => {
+ return rsp.body;
+ });
+ }),
+ dc.waitForEvent('invalidated').then((event) => {
+ assert.strictEqual(event.body.areas.length, 1);
+ assert.strictEqual(event.body.areas[0], 'threads');
+ })
+ ]);
+ // Toggle so only the main goroutine is shown.
+ await toggle();
+ threadsResponse = await dc.threadsRequest();
+ assert.ok(threadsResponse.success);
+ assert.strictEqual(threadsResponse.body.threads.length, 1);
+ // Toggle so all goroutines are shown again.
+ await toggle();
+ threadsResponse = await dc.threadsRequest();
+ assert.ok(threadsResponse.success);
+ assert.ok(threadsResponse.body.threads.length > 1);
+ });
+ });
+
let testNumber = 0;
async function initializeDebugConfig(config: DebugConfiguration, keepUserLogSettings?: boolean) {
// be explicit and prevent resolveDebugConfiguration from picking
To view, visit change 534955. To unsubscribe, or for help writing mail filters, visit settings.