a-h / templ

A language for writing HTML user interfaces in Go.
https://templ.guide/
MIT License
7.14k stars 236 forks source link

lsp error when ı reload or open templ file #800

Closed BeratHundurel closed 1 week ago

BeratHundurel commented 1 week ago

I am getting an error in VS Code that says 'connection to server got closed' when I reload the page or open new templ file. I logged the error and found this error message: 'unable to complete because the sourcemap for the URI doesn't exist in the cache.'

I will attach the log file. Also, in the command line, I am able to execute commands like "templ lsp --help", and "which go gopls templ" command give me correct results. templ.log

FernandoAcTr commented 1 week ago

I'm facing the same issue. Any idea how to fix it? This is what I have go version go1.22.2 darwin/arm64

goroutine 64 [running]:
github.com/a-h/templ/cmd/templ/lspcmd/proxy.(*Server).CodeAction(0x1400020a050, {0x102e31470, 0x140000f8870}, 0x1400028f680)
    /Users/lacosta/go/pkg/mod/github.com/a-h/templ@v0.2.707/cmd/templ/lspcmd/proxy/server.go:294 +0x358
github.com/a-h/protocol.serverDispatch({0x102e31470, 0x140000f8870}, {0x102e36880, 0x1400020a050}, 0x140001bf740, {0x102e31748, 0x14000165500})
    /Users/lacosta/go/pkg/mod/github.com/a-h/protocol@v0.0.0-20230224160810-b4eec67c1c22/server.go:158 +0x3e14
github.com/a-h/protocol.NewServer.ServerHandler.func1({0x102e31470, 0x140000f8870}, 0x140001bf740, {0x102e31748, 0x14000165500})
    /Users/lacosta/go/pkg/mod/github.com/a-h/protocol@v0.0.0-20230224160810-b4eec67c1c22/server.go:36 +0x6c
github.com/a-h/protocol.Handlers.ReplyHandler.func1({0x102e31470, 0x140000f8870}, 0x14000129188, {0x102e31748, 0x14000165500})
    /Users/lacosta/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:35 +0xc0
github.com/a-h/protocol.Handlers.AsyncHandler.func2.2()
    /Users/lacosta/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:114 +0x78
created by github.com/a-h/protocol.Handlers.AsyncHandler.func2 in goroutine 9
    /Users/lacosta/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:112 +0x164
[Error - 13:45:17] Server process exited with code 2.
[Error - 13:45:17] Connection to server got closed. Server will not be restarted.
DarioDT75 commented 1 week ago

I'm affected too. go version go1.22.1 darwin/amd64 VS Code reports:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xb79c620]

goroutine 42 [running]:
github.com/a-h/templ/cmd/templ/lspcmd/proxy.(*Server).CodeAction(0xc000146050, {0xb980730, 0xc0000b2000}, 0xc0003af620)
    /Users/dark/go/pkg/mod/github.com/a-h/templ@v0.2.707/cmd/templ/lspcmd/proxy/server.go:294 +0x480
github.com/a-h/protocol.serverDispatch({0xb980730, 0xc0000b2000}, {0xb985a20, 0xc000146050}, 0xc0005008d0, {0xb980a08, 0xc0000b0000})
    /Users/dark/go/pkg/mod/github.com/a-h/protocol@v0.0.0-20230224160810-b4eec67c1c22/server.go:158 +0x4013
github.com/a-h/protocol.NewServer.ServerHandler.func1({0xb980730, 0xc0000b2000}, 0xc0005008d0, {0xb980a08, 0xc0000b0000})
    /Users/dark/go/pkg/mod/github.com/a-h/protocol@v0.0.0-20230224160810-b4eec67c1c22/server.go:36 +0x7e
github.com/a-h/protocol.Handlers.ReplyHandler.func1({0xb980730, 0xc0000b2000}, 0xc0003c8078, {0xb980a08, 0xc0000b0000})
    /Users/dark/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:35 +0xc6
github.com/a-h/protocol.Handlers.AsyncHandler.func2.2()
    /Users/dark/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:114 +0x76
created by github.com/a-h/protocol.Handlers.AsyncHandler.func2 in goroutine 25
    /Users/dark/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:112 +0x165
[Error - 2:06:41 PM] Server process exited with code 2.
[Error - 2:06:41 PM] Connection to server got closed. Server will not be restarted.

gopls.log templ.log

DarioDT75 commented 1 week ago

Update: in a machine that was working fine, it started to happen once gopls was updated to 0.16.0

tim-rus commented 1 week ago

Update: in a machine that was working fine, it started to happen once gopls was updated to 0.16.0

Yeap. Rolled back to gopls@v0.15.3 and that fixed the problem. Thnx.

joerdav commented 1 week ago

This has been fixed in mainline, so should be resolved in the next release. Alternatively you can install mainline now go install github.com/a-h/templ/cmd/templ@main

advdv commented 1 week ago

@a-h @joerdav sorry for pinging but I think it might be worth it to roll a new release just to fix this because changing to the mainline release "@main" triggers this issue: https://github.com/a-h/templ/issues/801. Or maybe create a pinned issue to advise users to prevent new issues from being created for the same problem, e.g:

For others, I think the best way currently is to downgrade gopls to 0.15.3:

EmmanuelOga commented 1 week ago

Thank you @advdv, just chiming in to say I'm getting the exact same issue and I was wondering how to fix it :-)

a-h commented 1 week ago

Fixed in https://github.com/a-h/templ/releases/tag/v0.2.731