Skip to content

LSP diagnostics not working on Windows #1121

@koppa96

Description

@koppa96

Describe the bug
LSP diagnostic errors don't show up in neither VS Code, nor in Goland.

To Reproduce
https://github.com/koppa96/templ-lsp-repro

Expected behavior
I expect an error to be visible when I use a variable that is not declared in a scope.

Screenshots

Image

The variable ajwskerf is clearly not declared, but is not underlined, and the IDE shows no problems about the file. Same thing happens in VS Code.

Logs

{"time":"2025-04-08T13:29:26.1674588+02:00","level":"INFO","msg":"lsp: starting up..."}
{"time":"2025-04-08T13:29:26.173959+02:00","level":"INFO","msg":"lsp: starting gopls..."}
{"time":"2025-04-08T13:29:26.1894604+02:00","level":"INFO","msg":"creating gopls client"}
{"time":"2025-04-08T13:29:26.189963+02:00","level":"INFO","msg":"creating proxy"}
{"time":"2025-04-08T13:29:26.189963+02:00","level":"INFO","msg":"creating templ server"}
{"time":"2025-04-08T13:29:26.189963+02:00","level":"INFO","msg":"listening"}
{"time":"2025-04-08T13:29:26.1909605+02:00","level":"INFO","msg":"client -> server: Initialize"}
{"time":"2025-04-08T13:29:26.3146584+02:00","level":"ERROR","msg":"walk error","error":"CreateFile /c%3A/Users/koppa.peter/GolandProjects/templtest: A rendszer nem találja a megadott elérési utat."}
{"time":"2025-04-08T13:29:26.3162292+02:00","level":"INFO","msg":"client -> server: Initialize end"}
{"time":"2025-04-08T13:29:26.3298162+02:00","level":"INFO","msg":"client -> server: Initialized"}
{"time":"2025-04-08T13:29:26.3298162+02:00","level":"INFO","msg":"client -> server: Initialized end"}
{"time":"2025-04-08T13:29:26.3303164+02:00","level":"INFO","msg":"client <- server: ShowMessage","message":"Loading packages..."}
{"time":"2025-04-08T13:29:26.5195718+02:00","level":"INFO","msg":"client -> server: DidOpen","uri":"file:///c%3A/Users/koppa.peter/GolandProjects/templtest/hello.templ"}
{"time":"2025-04-08T13:29:26.5205705+02:00","level":"INFO","msg":"setting source map cache contents","uri":"file:///c%3A/Users/koppa.peter/GolandProjects/templtest/hello.templ"}
{"time":"2025-04-08T13:29:26.5205705+02:00","level":"INFO","msg":"client -> server: DidOpen end"}
{"time":"2025-04-08T13:29:26.7888516+02:00","level":"INFO","msg":"client <- server: LogMessage","message":"2025/04/08 13:29:26 Created View (#1)\n\tdirectory=C:\\Users\\koppa.peter\\GolandProjects\\templtest\n\tview_type=\"GoMod\"\n\troot_dir=\"file:///C:/Users/koppa.peter/GolandProjects/templtest\"\n\tgo_version=\"go version go1.23.8 windows/amd64\"\n\tbuild_flags=[]\n\tenv={GOOS:windows GOARCH:amd64 GOCACHE:C:\\Users\\koppa.peter\\AppData\\Local\\go-build GOMODCACHE:C:\\Users\\koppa.peter\\go\\pkg\\mod GOPATH:C:\\Users\\koppa.peter\\go GOPRIVATE: GOFLAGS: GO111MODULE: GOTOOLCHAIN:auto GOROOT:C:\\Users\\koppa.peter\\go\\pkg\\mod\\golang.org\\toolchain@v0.0.1-go1.23.8.windows-amd64 GoVersion:23 GoVersionOutput:go version go1.23.8 windows/amd64\n ExplicitGOWORK: EffectiveGOPACKAGESDRIVER:}\n\tenv_overlay=[]\n"}
{"time":"2025-04-08T13:29:27.5667969+02:00","level":"INFO","msg":"client <- server: LogMessage","message":"2025/04/08 13:29:27 go/packages.Load #1\n\tview_id=\"1\"\n\tsnapshot=0\n\tdirectory=C:\\Users\\koppa.peter\\GolandProjects\\templtest\n\tquery=[C:\\Users\\koppa.peter\\GolandProjects\\templtest\\... builtin]\n\tpackages=2\n\tduration=777.4322ms\n"}
{"time":"2025-04-08T13:29:27.6016035+02:00","level":"INFO","msg":"client <- server: ShowMessage","message":"Finished loading packages."}
{"time":"2025-04-08T13:29:27.6016035+02:00","level":"INFO","msg":"client <- server: RegisterCapability"}
{"time":"2025-04-08T13:29:27.8444933+02:00","level":"INFO","msg":"client -> server: CodeAction","params":{"textDocument":{"uri":"file:///c%3A/Users/koppa.peter/GolandProjects/templtest/hello.templ"},"context":{"diagnostics":[]},"range":{"start":{"line":3,"character":18},"end":{"line":3,"character":18}}}}
{"time":"2025-04-08T13:29:27.901725+02:00","level":"INFO","msg":"client -> server: CodeAction end"}
{"time":"2025-04-08T13:29:28.01314+02:00","level":"INFO","msg":"client -> server: CodeAction","params":{"textDocument":{"uri":"file:///c%3A/Users/koppa.peter/GolandProjects/templtest/hello.templ"},"context":{"diagnostics":[]},"range":{"start":{"line":3,"character":18},"end":{"line":3,"character":18}}}}
{"time":"2025-04-08T13:29:28.3457828+02:00","level":"INFO","msg":"client <- server: LogMessage","message":"2025/04/08 13:29:28 go/packages.Load #2\n\tview_id=\"1\"\n\tsnapshot=1\n\tdirectory=C:\\Users\\koppa.peter\\GolandProjects\\templtest\n\tquery=[file=C:\\Users\\koppa.peter\\GolandProjects\\templtest\\hello_templ.go]\n\tpackages=1\n\tduration=719.5475ms\n"}
{"time":"2025-04-08T13:29:28.4259383+02:00","level":"INFO","msg":"client <- server: PublishDiagnostics"}
{"time":"2025-04-08T13:29:28.4259383+02:00","level":"INFO","msg":"client <- server: PublishDiagnostics: [0]","diagnostic":{"range":{"start":{"line":34,"character":65},"end":{"line":34,"character":73}},"severity":1,"code":"UndeclaredName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName"},"source":"compiler","message":"undefined: ajwskerf"}}
{"time":"2025-04-08T13:29:28.4259383+02:00","level":"ERROR","msg":"unable to complete because the sourcemap for the URI doesn't exist in the cache","uri":"file:///C:/Users/koppa.peter/GolandProjects/templtest/hello.templ"}
{"time":"2025-04-08T13:29:28.7360915+02:00","level":"INFO","msg":"client <- server: LogMessage","message":"2025/04/08 13:29:28 go/packages.Load #4\n\tview_id=\"1\"\n\tsnapshot=1\n\tdirectory=C:\\Users\\koppa.peter\\GolandProjects\\templtest\n\tquery=[file=C:\\Users\\koppa.peter\\GolandProjects\\templtest\\hello_templ.go]\n\tpackages=1\n\tduration=721.9093ms\n"}
{"time":"2025-04-08T13:29:28.742141+02:00","level":"INFO","msg":"client -> server: CodeAction end"}
{"time":"2025-04-08T13:29:29.700788+02:00","level":"INFO","msg":"client <- server: PublishDiagnostics"}
{"time":"2025-04-08T13:29:29.700788+02:00","level":"INFO","msg":"client <- server: PublishDiagnostics: skipping go.mod diagnostics"}

templ info output

(✓) os [ goos=windows goarch=amd64 ]
(✓) go [ location=C:\Users\koppa.peter\go\pkg\mod\golang.org\toolchain@v0.0.1-go1.23.8.windows-amd64\bin\go.exe version=go version go1.23.8 windows/amd64 ]
(✓) gopls [ location=C:\Users\koppa.peter\go\bin\gopls.exe version=golang.org/x/tools/gopls v0.18.1 ]
(✓) templ [ location=C:\Users\koppa.peter\go\bin\templ.exe version=v0.3.857 ]

Desktop (please complete the following information):

  • OS: Windows 10
  • templ CLI version (templ version): v0.3.857
  • Go version (go version): go version go1.23.8 windows/amd64
  • gopls version (gopls version): golang.org/x/tools/gopls v0.18.1

Additional context

In the logs this line occurs:

{"time":"2025-04-08T13:29:26.5205705+02:00","level":"INFO","msg":"setting source map cache contents","uri":"file:///c%3A/Users/koppa.peter/GolandProjects/templtest/hello.templ"}

Which indicates that the file has been set in the source map cache.
Later when the LSP tries to publish diagnostics, this error happens:

{"time":"2025-04-08T13:29:28.4259383+02:00","level":"INFO","msg":"client <- server: PublishDiagnostics"}
{"time":"2025-04-08T13:29:28.4259383+02:00","level":"INFO","msg":"client <- server: PublishDiagnostics: [0]","diagnostic":{"range":{"start":{"line":34,"character":65},"end":{"line":34,"character":73}},"severity":1,"code":"UndeclaredName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName"},"source":"compiler","message":"undefined: ajwskerf"}}
{"time":"2025-04-08T13:29:28.4259383+02:00","level":"ERROR","msg":"unable to complete because the sourcemap for the URI doesn't exist in the cache","uri":"file:///C:/Users/koppa.peter/GolandProjects/templtest/hello.templ"}

Seems, as if it was unable to find the file in the source map cache. I don't know if it's a logging issue, but in the log, that says the cache is being set, the file's uri contains c%3A instead of c:. Could be the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationIssue needs some investigation before being fixedbugSomething isn't workingwindows

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions