|
1 |
| -# Settings and Commands |
| 1 | +# Commands |
2 | 2 |
|
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: |
4 | 14 |
|
5 | 15 | 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. |
7 | 17 | 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) |
9 | 94 |
|
10 |
| -<!--TODO(rstambler): This image needs to be updated.--> |
11 |
| - |
| 95 | +Re-run the most recently executed test command. |
12 | 96 |
|
13 |
| -## Settings |
| 97 | +#### [`Go: Test All Packages In Workspace`](features.md#test-and-benchmark-in-the-editor) |
14 | 98 |
|
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. |
16 | 100 |
|
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]() |
18 | 102 |
|
19 |
| -A list of popular and notable settings can be found below. |
| 103 | +#### [`Go: Toggle Test File`]() |
20 | 104 |
|
21 |
| -### docsTool |
| 105 | +#### [`Go: Apply Cover Profile]() |
22 | 106 |
|
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`]() |
24 | 108 |
|
25 |
| -### formatTool |
| 109 | +### Build, lint, and vet |
26 | 110 |
|
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`]() |
28 | 112 |
|
29 |
| -### lintTool |
| 113 | +#### [`Go: Lint Current Package`]() |
30 | 114 |
|
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`]() |
32 | 116 |
|
33 |
| -### lintFlags |
| 117 | +#### [`Go: Build Workspace`]() |
34 | 118 |
|
35 |
| -This setting can be used to pass additional flags to your lint tool of choice. |
| 119 | +#### [`Go: Lint Workspace`]() |
36 | 120 |
|
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`]() |
38 | 122 |
|
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`]() |
42 | 124 |
|
43 |
| -#### Examples |
| 125 | +### Miscellaneous |
44 | 126 |
|
45 |
| -Enable all [`golangci-lint`] linters and only show errors in new code: |
| 127 | +#### [`Go: Restart Language Server`]() |
46 | 128 |
|
47 |
| -```json5 |
48 |
| -"go.lintFlags": ["--enable-all", "--new"] |
49 |
| -``` |
| 129 | +#### [`Go: Run on Go Playground`](features.md#go-playground) |
50 | 130 |
|
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). |
52 | 132 |
|
53 |
| -```json5 |
54 |
| -"go.lintFlags": [ |
55 |
| - "-exclude=vendor/...", |
56 |
| - "-config=${workspaceFolder}/config.toml" |
57 |
| -] |
58 |
| -``` |
| 133 | +### Troubleshooting |
59 | 134 |
|
60 |
| -### Commands |
| 135 | +#### `Go: Current GOPATH` |
61 | 136 |
|
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. |
63 | 138 |
|
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) |
80 | 140 |
|
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. |
82 | 142 |
|
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`]() |
84 | 144 |
|
85 | 145 | [`golint`]: https://pkg.go.dev/golang.org/x/lint/golint?tab=overview
|
86 | 146 | [`staticcheck`]: https://pkg.go.dev/honnef.co/go/tools/staticcheck?tab=overview
|
87 | 147 | [`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 |
0 commit comments