Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp error when ı reload or open templ file #800

Closed
BeratHundurel opened this issue Jun 21, 2024 · 8 comments
Closed

lsp error when ı reload or open templ file #800

BeratHundurel opened this issue Jun 21, 2024 · 8 comments

Comments

@BeratHundurel
Copy link

BeratHundurel commented Jun 21, 2024

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

@BeratHundurel BeratHundurel changed the title lsp error when ı try to format the page lsp error when ı reload or open templ file Jun 21, 2024
@FernandoAcTr
Copy link

FernandoAcTr commented Jun 21, 2024

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
Copy link

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
Copy link

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

@tim-rus
Copy link

tim-rus commented Jun 22, 2024

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
Copy link
Collaborator

joerdav commented Jun 22, 2024

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
Copy link

advdv commented Jun 25, 2024

@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: #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:

  • Close down vscode, run: go install golang.org/x/tools/gopls@v0.15.3
  • If you've tinkered with the templ binary, re-install the latest stable version: go install github.com/a-h/templ/cmd/templ@v0.2.707
  • if you've switched to @main in go mod, revert templ to the stable version, eg: require ( github.com/a-h/templ v0.2.707 )
  • recompile with templ generate
  • restart vscode

@EmmanuelOga
Copy link

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
Copy link
Owner

a-h commented Jun 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants