[tools] gopls: change the default value for templateExtensions to be empty

185 views
Skip to first unread message

Robert Findley (Gerrit)

unread,
Jan 6, 2022, 10:25:39 AM1/6/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Robert Findley has uploaded this change for review.

View Change

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
---
M internal/lsp/fake/editor.go
M internal/lsp/source/api_json.go
M gopls/internal/regtest/misc/template_test.go
M gopls/doc/features.md
M internal/lsp/source/options.go
M gopls/doc/settings.md
6 files changed, 35 insertions(+), 10 deletions(-)

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{

To view, visit change 375874. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I7e37d22b1bc63d8300634b3b0394b4036b43fa49
Gerrit-Change-Number: 375874
Gerrit-PatchSet: 1
Gerrit-Owner: Robert Findley <rfin...@google.com>
Gerrit-Reviewer: Robert Findley <rfin...@google.com>
Gerrit-MessageType: newchange

kokoro (Gerrit)

unread,
Jan 6, 2022, 10:32:54 AM1/6/22
to Robert Findley, goph...@pubsubhelper.golang.org, Gopher Robot, golang-co...@googlegroups.com

Kokoro presubmit build finished with status: SUCCESS
Logs at: https://source.cloud.google.com/results/invocations/4d5b0606-18a9-432f-8834-167f4bdd6954

Patch set 1:gopls-CI +1

View Change

    To view, visit change 375874. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: I7e37d22b1bc63d8300634b3b0394b4036b43fa49
    Gerrit-Change-Number: 375874
    Gerrit-PatchSet: 1
    Gerrit-Owner: Robert Findley <rfin...@google.com>
    Gerrit-Reviewer: Robert Findley <rfin...@google.com>
    Gerrit-Reviewer: kokoro <noreply...@google.com>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-Comment-Date: Thu, 06 Jan 2022 15:32:47 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    kokoro (Gerrit)

    unread,
    Jan 13, 2022, 11:55:11 AM1/13/22
    to Robert Findley, goph...@pubsubhelper.golang.org, Peter Weinberger, Hyang-Ah Hana Kim, Gopher Robot, golang-co...@googlegroups.com

    Attention is currently required from: Peter Weinberger, Hyang-Ah Hana Kim.

    Kokoro presubmit build finished with status: SUCCESS

    Logs at: https://source.cloud.google.com/results/invocations/07578941-5b05-4583-98d9-72226c1af576

    Patch set 2:gopls-CI +1

    View Change

      To view, visit change 375874. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: tools
      Gerrit-Branch: master
      Gerrit-Change-Id: I7e37d22b1bc63d8300634b3b0394b4036b43fa49
      Gerrit-Change-Number: 375874
      Gerrit-PatchSet: 2
      Gerrit-Owner: Robert Findley <rfin...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
      Gerrit-Reviewer: Peter Weinberger <p...@google.com>
      Gerrit-Reviewer: Robert Findley <rfin...@google.com>
      Gerrit-Reviewer: kokoro <noreply...@google.com>
      Gerrit-Attention: Peter Weinberger <p...@google.com>
      Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
      Gerrit-Comment-Date: Thu, 13 Jan 2022 16:55:05 +0000

      kokoro (Gerrit)

      unread,
      Jan 13, 2022, 1:59:59 PM1/13/22
      to Robert Findley, goph...@pubsubhelper.golang.org, Suzy Mueller, Gopher Robot, Peter Weinberger, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

      Attention is currently required from: Peter Weinberger, Suzy Mueller, Hyang-Ah Hana Kim.

      Kokoro presubmit build finished with status: SUCCESS

      Logs at: https://source.cloud.google.com/results/invocations/fed0f649-ad73-455f-842c-ff6f4d1bc363

      Patch set 3:gopls-CI +1

      View Change

        To view, visit change 375874. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: tools
        Gerrit-Branch: master
        Gerrit-Change-Id: I7e37d22b1bc63d8300634b3b0394b4036b43fa49
        Gerrit-Change-Number: 375874
        Gerrit-PatchSet: 3
        Gerrit-Owner: Robert Findley <rfin...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
        Gerrit-Reviewer: Peter Weinberger <p...@google.com>
        Gerrit-Reviewer: Robert Findley <rfin...@google.com>
        Gerrit-Reviewer: Suzy Mueller <suz...@golang.org>
        Gerrit-Reviewer: kokoro <noreply...@google.com>
        Gerrit-Attention: Peter Weinberger <p...@google.com>
        Gerrit-Attention: Suzy Mueller <suz...@golang.org>
        Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
        Gerrit-Comment-Date: Thu, 13 Jan 2022 18:59:54 +0000

        Suzy Mueller (Gerrit)

        unread,
        Jan 13, 2022, 2:05:05 PM1/13/22
        to Robert Findley, goph...@pubsubhelper.golang.org, kokoro, Gopher Robot, Peter Weinberger, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

        Attention is currently required from: Peter Weinberger, Robert Findley, Hyang-Ah Hana Kim.

        Patch set 3:Code-Review +2

        View Change

          To view, visit change 375874. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: tools
          Gerrit-Branch: master
          Gerrit-Change-Id: I7e37d22b1bc63d8300634b3b0394b4036b43fa49
          Gerrit-Change-Number: 375874
          Gerrit-PatchSet: 3
          Gerrit-Owner: Robert Findley <rfin...@google.com>
          Gerrit-Reviewer: Gopher Robot <go...@golang.org>
          Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
          Gerrit-Reviewer: Peter Weinberger <p...@google.com>
          Gerrit-Reviewer: Robert Findley <rfin...@google.com>
          Gerrit-Reviewer: Suzy Mueller <suz...@golang.org>
          Gerrit-Reviewer: kokoro <noreply...@google.com>
          Gerrit-Attention: Peter Weinberger <p...@google.com>
          Gerrit-Attention: Robert Findley <rfin...@google.com>
          Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
          Gerrit-Comment-Date: Thu, 13 Jan 2022 19:05:01 +0000

          kokoro (Gerrit)

          unread,
          Jan 13, 2022, 2:44:03 PM1/13/22
          to Robert Findley, goph...@pubsubhelper.golang.org, Gopher Robot, Suzy Mueller, Peter Weinberger, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

          Attention is currently required from: Peter Weinberger, Robert Findley, Hyang-Ah Hana Kim.

          Kokoro presubmit build finished with status: SUCCESS
          Logs at: https://source.cloud.google.com/results/invocations/6e07dc20-a0e8-4d34-aa09-81730c2e4adb

          Patch set 4:gopls-CI +1

          View Change

            To view, visit change 375874. To unsubscribe, or for help writing mail filters, visit settings.

            Gerrit-Project: tools
            Gerrit-Branch: master
            Gerrit-Change-Id: I7e37d22b1bc63d8300634b3b0394b4036b43fa49
            Gerrit-Change-Number: 375874
            Gerrit-PatchSet: 4
            Gerrit-Owner: Robert Findley <rfin...@google.com>
            Gerrit-Reviewer: Gopher Robot <go...@golang.org>
            Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
            Gerrit-Reviewer: Peter Weinberger <p...@google.com>
            Gerrit-Reviewer: Robert Findley <rfin...@google.com>
            Gerrit-Reviewer: Suzy Mueller <suz...@golang.org>
            Gerrit-Reviewer: kokoro <noreply...@google.com>
            Gerrit-Attention: Peter Weinberger <p...@google.com>
            Gerrit-Attention: Robert Findley <rfin...@google.com>
            Gerrit-Attention: Hyang-Ah Hana Kim <hya...@gmail.com>
            Gerrit-Comment-Date: Thu, 13 Jan 2022 19:43:59 +0000

            Robert Findley (Gerrit)

            unread,
            Jan 13, 2022, 3:56:27 PM1/13/22
            to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Gopher Robot, kokoro, Suzy Mueller, Peter Weinberger, Hyang-Ah Hana Kim, golang-co...@googlegroups.com

            Robert Findley submitted this change.

            View Change



            3 is the latest approved patch-set.
            No files were changed between the latest approved patch-set and the submitted one.

            Approvals: Suzy Mueller: Looks good to me, approved Robert Findley: Trusted; Run TryBots Gopher Robot: TryBots succeeded kokoro: gopls CI succeeded
            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 <rfin...@google.com>
            Run-TryBot: Robert Findley <rfin...@google.com>
            Reviewed-by: Suzy Mueller <suz...@golang.org>
            gopls-CI: kokoro <noreply...@google.com>
            TryBot-Result: Gopher Robot <go...@golang.org>

            ---
            M internal/lsp/fake/editor.go
            M internal/lsp/source/api_json.go
            M gopls/internal/regtest/misc/template_test.go
            M gopls/doc/features.md
            M internal/lsp/source/options.go
            M gopls/doc/settings.md
            6 files changed, 41 insertions(+), 10 deletions(-)

            To view, visit change 375874. To unsubscribe, or for help writing mail filters, visit settings.

            Gerrit-Project: tools
            Gerrit-Branch: master
            Gerrit-Change-Id: I7e37d22b1bc63d8300634b3b0394b4036b43fa49
            Gerrit-Change-Number: 375874
            Gerrit-PatchSet: 5
            Gerrit-Owner: Robert Findley <rfin...@google.com>
            Gerrit-Reviewer: Gopher Robot <go...@golang.org>
            Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
            Gerrit-Reviewer: Peter Weinberger <p...@google.com>
            Gerrit-Reviewer: Robert Findley <rfin...@google.com>
            Gerrit-Reviewer: Suzy Mueller <suz...@golang.org>
            Gerrit-Reviewer: kokoro <noreply...@google.com>
            Gerrit-MessageType: merged
            Reply all
            Reply to author
            Forward
            0 new messages