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

src/goTestExplorer: implement a test provider for the new test api #1590

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
29b89e0
src/goModules: correctly handle gopath mode
firelizzard18 Jun 25, 2021
1fa5e10
package.json: prepare for test api
firelizzard18 Jun 25, 2021
8b83fcc
src/goTestExplorer: implement test api
firelizzard18 Jun 25, 2021
4dbce41
src/goTestExplorer: handle workspaces correctly
firelizzard18 Jun 25, 2021
80bf7b3
src/goTestExplorer: run tests
firelizzard18 Jun 25, 2021
7b637aa
src/goTestExplorer: cleanup imports
firelizzard18 Jun 25, 2021
300e5e6
src/goTestExplorer: improve test status granularity
firelizzard18 Jun 25, 2021
c3b37e5
src/goTestExplorer: improve reporting
firelizzard18 Jun 25, 2021
0c35f08
src/goModules,src/goTestExplorer: lint
firelizzard18 Jun 26, 2021
0c79b0a
src/goTestExplorer: explain benchmark output
firelizzard18 Jul 8, 2021
075fea0
src/goTestExplorer: improve readability
firelizzard18 Jul 9, 2021
a846bc9
src/goTestExplorer: add tests
firelizzard18 Jul 9, 2021
04a1899
src/goTestExplorer: add tests for workspace events
firelizzard18 Jul 9, 2021
27bd88f
src/goTestExplorer: handle document updates
firelizzard18 Jul 16, 2021
29f9eb8
src/goTestExplorer: default to not run benchmarks
firelizzard18 Jul 16, 2021
9bb5fcc
src/goTestExplorer: configure flat/nested packages
firelizzard18 Jul 16, 2021
b34fe49
src/goTestExplorer: diff for examples
firelizzard18 Jul 16, 2021
f59453d
src/goTestExplorer: handle build failures
firelizzard18 Jul 16, 2021
1a7266c
src/goTestExplorer: update VSCode api
firelizzard18 Jul 16, 2021
aab8505
src/goTestExplorer: improve test output handling
firelizzard18 Jul 21, 2021
15d1d2e
src/goTestExplorer: update to final API
firelizzard18 Jul 22, 2021
43f273c
src/goTestExplorer: deal with benchmarks
firelizzard18 Jul 23, 2021
c8258d2
src/goTestExplorer: polish
firelizzard18 Jul 23, 2021
42b6214
src/goTestExplorer: cancel tests
firelizzard18 Jul 24, 2021
e225b49
Update to VSCode 1.59
firelizzard18 Aug 8, 2021
b4f6885
src/goTestExplorer: fix run all tests
firelizzard18 Aug 8, 2021
f6c1077
src/goTestExplorer: cleanup
firelizzard18 Aug 8, 2021
1633f67
src/goTestExplorer: fixes
firelizzard18 Aug 9, 2021
5b058a2
src/goTestExplorer: address review comments
firelizzard18 Aug 11, 2021
9ad01bf
src/goTestExplorer: address comments
firelizzard18 Aug 12, 2021
5e41e65
src/goTestExplorer: support VSCode 1.58
firelizzard18 Aug 13, 2021
bf637ce
package.json: add Testing category
firelizzard18 Aug 13, 2021
4da995c
docs: update commands and settings
firelizzard18 Aug 13, 2021
59af29b
src/goTestExplorer: back to 1.59
firelizzard18 Aug 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ Runs all unit tests in the current file.

Runs all unit tests in the package of the current file.

### `Go Test: Refresh`

Refresh a test in the test explorer. Only available as a context menu option in the test explorer.

### `Go: Benchmark Package`

Runs all benchmarks in the package of the current file.
Expand Down
16 changes: 16 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,22 @@ Absolute path to a file containing environment variables definitions. File conte
### `go.testEnvVars`

Environment variables that will be passed to the process that runs the Go tests
### `go.testExplorerConcatenateMessages`

If true, test log messages associated with a given location will be shown as a single message.

Default: `true`
### `go.testExplorerPackages`

Control whether packages in the test explorer are presented flat or nested.<br/>
Allowed Options: `flat`, `nested`

Default: `"flat"`
### `go.testExplorerRunBenchmarks`

Include benchmarks when running all tests in a group.

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

Flags to pass to `go test`. If null, then buildFlags will be used. This is not propagated to the language server.
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 45 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"Snippets",
"Linters",
"Debuggers",
"Formatters"
"Formatters",
"Testing"
],
"galleryBanner": {
"color": "#F2F2F2",
Expand Down Expand Up @@ -70,7 +71,7 @@
"@types/node": "^13.11.1",
"@types/semver": "^7.1.0",
"@types/sinon": "^9.0.0",
"@types/vscode": "^1.52.0",
"@types/vscode": "^1.59.0",
"adm-zip": "^0.4.14",
"fs-extra": "^9.0.0",
"get-port": "^5.1.1",
Expand Down Expand Up @@ -232,6 +233,13 @@
"title": "Go: Test Package",
"description": "Runs all unit tests in the package of the current file."
},
{
"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.",
"category": "Test",
"icon": "$(refresh)"
},
{
"command": "go.benchmark.package",
"title": "Go: Benchmark Package",
Expand Down Expand Up @@ -1282,6 +1290,28 @@
"description": "Flags to pass to `go test`. If null, then buildFlags will be used. This is not propagated to the language server.",
"scope": "resource"
},
"go.testExplorerPackages": {
"type": "string",
"enum": [
"flat",
"nested"
],
"default": "flat",
"description": "Control whether packages in the test explorer are presented flat or nested.",
"scope": "resource"
},
"go.testExplorerRunBenchmarks": {
"type": "boolean",
"default": false,
"description": "Include benchmarks when running all tests in a group.",
"scope": "resource"
},
"go.testExplorerConcatenateMessages": {
"type": "boolean",
"default": true,
"description": "If true, test log messages associated with a given location will be shown as a single message.",
"scope": "resource"
},
"go.generateTestsFlags": {
"type": "array",
"items": {
Expand Down Expand Up @@ -2356,6 +2386,12 @@
}
},
"menus": {
"commandPalette": [
{
"command": "go.test.refresh",
"when": "false"
}
],
"editor/context": [
{
"when": "editorTextFocus && config.go.editorContextMenuCommands.toggleTestFile && resourceLangId == go",
Expand Down Expand Up @@ -2437,6 +2473,13 @@
"command": "go.show.commands",
"group": "Go group 2"
}
],
"testing/item/context": [
{
"command": "go.test.refresh",
"when": "testId =~ /_test\\.go/",
"group": "inline"
}
]
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,9 @@ export async function buildLanguageClient(cfg: BuildLanguageClientOption): Promi
// cause to reorder candiates, which is not ideal.
// Force to use non-empty `label`.
// https://github.com/golang/vscode-go/issues/441
hardcodedFilterText = items[0].label;
let { label } = items[0];
if (typeof label !== 'string') label = label.label;
hardcodedFilterText = label;
}
for (const item of items) {
item.filterText = hardcodedFilterText;
Expand Down
11 changes: 11 additions & 0 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import { getFormatTool } from './goFormat';
import { resetSurveyConfig, showSurveyConfig, timeMinute } from './goSurvey';
import { ExtensionAPI } from './export';
import extensionAPI from './extensionAPI';
import { isVscodeTestingAPIAvailable, TestExplorer } from './goTestExplorer';

export let buildDiagnosticCollection: vscode.DiagnosticCollection;
export let lintDiagnosticCollection: vscode.DiagnosticCollection;
Expand Down Expand Up @@ -335,6 +336,16 @@ If you would like additional configuration for diagnostics from gopls, please se
})
);

if (isVscodeTestingAPIAvailable) {
const testExplorer = TestExplorer.setup(ctx);

ctx.subscriptions.push(
vscode.commands.registerCommand('go.test.refresh', (args) => {
if (args) testExplorer.resolve(args);
})
);
}

ctx.subscriptions.push(
vscode.commands.registerCommand('go.subtest.cursor', (args) => {
const goConfig = getGoConfig();
Expand Down
3 changes: 2 additions & 1 deletion src/goModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ async function runGoModEnv(folderPath: string): Promise<string> {
return resolve('');
}
const [goMod] = stdout.split('\n');
resolve(goMod);
if (goMod === '/dev/null' || goMod === 'NUL') resolve('');
else resolve(goMod);
});
});
}
Expand Down
9 changes: 7 additions & 2 deletions src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,14 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider,
return;
}

let { label } = item;
if (typeof label !== 'string') label = label.label;

return runGodoc(
path.dirname(item.fileName),
item.package || path.dirname(item.fileName),
item.receiver,
item.label,
label,
token
)
.then((doc) => {
Expand Down Expand Up @@ -358,7 +361,9 @@ export class GoCompletionItemProvider implements vscode.CompletionItemProvider,
areCompletionsForPackageSymbols = true;
}
if (suggest.class === 'package') {
const possiblePackageImportPaths = this.getPackageImportPath(item.label);
let { label } = item;
if (typeof label !== 'string') label = label.label;
const possiblePackageImportPaths = this.getPackageImportPath(label);
if (possiblePackageImportPaths.length === 1) {
item.detail = possiblePackageImportPaths[0];
}
Expand Down
Loading