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

Golang debug test at cursor via hotkey ctrl-k ctrl-c not working #3678

Open
nixomose opened this issue Feb 8, 2025 · 9 comments
Open

Golang debug test at cursor via hotkey ctrl-k ctrl-c not working #3678

nixomose opened this issue Feb 8, 2025 · 9 comments
Labels
Go Companion Issues relating to the Go Companion extension go-test issues related to go test support (test output, test explorer, ...) HelpWanted Issues that are not prioritized by the maintainers. Help is requested from community contributors. NeedsFix The path to resolution is known, but the work has not been done.

Comments

@nixomose
Copy link

nixomose commented Feb 8, 2025

Type: Bug

In go I have a test file with lots of tests, usually I hit ctrl-k ctrl-c to debug the test at the cursor location.
Used to work great, I upgraded vscode recently and now it says

The Go test explorer does not support debugging multiple tests

If I run it from the right-click menu it works most of the time, sometimes not, and if I click the "debug test" at the top of the function it works all the time, but the hotkey always fails.
Hotkey as you might guess is most useful.

Extension version: 0.44.0
VS Code version: Code 1.97.0 (33fc5a94a3f99ebe7087e8fe79fbe1d37a251016, 2025-02-04T22:41:26.688Z)
OS version: Linux x64 6.8.0-52-generic
Modes:

System Info
Item Value
CPUs AMD Ryzen 7 5700G with Radeon Graphics (16 x 4478)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
webnn: disabled_off
Load (avg) 2, 4, 4
Memory (System) 121.74GB (82.82GB free)
Process Argv --unity-launch --crash-reporter-id d3806a5c-5455-4feb-9200-3168db5f4747
Screen Reader no
VM 0%
DESKTOP_SESSION xubuntu
XDG_CURRENT_DESKTOP XFCE
XDG_SESSION_DESKTOP xubuntu
XDG_SESSION_TYPE x11
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt551cf:31179979
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
h48ei257:31000450
pythontbext0:30879054
cppperfnew:31000557
dwnewjupytercf:31046870
nativerepl2:31139839
pythonrstrctxt:31112756
nativeloc1:31192215
iacca1:31171482
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624
hdaa2157:31222309
copilot_t_ci:31222730
jda6j935:31233686

@gopherbot gopherbot added this to the Untriaged milestone Feb 8, 2025
@h9jiang
Copy link
Member

h9jiang commented Feb 13, 2025

Hi nixomose

Thanks for reporting this. I was not able to reproduce the issue in my Mac, here are a few questions I'm hoping that may get us more clarification:

  • When right clicking in a go test, there are two Debug test at cursor, are you using the one in the bottom or the one with Go: Debug test at cursor. And the The ctrl k + ctrlc is not mapped to anything in my current setup, my default is ctrl ; + ctrl c.
Image
  • How many test do you have in your test file? Could you re-produce this with smaller test set? Like 20? (I'm hoping to reproduce the issue from my side) Do you think the issue is test count, or line of code relevant?

  • Could you share any go related settings in your User Setting JSON? Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

  • What was the vscode-go version before you upgrade to v0.44.0? I can try locate the diff to see what have changed relevant to test debug.

Thank you.

@h9jiang h9jiang added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 13, 2025
@nixomose
Copy link
Author

Sorry, I mistyped, it is ctrl-; + ctrl-c like you said, not ctrl-k that was my mistake.

for reference:

This one "debug test"

Image
works all the time

this one:

Image

works some of the time, I notice, if it says "Ctrl-; Ctrl-C" after the "Debug test at cursor" then it won't work.
But if the "Ctrl-; Ctrl-C" is absent, it will work.

This one:
Image
I hadn't noticed until you mentioned it, seems to work all the time.

As for how many tests, it doesn't matter. I have a *_test.go file with one test in it and it still yields the same error:
"The Go test explorer does not support debugging multiple tests"

The problem must be related to this:

Image
There are no tests running, but something thinks there is.

Sorry, I can't tell you much about the vscode-go version. I just upgrade vscode itself usually when it tells me there's a new version. I have no idea when the plugins update.

as for settings, not much:

"go.testFlags": [
"-v"
],
"go.buildFlags": [
"-v"
],
"go.testEnvVars": {
"LOG_LEVEL": "debug",
"GITHUB_ACTIONS": "false",
"CLOUD_TEST_POSTGRES_HOST": "work",
"CLOUD_TEST_POSTGRES_USER": "testuser",
"CLOUD_TEST_POSTGRES_PASS": "postgres"
// "GODEBUG": "gctrace=1"
},
"go.formatTool": "gofumpt",
"go.testEnvFile": "/test.env",
"go.toolsManagement.autoUpdate": true,

there's a whole go.* pile of settings in defaultSettings.json I assume you don't need those?

Thanks for trying to help fix this.
I'm sure it has something to do with the ghost test that's not running but something thinks it is...

@davidmichaelkarr
Copy link

I see the same symptoms, and I'll try to answer the same questions.

I am on Windows, using v1.97.2 of vscode, with v0.44.0 of vscode-go (just go to the extensions tab and hover on the "Go" extension to find this).

All of the keyboard shortcuts for debugging tests appear to get that error dialog, including some not in the context menu.

My context menu has some of these functions, not all of them, but some of them are slightly duplicated:

Image

For instance, "Debug Test and Cursor" is in the menu twice, one with a key binding next to it and the other not. If I select the one without the key binding, it works fine. If I select the one with the key binding, it gets that error dialog.

My test file only has two tests in it, although one of them is a table-based test. I see the same behavior with both tests.

The only reference setting beginning with "go" is:
"go.toolsManagement.autoUpdate": true,

As I only just discovered the existence of these features, I never saw it working before, so the previous version of vscode-go is sort of irrelevant.

@leandrosa
Copy link

I'm facing this same error. I'm using Ubuntu 22.04.5 LTS and vscode version: 1.97.2; x64; e54c774e0add60467559eb0d1e229c6452cf8447.
When I try to run the tests using the command palette Test: Debug Test at Cursor the message The Go test explorer does not support debugging multiple tests is shown, but when I use the command palette Go: Debug Test at Cursor it works well.

Image

Image

@firelizzard18
Copy link
Contributor

Go: Debug Test At Cursor and Test: Debug Test At Cursor are not the same.

The Go: command is provided by this extension (vscode-go) and executes via vscode-go's legacy test support. The Test: command is provided by the IDE (vscode) and executes via the Testing API, which calls vscode-go's test explorer, which is a completely separate component from the legacy test support.

Go test explorer does not support debugging multiple tests

This error is a limitation of vscode-go's test explorer. The Test: command uses the Testing API to tell the test explorer, "Run these tests" (these are Testing API 'test items'). But the test explorer isn't smart enough to handle that unless "these tests" is a single test. Which leads to the question, "Why isn't it a single test?" I don't know and unfortunately that is part of the IDE and thus out of our control. There are two workarounds:

  • Use Go: Debug Test At Cursor instead; or
  • Use the new/experimental test explorer:
    1. Switch to the prerelease version of vscode-go
    2. Install Go Companion.

If you're willing, I recommend switching to vscode-go prerelease + Go Companion. Go Companion is a prerelease version of a new test explorer implementation we're testing out. Work on the old test explorer (the one that's currently part of vscode-go) has been halted so the "can't debug multiple tests" problem is unlikely to be fixed unless someone volunteers.

When you see "The Go test explorer does not support debugging multiple tests", that's definitely caused by what I described above. If you run Go: Debug Test At Cursor, it should always work. Debug Test at Cursor [Ctrl+; Ctrl+C] in the right click menu is probably the Test: command. I don't know why that would work sometimes (when it passes a single test item to the explorer) and not others (when it passes multiple test items to the explorer); that code is not part of vscode-go.

@firelizzard18 firelizzard18 added HelpWanted Issues that are not prioritized by the maintainers. Help is requested from community contributors. NeedsFix The path to resolution is known, but the work has not been done. go-test issues related to go test support (test output, test explorer, ...) Go Companion Issues relating to the Go Companion extension and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Feb 17, 2025
@firelizzard18
Copy link
Contributor

This issue can be resolved either by:

  1. Merging new test explorer from Go Companion into vscode-go (no ETA yet); or
  2. Someone fixing the old test explorer (unplanned).

Fixing the old test explorer could be done one of two ways:

  1. Detect when the TestRunRequest can be reduced to a single test that needs to be run (i.e. the user isn't actually trying to debug multiple tests); or
  2. Actually support debugging multiple tests at a time (though debugging tests from different packages is probably not feasible).

If someone wants to take a stab at it, here's the relevant code:

async debug(request: TestRunRequest, token?: CancellationToken) {
if (!request.include) {
await vscode.window.showErrorMessage('The Go test explorer does not support debugging multiple tests');
return;
}
const collected = new Map<TestItem, CollectedTest[]>();
const files = new Set<TestItem>();
for (const item of request.include) {
await this.collectTests(item, true, request.exclude || [], collected, files);
}
const tests = Array.from(collected.values()).reduce((a, b) => a.concat(b), []);
if (tests.length > 1) {
await vscode.window.showErrorMessage('The Go test explorer does not support debugging multiple tests');
return;
}

@nixomose
Copy link
Author

okay so the simple workaround for now is to bind ctrl-; ctrl-c to the "Go: debug test at cursor" option? Seems to solve the problem.

@firelizzard18
Copy link
Contributor

Correct, that is the simplest workaround

@nixomose
Copy link
Author

Correct, that is the simplest workaround

thanks for confirming, works fine, I just didn't notice those options were there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Go Companion Issues relating to the Go Companion extension go-test issues related to go test support (test output, test explorer, ...) HelpWanted Issues that are not prioritized by the maintainers. Help is requested from community contributors. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants