extension/src: change sub test input paramter from slice type to type
The vscode.executeCommand api accepts a slice of any as input
parameters. But vscode will flatten the slice into individual
arguments before actually calling the receiver.
E.g. a command with arg ["foo", 0, true] should have a corresponding
command signature of func(string, number, boolean).
Fix golang/vscode-go#3908
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ae37c81..3eb4108 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -75,6 +75,9 @@
* Resolved a problem where `staticcheck` was being installed automatically even
when it was not in use (golang/vscode-go#3898).
+* Fix issue where sub test codelens runs sub test based on the cursor instead of
+the codelen's position (golang/vscode-go#3908).
+
## v0.51.1 (prerelease)
Date: 2025-10-27
diff --git a/extension/src/goTest.ts b/extension/src/goTest.ts
index 22c972e..4d65db4 100644
--- a/extension/src/goTest.ts
+++ b/extension/src/goTest.ts
@@ -181,7 +181,7 @@
* @param args
*/
export function testAtCursor(cmd: TestAtCursorCmd): CommandFactory {
- return (ctx, goCtx) => (args: any) => {
+ return (_, goCtx) => (args: any) => {
const goConfig = getGoConfig();
return _testAtCursor(goCtx, goConfig, cmd, args).catch((err) => {
if (err instanceof NotFoundError) {
@@ -261,7 +261,10 @@
}
/**
- * Executes the sub unit test at the primary cursor.
+ * Executes the sub unit.
+ *
+ * If the `args` is provided, run the subtest based on the test info provided in
+ * the args. Otherwise, infer the test info from the cursor.
*
* @param cmd Whether the command is test or debug.
*/
@@ -273,10 +276,10 @@
* codelens provided by {@link GoRunTestCodeLensProvider}, args
* specifies the function and subtest names.
*/
- args?: [SubTestAtCursorArgs]
+ args?: SubTestAtCursorArgs
) => {
try {
- return await _subTestAtCursor(goCtx, getGoConfig(), cmd, args?.[0]);
+ return await _subTestAtCursor(goCtx, getGoConfig(), cmd, args);
} catch (err) {
if (err instanceof NotFoundError) {
vscode.window.showInformationMessage(err.message);
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
the codelen's position (golang/vscode-go#3908). nit: delete whitespace
"instead of the codelens' position"
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
extension/src: change sub test input paramter from slice type to type```suggestion
extension/src: change sub test input parameter from slice type to type
```
return await _subTestAtCursor(goCtx, getGoConfig(), cmd, args);I made this change specifically to fix a bug (CL 657395, golang/vscode-go#3718). I tested it then so I guess something changed? I just launched the debugger and `args` is in fact an object not an array. And the code lens code hasn't changed in 3 years. I guess vscode changed...
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
| Commit-Queue | +1 |
extension/src: change sub test input paramter from slice type to type```suggestion
extension/src: change sub test input parameter from slice type to type
```
Done
nit: delete whitespace
"instead of the codelens' position"
Done
* Executes the sub unit.Hongxiang Jiangsub unit test?
Done
return await _subTestAtCursor(goCtx, getGoConfig(), cmd, args);I made this change specifically to fix a bug (CL 657395, golang/vscode-go#3718). I tested it then so I guess something changed? I just launched the debugger and `args` is in fact an object not an array. And the code lens code hasn't changed in 3 years. I guess vscode changed...
I'm not sure whether VSCode have changed since. I did bump the vscode api a few times recently. It could be the api bump or vscode change or it was never working correctly.
Lesson learned, vscode is calling our commands with flattened arguments.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
2 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: CHANGELOG.md
Insertions: 2, Deletions: 2.
@@ -15,7 +15,7 @@
minimum Go version remains Go 1.23. A new notification will now be sent to help
users running older versions upgrade to Go 1.23+.
-### Changse
+### Changes
* **Tool Management Refactoring**: The extension now correctly uses the tools
specified in the `"go.lintTool"` and `"go.formatTool"` settings.
@@ -76,7 +76,7 @@
when it was not in use (golang/vscode-go#3898).
* Fix issue where sub test codelens runs sub test based on the cursor instead of
-the codelen's position (golang/vscode-go#3908).
+the codelens' position (golang/vscode-go#3908).
## v0.51.1 (prerelease)
```
```
The name of the file: extension/src/goTest.ts
Insertions: 1, Deletions: 1.
@@ -261,7 +261,7 @@
}
/**
- * Executes the sub unit.
+ * Executes the sub unit test.
*
* If the `args` is provided, run the subtest based on the test info provided in
* the args. Otherwise, infer the test info from the cursor.
```
extension/src: change sub test input parameter from slice type to type
The vscode.executeCommand api accepts a slice of any as input
parameters. But vscode will expand the slice into individual
arguments before actually calling the receiver.
E.g. a command with arg ["foo", 0, true] of type []any should have a
corresponding command signature of func(string, number, boolean).
a command with arg ["foo"] of type []any should have a corresponding
command signature of func(string).
Fix golang/vscode-go#3908
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |