Skip to content

Commit 982638e

Browse files
committed
docs/features.md: add details about custom formatter setting
Fixes #3397 Change-Id: I49fdf614538e01f42f4a25d8c56c6035b3af8e6e Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/597296 kokoro-CI: kokoro <[email protected]> Reviewed-by: Suzy Mueller <[email protected]> Commit-Queue: Hyang-Ah Hana Kim <[email protected]>
1 parent 7a532aa commit 982638e

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

docs/features.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,15 @@ Format code and organize imports, either manually or on save.
194194

195195
The extension formats Go code, organizes imports, and removes unused imports by default. For different behavior, please override per-language default settings following [the instruction](advanced.md#formatting-code-and-organizing-imports).
196196

197-
When organizing imports, the imported packages are grouped in the default `goimports` style. In order to group some packages after 3rd-party packages, use [`"gopls": { "formatting.local": <comma-separated imports prefix>}`](settings.md#formattinglocal).
197+
#### Organizing imports
198+
199+
When organizing imports, the imported packages are grouped in the default `goimports` style. In order to group some packages after 3rd-party packages, use the [`"formatting.local"`](settings.md#formattinglocal) setting.
200+
201+
```json
202+
"gopls": {
203+
"formatting.local": "example.com/myorg,github.com/myorg2"
204+
}
205+
```
198206

199207
#### Add import
200208

@@ -204,8 +212,23 @@ The extension organizes imports automatically and can add missing imports if the
204212

205213
#### Custom formatter
206214

207-
In addition to the default `gofmt`-style formatter, the Go language server supports `gofumpt`-style formatting. You can enable `gofumpt` formatting by setting `"gopls.formatting.gofumpt"`.
208-
You can also configure to use other custom formatter by using the `"go.formatTool"` setting. The custom formatter must operate on file contents from STDIN, and output the formatted result to STDOUT.
215+
In addition to the default [`go fmt`](https://pkg.go.dev/cmd/gofmt) style formatter, the language server (`gopls`) supports `github.com/mvdan/gofumpt` style formmating. Use gopls's [`formatting.gofumpt`](settings.md#formattinggofumpt) setting:
216+
217+
```json
218+
"gopls": { "fomatting.gofumpt": true }
219+
```
220+
221+
You can also configure to use other custom formatter (`golines`) by using the `"go.formatTool"` setting. The custom formatter must operate on file contents from STDIN, and output the formatted result to STDOUT.
222+
223+
```json
224+
"go.formatTools": "custom",
225+
"go.alternateTools": {
226+
// the binary name if it is in your PATH, or
227+
// provide the exact path to your
228+
// custom formatter.
229+
"customFormatter": "golines"
230+
}
231+
```
209232

210233
### [Rename symbol](https://code.visualstudio.com/docs/editor/refactoring#_rename-symbol)
211234

0 commit comments

Comments
 (0)