Skip to content

Commit 5acb0e8

Browse files
committed
docs/features.md: discuss default formatting behavior and template support
We already have a section in the advanced.md doc abount default formatting and imports behavior. I hope this additional reference helps users to discover the control knob. Didn't mention completion, diagnostics for Go template files yet. We need to update the diagnostics section to discuss gopls's diagnostics feature. Updates golang#609 Change-Id: Ib2e695d847c56bd4f562d91d2938cb5c1a032764
1 parent debf84a commit 5acb0e8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

docs/features.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This document describes the features supported by this extension.
1515
* [Find interface implementations](#find-interface-implementations)
1616
* [Document outline](#document-outline)
1717
* [Toggle between code and tests](#toggle-between-code-and-tests)
18+
* [Syntax Highlighting](#syntax-highlighting)
1819
* [Code Editing](#code-editing)
1920
* [Snippets](#snippets)
2021
* [Format and organize imports](#format-and-organize-imports)
@@ -103,6 +104,19 @@ Quickly toggle between a file and its corresponding test file by using the [`Go:
103104

104105
<div style="text-align: center;"><img src="images/toggletestfile.gif" alt="Toggle between reverse.go and reverse_test.go" style="width: 75%"> </div>
105106

107+
108+
## Syntax Highlighting
109+
110+
The default syntax highlighting for Go files is implemented in Visual Studio Code using TextMate grammar, not by this extension.
111+
112+
If you are using `gopls`, you can enable [Semantic Highlighting](https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide) for more accurate syntax highlighting based on semantic tokenization using `"gopls": { "ui.semanticTokens": true }`.
113+
114+
### Go template syntax highlighting
115+
116+
When `gopls`'s semantic tokens feature is enabled, `gopls` also provides semantic tokens for Go template files (language identifier: `gotmpl`). By default, the extension associates all `*.tmpl` or `*.gotmpl` files in the workspace with `gotmpl` language. Users can override the language mode by using Visual Studio Code's UI or the `"files.associations"` setting. See [Visual Studio Code's doc](https://code.visualstudio.com/docs/languages/overview#_changing-the-language-for-the-selected-file) for more details.
117+
118+
<div style="text-align: center;"><img src="images/gotmpl.gif" alt="Enable Go template language support by changing the language ID" style="width: 75%"> </div>
119+
106120
## Code Editing
107121

108122
### [Snippets](https://code.visualstudio.com/docs/editor/userdefinedsnippets)
@@ -115,13 +129,16 @@ Predefined snippets for quick coding. These snippets will appear as completion s
115129

116130
Format code and organize imports, either manually or on save.
117131

132+
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](https://github.com/golang/vscode-go/blob/master/docs/advanced.md#formatting-code-and-organizing-imports).
133+
134+
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>}`](https://github.com/golang/vscode-go/blob/master/docs/settings.md#formattinglocal).
135+
118136
#### Add import
119137

120-
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.
138+
The extension organizes imports automatically and can add missing imports if the package is present in your module cache already. However, you can also manually add a new import to your file through the [`Go: Add Import`](commands.md#go-add-import) command. Available packages are offered from module cache (or from your `GOPATH` in GOPATH mode).
121139

122140
<div style="text-align: center;"><img src="images/addimport.gif" alt="Add byte import to Go file" style="width: 75%"> </div>
123141

124-
125142
### [Rename symbol](https://code.visualstudio.com/docs/editor/refactoring#_rename-symbol)
126143

127144
Rename all occurrences of a symbol in your workspace.

docs/images/gotmpl.gif

524 KB
Loading

0 commit comments

Comments
 (0)