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, which may be configured by the templateExtensions
setting. If this list is empty, template support is disabled. (This is the default value, since Go templates don't have a canonical file extension.)
Additional configuration may be necessary to ensure that your client chooses the correct language kind when opening template files. Gopls recogizes both "tmpl"
and "gotmpl"
for template files. For example, in VS Code
you will also need to add an entry to the files.associations
mapping:
"files.associations": { ".mytemplate": "gotmpl" },
In template files, template support works inside the default {{
delimiters. (Go template parsing allows the user to specify other delimiters, but gopls does not know how to do that.)
Gopls template support includes the following features:
TODO: also