Skip to content

Commit

Permalink
src/goTest: do not set range for dynamic subtests
Browse files Browse the repository at this point in the history
By default, no longer sets the range property of dynamically discovered
subtests. As a result, 'Go to Test' for a dynamic subtest will open
relevant file but will not scroll to the function; and no play button
will appear in the gutter for the subtest. Adds a setting to revert to
the previous behavior.

Since the previous behavior was to copy the range from the parent test,
all such subtests would have the exact same range as the parent test,
and thus the gutter play button would attempt to run the parent test and
all of its subtests, requiring the user to right click the play button
and manually select the parent test to avoid this.

Change-Id: I7b95995206045b215a60d34afc00cbb6ad36ccd0
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/345869
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
Trust: Hyang-Ah Hana Kim <[email protected]>
Trust: Robert Findley <[email protected]>
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
TryBot-Result: kokoro <[email protected]>
  • Loading branch information
firelizzard18 authored and hyangah committed Sep 3, 2021
1 parent 1c36262 commit 9021bff
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ Default: `"flat"`

Include benchmarks when running all tests in a group.

Default: `false`
### `go.testExplorerSetDynamicSubtestRange`

If true, the source location of dynamically discovered subtests will be set to the source location of the containing function

Default: `false`
### `go.testFlags`

Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,12 @@
"description": "If true, test log messages associated with a given location will be shown as a single message.",
"scope": "resource"
},
"go.testExplorerSetDynamicSubtestRange": {
"type": "boolean",
"default": false,
"description": "If true, the source location of dynamically discovered subtests will be set to the source location of the containing function",
"scope": "resource"
},
"go.generateTestsFlags": {
"type": "array",
"items": {
Expand Down
18 changes: 16 additions & 2 deletions src/goTest/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,14 @@ export class GoTestResolver {
item.canResolveChildren = true;
const sub = this.createItem(name, item.uri, kind, `${parentName}/${name}`);
item.children.add(sub);
sub.range = item.range;
if (dynamic) this.isDynamicSubtest.add(item);

if (dynamic) {
this.isDynamicSubtest.add(sub);
if (this.shouldSetRange(item)) {
sub.range = item.range;
}
}

return sub;
}

Expand Down Expand Up @@ -192,6 +198,11 @@ export class GoTestResolver {

/* ***** Private ***** */

private shouldSetRange(item: TestItem): boolean {
const config = getGoConfig(item.uri);
return config.get<boolean>('testExplorerSetDynamicSubtestRange');
}

// Create an item.
private createItem(label: string, uri: Uri, kind: GoTestKind, name?: string): TestItem {
return this.ctrl.createTestItem(GoTest.id(uri, kind, name), label, uri.with({ query: '', fragment: '' }));
Expand Down Expand Up @@ -222,6 +233,9 @@ export class GoTestResolver {
// location.
private relocateChildren(item: TestItem) {
item.children.forEach((child) => {
if (!this.isDynamicSubtest.has(child)) return;
if (!this.shouldSetRange(child)) return;

child.range = item.range;
this.relocateChildren(child);
});
Expand Down

0 comments on commit 9021bff

Please sign in to comment.