a-h / templ

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

Connection to server got closed. Server will not be restarted. (source: templ-vscode) #803

Closed WilfredDube closed 1 week ago

WilfredDube commented 1 week ago

Since yesterday my templ files can't be formatted by pressing: (Ctrl+Shift+I) in VS Code or VSCodium.

Screenshot from 2024-06-23 11-46-38

When the editors open the following error message pops up:

Screenshot from 2024-06-23 11-32-34

This is the output:

[Info  - 10:36:38 AM] 2024/06/23 10:36:38 Created View (#1)
    directory=/Projects/app
    view_type="GoMod"
    root_dir="file:///Projects/app"
    go_version="go version go1.22.2 linux/amd64"
    build_flags=[]
    env={GOOS:linux GOARCH:amd64 GOCACHE:/home/user/.cache/go-build GOMODCACHE:/home/user/go/pkg/mod GOPATH:/home/user/go GOPRIVATE: GOFLAGS: GO111MODULE: GoVersion:22 GoVersionOutput:go version go1.22.2 linux/amd64
 ExplicitGOWORK: EffectiveGOPACKAGESDRIVER:}
    env_overlay=[]

[Info  - 10:36:40 AM] 2024/06/23 10:36:40 go/packages.Load #1
    view_id="1"
    snapshot=0
    directory=/Projects/app
    query=[/Projects/app/... builtin]
    packages=16
    duration=1.986667775s

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

goroutine 56 [running]:
github.com/a-h/templ/cmd/templ/lspcmd/proxy.(*Server).CodeAction(0xc00008a4b0, {0xa55250, 0xc000250140}, 0xc000214ba0)
    /home/user/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({0xa55250, 0xc000250140}, {0xa5b300, 0xc00008a4b0}, 0xc0004529f0, {0xa55528, 0xc000216440})
    /home/user/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({0xa55250, 0xc000250140}, 0xc0004529f0, {0xa55528, 0xc000216440})
    /home/user/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({0xa55250, 0xc000250140}, 0xc00020e0f0, {0xa55528, 0xc000216440})
    /home/user/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:35 +0xc6
github.com/a-h/protocol.Handlers.AsyncHandler.func2.2()
    /home/user/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 11
    /home/user/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:112 +0x165
[Error - 10:36:41 AM] Server process exited with code 2.
[Error - 10:36:41 AM] Connection to server got closed. Server will not be restarted.

I reinstalled the templ extension and added this in my settings.json but nothing works. It has been working well before and I can't trace back the steps that got me to this point.

{
    "editor.formatOnSave": true,
    "[templ]": {
        "editor.defaultFormatter": "a-h.templ"
    },
}

These are some of extension settings for templ. I'm not sure what I'm supposed to do here. Screenshot from 2024-06-23 11-43-22

prencher commented 1 week ago

Seeing the same on macOS with the latest VS Code (v1.90), Go extension (v0.41.4, gopls v0.16.0, go v1.22.3), and templ-vscode extension (v0.0.25, templ v0.2.707).

rAlexander89 commented 1 week ago

same

joerdav commented 1 week ago

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

prencher commented 1 week ago

Unfortunately changing to main now causes the issues outlined in #801.

For anybody else looking for a fix for this and running into issues after changing to main, follow along on that issue.