Skip to content

Commit b3751f4

Browse files
committed
[release] docs: rewrite debugging.md, testing.md, smoke-test.md, etc.
Rewrote a number of documents. Notable changes: - Cleaned up and updated the debugging documentation. Some more work still needs to be done, but I think it's in pretty good shape. - Move build/README.md to docs/testing.md. I think it fits better with the other docs, and I expect most of the build directory will be going away soon? Hana, let me know what you think because I can also move it back. - Separated settings.md from commands.md. Ran out of steam when trying to finish commands.md, but I'll try to work on it more next. Haven't updated all of the incorrect references to commands.md yet, but that's for the next CL. - Updated and cleaned up the smoke test. Not sure if we'll ever use it, but it's not a bad thing to have, and I caught a gopls bug with it. Change-Id: Ie9ed8187a0597d36f5960d77fd999d14366bbe74 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/236379 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> (cherry picked from commit 4a34f9b) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/236958
1 parent 8fe064d commit b3751f4

15 files changed

+567
-262
lines changed

build/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# This Docker container is used for testing on GCB.
2+
13
FROM golang:1.14 AS gobuilder
24

35
ENV GO111MODULE on

build/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# See the [testing documentation](../docs/testing.md)

docs/Smoke-Test.md

Lines changed: 82 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,82 @@
1-
**Pre-requisites for testing Go extension if you don't already have Go installed and the extension set up**
2-
3-
1. Install [Go](https://golang.org/doc/install#install)
4-
2. Run `go get github.com/golang/example/hello`
5-
3. Sideload the Go extension and open the folder $HOME/go/src/gitHub.com/golang/example in VS Code
6-
4. Open any Go file. You will see "Analysis Tools Missing" in the status bar. Click on it to install the Go tools that the extension needs.
7-
8-
**Features to Smoke Test:**
9-
10-
Try the below features for functions, structs and interfaces from current/std/third party packages
11-
- Goto and Peek Definition
12-
- Find References
13-
- Hover Info
14-
15-
Try the below for functions in built-in (fmt, strings, math etc) and custom packages (stringutil in the hello project)
16-
- Auto complete
17-
- Auto complete for unimported packages
18-
- Set `go.useCodeSnippetsOnFunctionSuggest` to true and check if code snippets show up for functions
19-
- Signature Help
20-
21-
Enable build, vet, lint and format On Save features, make a change in a go file and save. Try both values "package" and "workspace" for the settings.
22-
- The output channel for Go should show build, vet and linting results
23-
- If there were errors, red squiggle lines should show up in the editor
24-
- Remove comments on an exported member (anything whose name starts with a capital letter), and make sure linter asks you to add the comment
25-
- Add tabs and extra lines, remove an import: formatting should fix all of these
26-
27-
Rename
28-
- Rename a local variable, rename should work, file should go to a dirty state
29-
- Rename an exported function (eg: Reverse in the hello project), rename should work across files, all affected files should open and be in dirty state
30-
31-
Add imports
32-
- The command "Go: Add import" should give a list of packages that can be imported.
33-
- Selecting one of these should add an import to the current go file
34-
- Already imported packages in the current file should not show up in the list
35-
36-
Other features:
37-
- File outline
38-
- Debugging
1+
# Smoke Test
2+
3+
Before releasing a new version of the extension, please run the following smoke test to make sure that all features are working.
4+
5+
## Set up
6+
7+
First, clone the [golang.org/x/example](https://github.com/golang/example). At the time of writing (June 2020), this repository has not changed since 2017. If it has changed since, these steps may not be exactly reproducible and should be adjusted.
8+
9+
<!--TODO(rstambler): Maintain our own smoke tests, or add a go.mod file to this repository.-->
10+
For now, we smoke test the extension only in `GOPATH` mode.
11+
12+
If it does not already exist:
13+
14+
```bash
15+
mkdir $GOPATH/src/github.com/golang
16+
```
17+
18+
Then,
19+
20+
```bash
21+
cd $GOPATH/src/github.com/golang
22+
git clone https://github.com/golang/example
23+
cd example
24+
```
25+
26+
Next, [build and sideload the modified Go extension](contributing.md#sideload) and open the `example/hello` directory. Open `hello.go`.
27+
28+
## Test code navigation
29+
30+
1. Go to definition on `fmt.Println`.
31+
2. Go to definition on `stringutil.Reverse`.
32+
3. Find all references of `fmt.Println`.
33+
4. Find all references of `stringutil.Reverse`.
34+
5. Hover over `fmt.Println`.
35+
6. Hover over `stringutil.Reverse`.
36+
37+
## Test autocompletion
38+
39+
<!--TODO(rstambler): We should require the user install another package in their GOPATH and expect unimported completions from that package.-->
40+
41+
1. Trigger autocompletion (Ctrl+Space) after `fmt.`.
42+
2. Trigger autocompletion (Ctrl+Space) after `stringutil.`.
43+
3. Enter a newline in the `main` function and type `fmt.`.
44+
4. Enter a newline in the `main` function and type `parser.`. Expect suggestions from the unimported standard library `go/parser` package.
45+
5. Enter a newline in the `main` function and type `fmt.`. Select the `fmt.Println` completion and observe the outcome. Toggle the `go.useCodeSnippetsOnFunctionSuggest` setting to ensure that placeholders are provided.
46+
6. Test signature help by manually triggering it (Ctrl+Shift+Space) while completing `fmt.Println`.
47+
7. Test signature help by manually triggering it (Ctrl+Shift+Space) while completing `stringutil.Reverse`.
48+
49+
## Test diagnostics
50+
51+
Enable `go.buildOnSave`, `go.vetOnSave`, and `go.lintOnSave`.
52+
53+
1. Add `var x int` to the `main` function and expect a build diagnostic.
54+
2. Add `fmt.Printf("hi", 1)` and expect a vet diagnostic.
55+
3. Add the following function to the bottom of the file and expect a lint diagnostic.
56+
57+
```go
58+
// Hello is hi.
59+
func Hi() {}
60+
```
61+
62+
You can also try toggling the `"package"` and `"workspace"` configurations for these settings.
63+
64+
## Test formatting and import organization
65+
66+
1. Hit enter 3 times in the `main` function and save. Expect formatting to remove all but one line.
67+
2. Remove the `"fmt"` import. Save and expect it to return.
68+
3. Remove the `"github.com/golang/example/stringutil"` import. Save and expect it to return.
69+
4. Confirm that the `Go: Add Import` command works (add `"archive/tar"`).
70+
71+
## Test renaming
72+
73+
1. Add the following to the `main` function, then rename `x` to `y`.
74+
75+
```go
76+
var x int
77+
fmt.Println(x)
78+
```
79+
80+
2. Rename `stringutil.Reverse`. `reverse.go` and `reverse_test.go` should be dirtied.
81+
82+
<!--TODO(rstambler): Other features should also be tested. Not sure if this whole smoke test process is worth it or will ever be followed.-->

docs/commands.md

Lines changed: 116 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,149 @@
1-
# Settings and Commands
1+
# Commands
22

3-
To view a complete list of the commands and settings for this extension:
3+
In addition to the integrated editing features, this extension offers a number of commands, which can be executed manually through the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) (Ctrl+Shift+P).
4+
5+
Some of these commands are also available in the VS Code context menu (right click). To control which of these commands show up in the editor context menu, update the [`"go.editorContextMenuCommands"`](settings.md#editorContextMenuCommands) setting.
6+
7+
All commands provided by this extension have the prefix "`Go:` ".
8+
9+
## Latest changes
10+
11+
The commands described below are up-to-date as of June 2020. We do our best to keep documentation current, but if a command is missing, you can always consult the full list in the Extensions view.
12+
13+
To view this list:
414

515
1. Navigate to the Extensions view (Ctrl+Shift+X).
6-
2. Find the Go extension, click on it to open the Extension Editor.
16+
2. Find the Go extension and click on it to open the Extension Editor.
717
3. Click on the `Feature Contributions` tab.
8-
4. Scroll away.
18+
4. Scroll through the list under `Commands`.
19+
20+
Finally, you can also see a full list by using a meta command: `Go: Show All Commands...`.
21+
22+
## Detailed list
23+
24+
Below is a detailed list of commands. They are categorized into [code editing and generation](#code-editing-and-generation), [testing and benchmarking](#testing-and-benchmarking), [build, lint, and vet](#build-lint-and-vet), [miscellaneous](#miscellaneous), and [troubleshooting](#troubleshooting). You will find the [troubleshooting](#troubleshooting) commands helpful when diagnosing an issue with the extension (learn more in the [Troubleshooting documentation](troubleshooting.md)).
25+
26+
### Code editing and generation
27+
28+
<!--Note: Try to keep this list in roughly alphabetical/logical order.-->
29+
30+
#### [`Go: Add Import`](features.md#add-import)
31+
32+
<!--TODO(rstambler): Confirm exactly how this works.-->
33+
Manually add an import to your file. See [Add import](features.md#add-import).
34+
35+
#### [`Go: Add Package to Workspace`]()
36+
37+
#### [`Go: Add Tags to Struct Fields`](features.md#add-struct-tags)
38+
39+
Automatically generate [tags](https://pkg.go.dev/reflect?tab=doc#StructTag) for your struct. See [Add or remove struct tags](features.md#add-or-remove-struct-tags).
40+
41+
#### [`Go: Remove Tags From Struct Fields`](features.md#add-struct-tags)
42+
43+
Removes [tags](https://pkg.go.dev/reflect?tab=doc#StructTag) from the selected struct fields. See [Add or remove struct tags](features.md#add-or-remove-struct-tags).
44+
45+
#### [`Go: Fill struct`](features.md#fill-struct-literals)
46+
47+
Fill a struct literal with default values. See [Fill struct](features.md#fill-struct-literals).
48+
49+
#### [`Go: Generate Interface Stubs`](features.md#generate-interface-implementation)
50+
51+
Generate method stubs for given interface. See [Generate interface implementation](features.md#generate-interface-implementation).
52+
53+
#### [`Go: Generate Unit Tests For Function`](features.md#generate-unit-tests)
54+
55+
Generate unit tests for the selected function in the current file. See [Generate unit tests](features.md#generate-unit-tests).
56+
57+
#### [`Go: Generate Unit Tests For File`](features.md#generate-unit-tests)
58+
59+
Generate unit tests for the current file. See [Generate unit tests](features.md#generate-unit-tests).
60+
61+
#### [`Go: Generate Unit Tests For Package`](features.md#generate-unit-tests)
62+
63+
Generate unit tests for the current package. See [Generate unit tests](features.md#generate-unit-tests).
64+
65+
#### [`Go: Extract to function`]()
66+
67+
#### [`Go: Extract to variable`]()
68+
69+
### Testing and benchmarking
70+
71+
#### [`Go: Test Function at Cursor`](features.md#test-and-benchmark-in-the-editor)
72+
73+
Run the test function at the current cursor position in the file.
74+
75+
#### [`Go: Subtest at Cursor`]()
76+
77+
#### [`Go: Benchmark Function At Cursor`]()
78+
79+
#### [`Go: Debug Test At Cursor`]()
80+
81+
#### [`Go: Test File`](features.md#test-and-benchmark-in-the-editor)
82+
83+
Run all of the tests in the current file.
84+
85+
#### [`Go: Benchmark File`]()
86+
87+
#### [`Go: Test Package`](features.md#test-and-benchmark-in-the-editor)
88+
89+
Run all of tests in the current package.
90+
91+
#### [`Go: Benchmark Package`]()
92+
93+
#### [`Go: Test Previous`](features.md#test-and-benchmark-in-the-editor)
994

10-
<!--TODO(rstambler): This image needs to be updated.-->
11-
![ext](https://user-images.githubusercontent.com/16890566/30246497-9d6cc588-95b0-11e7-87dd-4bd1b18b139f.gif)
95+
Re-run the most recently executed test command.
1296

13-
## Settings
97+
#### [`Go: Test All Packages In Workspace`](features.md#test-and-benchmark-in-the-editor)
1498

15-
You can configure your settings by modifying your [User or Workspace Settings](https://code.visualstudio.com/docs/getstarted/settings). To navigate to your settings, open the Command Palette (Ctrl+Shift+P) and search for "settings". The simplest way to modify your settings is through "Preferences: Open Settings (UI)".
99+
Run all of the tests in the current workspace.
16100

17-
**NOTE: Most of these settings don't apply if you are using [`gopls`](gopls.md). Learn more about `gopls`-specific settings in this [documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md).**
101+
#### [`Go: Cancel Running Tests]()
18102

19-
A list of popular and notable settings can be found below.
103+
#### [`Go: Toggle Test File`]()
20104

21-
### docsTool
105+
#### [`Go: Apply Cover Profile]()
22106

23-
One of `"godoc"`, `"gogetdoc"`, or `"guru"` (`gogetdoc` is the default). This is the tool used by the [go to definition](features.md#go-to-definition), [signature help](features.md#signature-help), and [quick info on hover](features.md#quick-info-on-hover) features. See more information about each of these tools in the [Documentation](tools.md#Documentation) section.
107+
#### [`Go: Toggle Test Coverage In Current Package`]()
24108

25-
### formatTool
109+
### Build, lint, and vet
26110

27-
One of `"gofmt"`, `"goimports"`, `"goreturns"`, and `"goformat"` (`goreturns` is the default). This is the tool used by the [formatting and import organization](features.md#formatting-and-import-organization) features. See more information about each of these tools in the [Formatting](tools.md#Formatting) section.
111+
#### [`Go: Build Current Package`]()
28112

29-
### lintTool
113+
#### [`Go: Lint Current Package`]()
30114

31-
One of `"golint"`, `"staticcheck"`, `"golangci-lint"`, and `"revive"` (`golint` is the default). This is the tool used by the [lint-on-save](features.md#lint-on-save) feature. See more information about each of these tools in the [Diagnostics](tools.md#Diagnostics) section.
115+
#### [`Go: Vet Current Package`]()
32116

33-
### lintFlags
117+
#### [`Go: Build Workspace`]()
34118

35-
This setting can be used to pass additional flags to your lint tool of choice.
119+
#### [`Go: Lint Workspace`]()
36120

37-
Most linters can be configured via special configuration files, but you may still need to pass command-line flags. The configuration documentation for each supported linter is listed here:
121+
#### [`Go: Vet Workspace`]()
38122

39-
* [`staticcheck`](https://staticcheck.io/docs/#configuration)
40-
* [`golangci-lint`](https://golangci-lint.run/usage/configuration/)
41-
* [`revive`](https://github.com/mgechev/revive#command-line-flags)
123+
#### [`Go: Install Current Package`]()
42124

43-
#### Examples
125+
### Miscellaneous
44126

45-
Enable all [`golangci-lint`] linters and only show errors in new code:
127+
#### [`Go: Restart Language Server`]()
46128

47-
```json5
48-
"go.lintFlags": ["--enable-all", "--new"]
49-
```
129+
#### [`Go: Run on Go Playground`](features.md#go-playground)
50130

51-
Configure `revive` to exclude `vendor` directories and apply extra configuration with a `config.toml` file:
131+
Upload the current selection or file to the Go Playground ([play.golang.org](https://play.golang.org)). See [Go Playground](features.md#go-playground).
52132

53-
```json5
54-
"go.lintFlags": [
55-
"-exclude=vendor/...",
56-
"-config=${workspaceFolder}/config.toml"
57-
]
58-
```
133+
### Troubleshooting
59134

60-
### Commands
135+
#### `Go: Current GOPATH`
61136

62-
In addition to integrated editing features, the extension also provides several commands in the Command Palette for working with Go files:
137+
See the current value of GOPATH. This is not equivalent to `go env GOPATH`, as your VS Code settings may have altered the value of `GOPATH` used by the extension.
63138

64-
* `Go: Add Import` to add an import from the list of packages in your Go context
65-
* `Go: Current GOPATH` to see your currently configured GOPATH
66-
* `Go: Test at cursor` to run a test at the current cursor position in the active document
67-
* `Go: Test Package` to run all tests in the package containing the active document
68-
* `Go: Test File` to run all tests in the current active document
69-
* `Go: Test Previous` to run the previously run test command
70-
* `Go: Test All Packages in Workspace` to run all tests in the current workspace
71-
* `Go: Generate Unit Tests For Package` Generates unit tests for the current package
72-
* `Go: Generate Unit Tests For File` Generates unit tests for the current file
73-
* `Go: Generate Unit Tests For Function` Generates unit tests for the selected function in the current file
74-
* `Go: Install Tools` Installs/updates all the Go tools that the extension depends on
75-
* `Go: Add Tags` Adds configured tags to selected struct fields.
76-
* `Go: Remove Tags` Removes configured tags from selected struct fields.
77-
* `Go: Generate Interface Stubs` Generates method stubs for given interface
78-
* `Go: Fill Struct` Fills struct literal with default values
79-
* `Go: Run on Go Playground` Upload the current selection or file to the Go Playground
139+
#### [`Go: Install/Update Tools`](tools.md)
80140

81-
You can access all of the above commands from the command palette (`Cmd+Shift+P` or `Ctrl+Shift+P`).
141+
Install or update the Go tools on which the extension depends. Tools can be installed or updated all at once, or individual tools can be selected.
82142

83-
A few of these are available in the editor context menu as an experimental feature as well. To control which of these commands show up in the editor context menu, update the setting `go.editorContextMenuCommands`.
143+
#### [`Go: Locate Configured Go Tools`]()
84144

85145
[`golint`]: https://pkg.go.dev/golang.org/x/lint/golint?tab=overview
86146
[`staticcheck`]: https://pkg.go.dev/honnef.co/go/tools/staticcheck?tab=overview
87147
[`golangci-lint`]: https://golangci-lint.run/
88-
[`revive`]: https://pkg.go.dev/github.com/mgechev/revive?tab=overview
148+
[`revive`]: https://pkg.go.dev/github.com/mgechev/revive?tab=overview
149+
[`gomodifytags`]: tools.md#gomodifytags

docs/contributing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,9 @@ The easiest way to start is by reading this [detailed guide for contributing to
9292
9393
Once you've sent out your change, a maintainer will take a look at your contribution within a few weeks. If you don't hear back in that time, feel free to ping the issue or send a message to the [#vscode-dev] channel of the [Gophers Slack].
9494
95+
## [Continuous Integration](testing.md)
96+
97+
The extension's test suite will run on your change once it has been mailed. If you have contributed via a GitHub pull request (PR), the test results will be provided via a [GitHub Action](testing.md#testing-via-github-actions) result on the PR. If you have mailed a Gerrit changelist (CL) directly, tests will run in [Google Cloud Build](testing.md#testing-via-gcb), and the results will be posted back on the CL. As of June 2020, the GCB and Gerrit integration is not yet ready, so the results of the CI run **will not** appear on the Gerrit changelist. Instead, if your change fails on GCB, your reviewer will notify you and provide you with the relevant logs.
98+
9599
[#vscode-dev]: https://gophers.slack.com/archives/CUWGEKH5Z
96100
[Gophers Slack]: https://invite.slack.golangbridge.org/

0 commit comments

Comments
 (0)