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 <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/gopls/doc/features.md b/gopls/doc/features.md
index 40b8939..dce6719 100644
--- a/gopls/doc/features.md
+++ b/gopls/doc/features.md
@@ -25,9 +25,8 @@
 
 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 @@
 ### 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).
 
 <!--TODO(rstambler): Automatically generate a list of supported features.-->
 
diff --git a/gopls/doc/settings.md b/gopls/doc/settings.md
index 542eb16..af83ae3 100644
--- a/gopls/doc/settings.md
+++ b/gopls/doc/settings.md
@@ -78,7 +78,7 @@
 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 2bb61fb..6d1419a 100644
--- a/gopls/internal/regtest/misc/template_test.go
+++ b/gopls/internal/regtest/misc/template_test.go
@@ -27,6 +27,9 @@
 	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 f92ef09..fe7d4b5 100644
--- a/internal/lsp/fake/editor.go
+++ b/internal/lsp/fake/editor.go
@@ -114,6 +114,10 @@
 	// 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 @@
 		"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 95a1aff..50c5519 100755
--- a/internal/lsp/source/api_json.go
+++ b/internal/lsp/source/api_json.go
@@ -30,7 +30,7 @@
 				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 147bb9e..f6f952f 100644
--- a/internal/lsp/source/options.go
+++ b/internal/lsp/source/options.go
@@ -114,7 +114,7 @@
 					ExperimentalPackageCacheKey: true,
 					MemoryMode:                  ModeNormal,
 					DirectoryFilters:            []string{"-node_modules"},
-					TemplateExtensions:          []string{"tmpl", "gotmpl"},
+					TemplateExtensions:          []string{},
 				},
 				UIOptions: UIOptions{
 					DiagnosticOptions: DiagnosticOptions{