|
2 | 2 |
|
3 | 3 | This document describes the features supported by this extension.
|
4 | 4 |
|
5 |
| -If you are using the Go language server, `gopls`, please the [gopls documentation](gopls.md) instead. (You can check if you are using `gopls` by opening your VS Code settings and checking if [`"go.useLanguageServer"`](settings.md#go.useLanguageServer) is `true`.) |
6 |
| - |
7 |
| -If you are using Go modules **without** the language server, some of the features listed below will not be available. |
8 |
| - |
9 | 5 | ## Table of Contents
|
10 | 6 |
|
11 | 7 | * [IntelliSense](#intellisense)
|
@@ -46,97 +42,132 @@ If you are using Go modules **without** the language server, some of the feature
|
46 | 42 |
|
47 | 43 | ### Code completion
|
48 | 44 |
|
49 |
| -Completion results appear for symbols as you type. You can trigger this manually with the Ctrl+Space shortcut. This feature is provided by the [`gocode`](tools.md#gocode) tool. |
| 45 | +Completion results appear for symbols as you type. You can trigger this manually with the Ctrl+Space shortcut. |
50 | 46 |
|
51 |
| -Autocompletion is also supported for packages you have not yet imported into your program. This feature is provided by the [`gopkgs`](tools.md#gopkgs) tool. |
| 47 | +Autocompletion is also supported for packages you have not yet imported into your program. |
52 | 48 |
|
53 |
| -### Signature help |
| 49 | +<div style="text-align: center;"><img src="images/completion-signature-help.gif" alt="Code completion and signature help" style="width: 75%"> </div> |
54 | 50 |
|
55 |
| -Information about the signature of a function pops up as you type in its parameters. This feature is provided by the [`gogetdoc`](tools.md#documentation) tool, but it can also be provided by a combination of [`godef`](tools.md#documentation) and [`godoc`](tools.md#documentation) (configured via the [`"go.docsTool"`](settings.md#go.docsTool) setting). |
| 51 | +### Signature help |
56 | 52 |
|
| 53 | +Information about the signature of a function pops up as you type in its parameters. |
57 | 54 | ### Quick info on hover
|
58 | 55 |
|
59 |
| -Documentation appears when you hover over a symbol. This feature is provided by the [`gogetdoc`](tools.md#documentation) tool, but it can also be provided by a combination of [`godef`](tools.md#documentation) and [`godoc`](tools.md#documentation) (configured via the [`"go.docsTool"`](settings.md#go.docsTool) setting). |
| 56 | +Documentation appears when you hover over a symbol. |
60 | 57 |
|
61 | 58 | ## [Code Navigation](https://code.visualstudio.com/docs/editor/editingevolved)
|
62 | 59 |
|
63 | 60 | ### Go to definition
|
64 | 61 |
|
65 |
| -Jump to or peek a symbol's declaration. This feature is provided by the [`gogetdoc`](tools.md#documentation) tool, but it can also be provided by a combination of [`godef`](tools.md#documentation) and [`godoc`](tools.md#documentation) (configured via the [`"go.docsTool"`](settings.md#go.docsTool) setting). |
| 62 | +Jump to or peek a symbol's declaration. |
| 63 | + |
| 64 | +<div style="text-align: center;"><img src="images/gotodefinition.gif" alt="Go to definition using the context menu" style="width: 75%"> </div> |
66 | 65 |
|
67 | 66 | ### Find references
|
68 | 67 |
|
69 |
| -Find or go to the references of a symbol. This feature is provided the [`guru`](tools.md#guru) tool. |
| 68 | +Find or go to the references of a symbol. |
70 | 69 |
|
71 | 70 | This feature is not available if you are using Go modules **without** [`gopls`](gopls.md), the Go language server.
|
72 | 71 |
|
| 72 | +<div style="text-align: center;"><img src="images/findallreferences.gif" alt="Find references using the context menu" style="width: 75%"> </div> |
| 73 | + |
73 | 74 | ### Find interface implementations
|
74 | 75 |
|
75 |
| -Find the concrete types that implement a given interface. This feature is provided by the [`guru`](tools.md#guru) tool. |
| 76 | +Find the concrete types that implement a given interface. |
76 | 77 |
|
77 | 78 | This feature is not available if you are using Go modules **without** [`gopls`](gopls.md), the Go language server.
|
78 | 79 |
|
| 80 | +<div style="text-align: center;"><img src="images/implementations.gif" alt="Go to implementations for Server that implements http.Handler and then finds all implementations of http.Handler in the workspace" style="width: 75%"> </div> |
| 81 | + |
79 | 82 | ### [Go to symbol](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-symbol)
|
80 | 83 |
|
81 | 84 | Search for symbols in your file or workspace by opening the Command Palette (Ctrl+Shift+P) and typing `@` for symbols in the current file or `#` for symbols in the entire workspace.
|
82 | 85 |
|
83 |
| -This feature is provided by the [`go-outline`](tools.md#go-outline) and [`go-symbols`](tools.md#go-symbols) tools. |
| 86 | +<div style="text-align: center;"><img src="images/workspace-symbols.gif" alt="Use Workspace Symbols to locate Hello in the workspace" style="width: 75%"> </div> |
| 87 | + |
| 88 | +### Call hierarchy |
| 89 | + |
| 90 | +Show all calls from or to a function. |
| 91 | + |
| 92 | +<div style="text-align: center;"><img src="images/callhierarchy.gif" alt="Show call hierarchy and investigate callers of a function" style="width: 75%"> </div> |
84 | 93 |
|
85 | 94 | ### Document outline
|
86 | 95 |
|
87 | 96 | See all the symbols in the current file in the VS Code's [Outline view](https://code.visualstudio.com/docs/getstarted/userinterface#_outline-view).
|
88 | 97 |
|
89 |
| -This feature is provided by the [`go-outline`](tools.md#go-outline) tool. |
| 98 | +<div style="text-align: center;"><img src="images/outline.png" alt="Outline of a Go file" style="width: 75%"> </div> |
90 | 99 |
|
91 | 100 | ### Toggle between code and tests
|
92 | 101 |
|
93 | 102 | Quickly toggle between a file and its corresponding test file by using the [`Go: Toggle Test File`](commands.md#go-toggle-test-file) command.
|
94 | 103 |
|
| 104 | +<div style="text-align: center;"><img src="images/toggletestfile.gif" alt="Toggle between reverse.go and reverse_test.go" style="width: 75%"> </div> |
| 105 | + |
95 | 106 | ## Code Editing
|
96 | 107 |
|
97 | 108 | ### [Snippets](https://code.visualstudio.com/docs/editor/userdefinedsnippets)
|
98 | 109 |
|
99 | 110 | Predefined snippets for quick coding. These snippets will appear as completion suggestions when you type. Users can also define their own custom snippets (see [Snippets in Visual Studio Code](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets)).
|
100 | 111 |
|
| 112 | +<div style="text-align: center;"><img src="images/snippets-tys.gif" alt="Use the struct type snippet" style="width: 75%"> </div> |
| 113 | + |
101 | 114 | ### Format and organize imports
|
102 | 115 |
|
103 |
| -Format code and organize imports, either manually or on save. The code is formatted by the [`gofmt`](tools.md#formatting) tool, which is the standard for Go code. Imports are added automatically to your file via the [`goimports`](tools.md#formatting) tool, which is also an industry standard. By default, this extension also uses the [`goreturns`](tools.md#formatting) tool, which automatically fills in default return values for functions. |
| 116 | +Format code and organize imports, either manually or on save. |
104 | 117 |
|
105 |
| -The behavior of the formatter can be configured via the [`"go.formatTool"`](settings.md#go.formatTool) tool setting. The [troubleshooting guide](troubleshooting.md#formatting) gives more details and explains how to [disable formatting](troubleshooting.md#disable-formatting) entirely. |
| 118 | +The [troubleshooting guide](troubleshooting.md#formatting) gives more details and explains how to [disable formatting](troubleshooting.md#disable-formatting) entirely. |
106 | 119 |
|
107 | 120 | #### Add import
|
108 | 121 |
|
109 | 122 | Manually add a new import to your file through the [`Go: Add Import`](commands.md#go-add-import) command. Available packages are offered from your `GOPATH` and module cache.
|
110 | 123 |
|
| 124 | +<div style="text-align: center;"><img src="images/addimport.gif" alt="Add byte import to Go file" style="width: 75%"> </div> |
| 125 | + |
| 126 | + |
111 | 127 | ### [Rename symbol](https://code.visualstudio.com/docs/editor/refactoring#_rename-symbol)
|
112 | 128 |
|
113 |
| -Rename all occurrences of a symbol in your workspace. This feature is provided by the [`gorename`](tools.md#gorename) tool. |
| 129 | +Rename all occurrences of a symbol in your workspace. |
114 | 130 |
|
115 | 131 | **Note**: For undo after rename to work on Windows, you need to have `diff` tool on your `PATH`.
|
116 | 132 |
|
117 | 133 | This feature is not available if you are using Go modules **without** [`gopls`](gopls.md), the Go language server.
|
118 | 134 |
|
| 135 | +<div style="text-align: center;"><img src="images/rename.gif" alt="Rename an exported variable in Go workspace" style="width: 75%"> </div> |
| 136 | + |
| 137 | + |
119 | 138 | ### Refactor
|
120 | 139 |
|
121 |
| -Extract a piece of code to a local variable or to its own function using the [`Go: Extract to variable`](commands.md#go-extract-to-variable) and [`Go: Extract to function`](commands.md#go-extract-to-function) commands. These features are provided by the [`godoctor`](tools.md#godoctor) tool. These features do not work with Go modules, but they will be supported by [`gopls`] in the future (see [golang/go#37170](https://github.com/golang/go/issues/37170)). |
| 140 | +Extract a piece of code to a local variable or to its own function using the [`Go: Extract to variable`](commands.md#go-extract-to-variable) and [`Go: Extract to function`](commands.md#go-extract-to-function) commands. |
| 141 | + |
| 142 | +For known issues with this feature see [golang/go#37170](https://github.com/golang/go/issues/37170). |
| 143 | + |
| 144 | +<div style="text-align: center;"><img src="images/extract-variable.gif" alt="Extract to variable followed by a rename" style="width: 75%"> </div> |
122 | 145 |
|
123 | 146 | ## Code Generation
|
124 | 147 |
|
125 | 148 | ### Add or remove struct tags
|
126 | 149 |
|
127 | 150 | Use the [`Go: Add Tags to Struct Fields`](commands.md#go-add-tags-to-struct-fields) command to automatically generate or remove [tags](https://pkg.go.dev/reflect?tab=doc#StructTag) for your struct. This feature is provided by the [`gomodifytags`](tools.md#gomodifytags) tool.
|
128 | 151 |
|
| 152 | +<div style="text-align: center;"><img src="images/addtagstostructfields.gif" alt="Add tags to struct fields" style="width: 75%"> </div> |
| 153 | + |
129 | 154 | ### Generate interface implementation
|
130 | 155 |
|
131 | 156 | Use the [`Go: Generate Interface Stubs`](commands.md#go-generate-interface-stubs) command to automatically generate method stubs for a given interface. This feature is provided by the [`impl`](tools.md#impl) tool.
|
132 | 157 |
|
| 158 | +<div style="text-align: center;"><img src="images/generateinterfaceimplementation.gif" alt="Generate functions to implement an interface" style="width: 75%"> </div> |
| 159 | + |
133 | 160 | ### Generate unit tests
|
134 | 161 |
|
135 | 162 | Easily generate unit tests for your project by running one of the [`Go: Generate Unit Tests for ...`](commands.md#go-generate-unit-tests-for-file) commands. This can be done at a function, file, or package level. This feature is provided by the [`gotests`](tools.md#gotests) tool.
|
136 | 163 |
|
| 164 | +<div style="text-align: center;"><img src="images/generateunittestsforfunction.gif" alt="Generate unit tests for a function" style="width: 75%"> </div> |
| 165 | + |
137 | 166 | ### Fill struct literals
|
138 | 167 |
|
139 |
| -Use the [`Go: Fill struct`](commands.md#fill-struct) command to automatically fill a struct literal with its default values. This command is provided by the [`fillstruct`](tools.md#fillstruct). |
| 168 | +Use the [`Go: Fill struct`](commands.md#fill-struct) command to automatically fill a struct literal with its default values. |
| 169 | + |
| 170 | +<div style="text-align: center;"><img src="images/fillstructliterals.gif" alt="Fill struct literals" style="width: 75%"> </div> |
140 | 171 |
|
141 | 172 | ## Diagnostics
|
142 | 173 |
|
@@ -178,7 +209,7 @@ Behind the scenes, the `Debug: Start without Debugging` command calls `go run`.
|
178 | 209 |
|
179 | 210 | ### Code Coverage
|
180 | 211 |
|
181 |
| -Show code coverage in the editor, either after running a test or on-demand. This can be done via the commands: [`Go: Apply Cover Profile`](commands.md#go-apply-cover-profile) and [`Go: Toggle Test Coverage in Current Package`](commands.go-toggle-test-coverage-in-current-package). |
| 212 | +Show code coverage in the editor, either after running a test or on-demand. This can be done via the commands: [`Go: Apply Cover Profile`](commands.md#go-apply-cover-profile) and [`Go: Toggle Test Coverage in Current Package`](commands.md#go-toggle-test-coverage-in-current-package). |
182 | 213 |
|
183 | 214 | ## [Debugging](debugging.md)
|
184 | 215 |
|
|
0 commit comments