Skip to content

Commit c4cfc42

Browse files
committed
gopls: change the default value for templateExtensions to be empty
There is no standard for go template file extensions, and users may not want this functionality. Make template support opt-in by changing the default value of templateExtensions to be []. Updates golang/vscode-go#1957 Change-Id: I7e37d22b1bc63d8300634b3b0394b4036b43fa49 Reviewed-on: https://go-review.googlesource.com/c/tools/+/375874 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Suzy Mueller <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent d34a02b commit c4cfc42

File tree

6 files changed

+20
-10
lines changed

6 files changed

+20
-10
lines changed

gopls/doc/features.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ supported within symbol queries:
2525

2626
Gopls provides some support for Go template files, that is, files that
2727
are parsed by `text/template` or `html/template`.
28-
Gopls recognizes template files based on their file extension.
29-
By default it looks for files ending in `.tmpl` or `.gotmpl`,
30-
but this list may be configured by the
28+
Gopls recognizes template files based on their file extension, which may be
29+
configured by the
3130
[`templateExtensions`](https://github.com/golang/tools/blob/master/gopls/doc/settings.md#templateextensions-string) setting.
3231
Making this list empty turns off template support.
3332

@@ -47,10 +46,10 @@ it is presented as a diagnostic. (Missing functions do not produce errors.)
4746
### Configuring your editor
4847

4948
In addition to configuring `templateExtensions`, you may need to configure your
50-
editor or LSP client to activate `gopls` for template files. In recent versions
51-
of `VS Code Go`, this happens automatically for files ending in `.tmpl` or
52-
`.gotmpl`. In Vim, you may need to configure your LSP client to operate on the
53-
`template` filetype.
49+
editor or LSP client to activate `gopls` for template files. For example, in
50+
`VS Code` you will need to configure both
51+
[`files.associations`](https://code.visualstudio.com/docs/languages/identifiers)
52+
and `build.templateExtensions` (the gopls setting).
5453

5554
<!--TODO(rstambler): Automatically generate a list of supported features.-->
5655

gopls/doc/settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ templateExtensions gives the extensions of file names that are treateed
7878
as template files. (The extension
7979
is the part of the file name after the final dot.)
8080

81-
Default: `["tmpl","gotmpl"]`.
81+
Default: `[]`.
8282

8383
#### **memoryMode** *enum*
8484

gopls/internal/regtest/misc/template_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func TestSuffixes(t *testing.T) {
2727
WithOptions(
2828
EditorConfig{
2929
AllExperiments: true,
30+
Settings: map[string]interface{}{
31+
"templateExtensions": []string{"tmpl", "gotmpl"},
32+
},
3033
},
3134
).Run(t, filesA, func(t *testing.T, env *Env) {
3235
env.OpenFile("a.tmpl")

internal/lsp/fake/editor.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ type EditorConfig struct {
114114
// Whether to edit files with windows line endings.
115115
WindowsLineEndings bool
116116

117+
// Settings holds arbitrary additional settings to apply to the gopls config.
118+
// TODO(rfindley): replace existing EditorConfig fields with Settings.
119+
Settings map[string]interface{}
120+
117121
ImportShortcut string
118122
DirectoryFilters []string
119123
VerboseOutput bool
@@ -223,6 +227,10 @@ func (e *Editor) configuration() map[string]interface{} {
223227
"completionBudget": "10s",
224228
}
225229

230+
for k, v := range e.Config.Settings {
231+
config[k] = v
232+
}
233+
226234
if e.Config.BuildFlags != nil {
227235
config["buildFlags"] = e.Config.BuildFlags
228236
}

internal/lsp/source/api_json.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/lsp/source/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func DefaultOptions() *Options {
114114
ExperimentalPackageCacheKey: true,
115115
MemoryMode: ModeNormal,
116116
DirectoryFilters: []string{"-node_modules"},
117-
TemplateExtensions: []string{"tmpl", "gotmpl"},
117+
TemplateExtensions: []string{},
118118
},
119119
UIOptions: UIOptions{
120120
DiagnosticOptions: DiagnosticOptions{

0 commit comments

Comments
 (0)