diff --git a/gopls/doc/features.md b/gopls/doc/features.md index 40b89391c3..dce671990e 100644 --- a/gopls/doc/features.md +++ b/gopls/doc/features.md @@ -25,9 +25,8 @@ supported within symbol queries: Gopls provides some support for Go template files, that is, files that are parsed by `text/template` or `html/template`. -Gopls recognizes template files based on their file extension. -By default it looks for files ending in `.tmpl` or `.gotmpl`, -but this list may be configured by the +Gopls recognizes template files based on their file extension, which may be +configured by the [`templateExtensions`](https://github.com/golang/tools/blob/master/gopls/doc/settings.md#templateextensions-string) setting. Making this list empty turns off template support. @@ -47,10 +46,10 @@ it is presented as a diagnostic. (Missing functions do not produce errors.) ### Configuring your editor In addition to configuring `templateExtensions`, you may need to configure your -editor or LSP client to activate `gopls` for template files. In recent versions -of `VS Code Go`, this happens automatically for files ending in `.tmpl` or -`.gotmpl`. In Vim, you may need to configure your LSP client to operate on the -`template` filetype. +editor or LSP client to activate `gopls` for template files. For example, in +`VS Code` you will need to configure both +[`files.associations`](https://code.visualstudio.com/docs/languages/identifiers) +and `build.templateExtensions` (the gopls setting). diff --git a/gopls/doc/settings.md b/gopls/doc/settings.md index 542eb1642c..af83ae31e7 100644 --- a/gopls/doc/settings.md +++ b/gopls/doc/settings.md @@ -78,7 +78,7 @@ templateExtensions gives the extensions of file names that are treateed as template files. (The extension is the part of the file name after the final dot.) -Default: `["tmpl","gotmpl"]`. +Default: `[]`. #### **memoryMode** *enum* diff --git a/gopls/internal/regtest/misc/template_test.go b/gopls/internal/regtest/misc/template_test.go index 2bb61fbcc0..6d1419a1b3 100644 --- a/gopls/internal/regtest/misc/template_test.go +++ b/gopls/internal/regtest/misc/template_test.go @@ -27,6 +27,9 @@ func TestSuffixes(t *testing.T) { WithOptions( EditorConfig{ AllExperiments: true, + Settings: map[string]interface{}{ + "templateExtensions": []string{"tmpl", "gotmpl"}, + }, }, ).Run(t, filesA, func(t *testing.T, env *Env) { env.OpenFile("a.tmpl") diff --git a/internal/lsp/fake/editor.go b/internal/lsp/fake/editor.go index f92ef09f23..fe7d4b5c1b 100644 --- a/internal/lsp/fake/editor.go +++ b/internal/lsp/fake/editor.go @@ -114,6 +114,10 @@ type EditorConfig struct { // Whether to edit files with windows line endings. WindowsLineEndings bool + // Settings holds arbitrary additional settings to apply to the gopls config. + // TODO(rfindley): replace existing EditorConfig fields with Settings. + Settings map[string]interface{} + ImportShortcut string DirectoryFilters []string VerboseOutput bool @@ -223,6 +227,10 @@ func (e *Editor) configuration() map[string]interface{} { "completionBudget": "10s", } + for k, v := range e.Config.Settings { + config[k] = v + } + if e.Config.BuildFlags != nil { config["buildFlags"] = e.Config.BuildFlags } diff --git a/internal/lsp/source/api_json.go b/internal/lsp/source/api_json.go index 95a1aff9b1..50c55199ec 100755 --- a/internal/lsp/source/api_json.go +++ b/internal/lsp/source/api_json.go @@ -30,7 +30,7 @@ var GeneratedAPIJSON = &APIJSON{ Name: "templateExtensions", Type: "[]string", Doc: "templateExtensions gives the extensions of file names that are treateed\nas template files. (The extension\nis the part of the file name after the final dot.)\n", - Default: "[\"tmpl\",\"gotmpl\"]", + Default: "[]", Hierarchy: "build", }, { diff --git a/internal/lsp/source/options.go b/internal/lsp/source/options.go index 147bb9e448..f6f952f856 100644 --- a/internal/lsp/source/options.go +++ b/internal/lsp/source/options.go @@ -114,7 +114,7 @@ func DefaultOptions() *Options { ExperimentalPackageCacheKey: true, MemoryMode: ModeNormal, DirectoryFilters: []string{"-node_modules"}, - TemplateExtensions: []string{"tmpl", "gotmpl"}, + TemplateExtensions: []string{}, }, UIOptions: UIOptions{ DiagnosticOptions: DiagnosticOptions{