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
Change-Id: I0320cb52652e96bb7804ccfac66ddecc09593e3f
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/718200
Auto-Submit: Hongxiang Jiang <hxjiang@golang.org>
Reviewed-by: Madeline Kalil <mkalil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ae37c81..6319dd2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
@@ -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 codelens' 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..69ccb2a 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 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.
*
* @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);