зеркало из https://github.com/golang/tools.git
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>
This commit is contained in:
Родитель
d34a02b6b5
Коммит
c4cfc425f2
|
@ -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).
|
||||
|
||||
<!--TODO(rstambler): Automatically generate a list of supported features.-->
|
||||
|
||||
|
|
|
@ -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*
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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{
|
||||
|
|
Загрузка…
Ссылка в новой задаче