What version of Go, VS Code & VS Code Go extension are you using?

Version Information
* Run `go version` to get version of Go from _the VS Code integrated terminal_. - go version go1.23.4 linux/amd64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. - v0.17.1 * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - 1.96.2 * Check your installed extensions to get the version of the VS Code Go extension - 0.44.0 * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. - # Tools Configuration ## Environment GOBIN: undefined toolsGopath: gopath: /home/bigon/go GOROOT: /usr/lib/go-1.23 PATH: /home/bigon/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games ## Tools go: /usr/bin/go: go version go1.23.4 linux/amd64 gopls: /home/bigon/go/bin/gopls (version: v0.17.1 built with go: go1.23.4) gotests: not installed gomodifytags: not installed impl: not installed goplay: not installed dlv: /usr/bin/dlv (version: undefined built with go: go1.23.4) staticcheck: /home/bigon/go/bin/staticcheck (version: v0.5.1 built with go: go1.23.4) ## Go env Workspace Folder (thanos-receivers): /home/bigon/Boulot//code/thanos-receivers GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/home/bigon/.cache/go-build' GOENV='/home/bigon/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GOMODCACHE='/home/bigon/go/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='linux' GOPATH='/home/bigon/go' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/usr/lib/go-1.23' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/usr/lib/go-1.23/pkg/tool/linux_amd64' GOVCS='' GOVERSION='go1.23.4' GODEBUG='' GOTELEMETRY='local' GOTELEMETRYDIR='/home/bigon/.config/go/telemetry' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='gcc' CXX='g++' CGO_ENABLED='1' GOMOD='/dev/null' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2302377950=/tmp/go-build -gno-record-gcc-switches'

Share the Go related settings you have added/edited

Default config

Describe the bug

No syntax highlighting for gotmpl

I'm expecting to have some colors and highlighting

Steps to reproduce the behavior:

  1. Install the vscode-go extension
  2. Open a gotmpl file
  3. No syntax highlighting for gotmpl

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

Comment From: bigon

I also see the following error in the gopls server output:

[Error - 16:49:00] Request textDocument/documentSymbol failed.
Error: name must not be falsy
    at Function.validate (file:///usr/share/code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:109:33647)
    at new Gd (file:///usr/share/code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:109:33936)
    at asDocumentSymbol (/home/bigon/.vscode/extensions/golang.go-0.44.0/dist/goMain.js:14573:22)
    at convertBatch (/home/bigon/.vscode/extensions/golang.go-0.44.0/dist/goMain.js:12968:23)
    at Object.map (/home/bigon/.vscode/extensions/golang.go-0.44.0/dist/goMain.js:12976:19)
    at Object.asDocumentSymbols (/home/bigon/.vscode/extensions/golang.go-0.44.0/dist/goMain.js:14570:22)
    at _provideDocumentSymbols (/home/bigon/.vscode/extensions/golang.go-0.44.0/dist/goMain.js:18861:64)
    at uI.provideDocumentSymbols (file:///usr/share/code/resources/app/out/vs/workbench/api/node/extensionHostProcess.js:138:126457)

**Comment From: findleyr**

Hi, are you setting the "templateExtensions" gopls setting?
https://github.com/golang/tools/blob/master/gopls/doc/settings.md#templateextensions-string

Without this set, VS Code will not recognize go template files.

**Comment From: bigon**

Hello,

For what I can see, the file with `.gotmpl` are already recognized as a go template

![Image](https://github.com/user-attachments/assets/7166c789-31a9-4a2a-ad10-a961bdd9e231)

For I added the following and it's the same issue

```json
    "gopls": {

        "templateExtensions": [
            "gotmpl",
        ]
    }

Comment From: findleyr

Thanks @bigon: are you still not seeing syntax highlighting after that change?

You may also need to add: "semanticTokens": true.

Comment From: bigon

"semanticTokens": true to true is showing some color, yes

Comment From: findleyr

Thank you. Reclassifying this as a documentation bug, to improve our (nearly nonexistent) documentation for working with template files.

Comment From: bigon

Shouldn't semanticTokens be set to true by default?

Comment From: aditya-7562

Hi @findleyr

I’d love to help improve the documentation around enabling .gotmpl (Go template) support in VS Code with gopls. I’m thinking of adding a short clarification under the build.templateExtensions section in docs/settings.md, including a note about also setting ui.semanticTokens to get proper syntax highlighting and symbol support.

Would it be alright if I open a PR with that change? Happy to follow any preferred format or placement if you have one in mind.

Thanks!

Comment From: h9jiang

Re: @bigon sorry for the late reply, it is off by default, see https://github.com/golang/vscode-go/issues/2286

I think the most important reason is performance issues. Type checking the package may take a while.

Comment From: h9jiang

Hi @aditya-7562

I think it is appropriate to add some clarification in

### `ui.semanticTokens`

indicating this controls the semantic token not only for the Go files as well as other template file specified in build.templateExtensions

Feel free to sent us a CL following the contributing guide.

Sorry, you can;t make changes to vscode-go, instead, you should visit tools repo and change the comment in gopls/internal/settings/settings.go. The next vscode-go will automatically have the setting updated.