Closed DreamwareDevelopment closed 1 week ago
You're using a version of templ from April, and likely using a newer version of gopls which templ didn't support (because it hadn't come out yet).
Can you install the latest version of templ and try again please?
I upgraded and then removed the older versions of templ so that I only have:
a-h ⚡pwd
/Users/zander/go/pkg/mod/github.com/a-h
a-h ⚡ls
lexical@v0.0.53 protocol@v0.0.0-20230224160810-b4eec67c1c22
parse@v0.0.0-20240121214402-3caf7543159a templ@v0.2.747
In my system. However, after uninstalling the extension then reinstalling I see:
[Info - 5:33:49 PM] 2024/07/05 17:33:49 go/packages.Load #1
view_id="1"
snapshot=0
directory=/Users/zander/Documents/Code/PMap/pmap-api
query=[/Users/zander/Documents/Code/PMap/pmap-api/apps/account-service/... /Users/zander/Documents/Code/PMap/pmap-api/apps/account-service/e2e/... /Users/zander/Documents/Code/PMap/pmap-api/apps/api-gateway/... /Users/zander/Documents/Code/PMap/pmap-api/apps/query-service/... /Users/zander/Documents/Code/PMap/pmap-api/apps/query-service/e2e/... /Users/zander/Documents/Code/PMap/pmap-api/apps/renderer-service/... /Users/zander/Documents/Code/PMap/pmap-api/apps/renderer-service/e2e/... /Users/zander/Documents/Code/PMap/pmap-api/libs/go-utils/... builtin]
packages=31
duration=649.70325ms
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x10 pc=0x10250f4bc]
goroutine 36 [running]:
github.com/a-h/templ/cmd/templ/lspcmd/proxy.(*Server).CodeAction(0x140000be050, {0x1026fe0b0, 0x140001d0140}, 0x140001869c0)
/Users/zander/go/pkg/mod/github.com/a-h/templ@v0.2.663/cmd/templ/lspcmd/proxy/server.go:293 +0x35c
github.com/a-h/protocol.serverDispatch({0x1026fe0b0, 0x140001d0140}, {0x102702000, 0x140000be050}, 0x14000a984e0, {0x1026fe388, 0x140001886c0})
/Users/zander/go/pkg/mod/github.com/a-h/protocol@v0.0.0-20230224160810-b4eec67c1c22/server.go:158 +0x3e60
github.com/a-h/protocol.NewServer.ServerHandler.func1({0x1026fe0b0, 0x140001d0140}, 0x14000a984e0, {0x1026fe388, 0x140001886c0})
/Users/zander/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({0x1026fe0b0, 0x140001d0140}, 0x14000180690, {0x1026fe388?, 0x140001886c0?})
/Users/zander/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:35 +0xdc
github.com/a-h/protocol.Handlers.AsyncHandler.func2.2()
/Users/zander/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 22
/Users/zander/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:112 +0x194
[Error - 5:33:49 PM] Connection to server got closed. Server will not be restarted.
[Error - 5:33:49 PM] Server process exited with code 2.
This is extremely strange because I'm certain that version doesn't exist in my filesystem anymore:
pmap-api ⚡cd /Users/zander/go/pkg/mod/github.com/a-h/templ@v0.2.663
cd: no such file or directory: /Users/zander/go/pkg/mod/github.com/a-h/templ@v0.2.663
I think the extension (lspcmd/proxy) may be caching the package itself?
I don't understand how these language server extensions work, so please bear with me.
Not sure if it helps, but sometimes people forget that they're running in a VS Code dev container that has different tools in it, or are running in WSL and haven't updated there.
I think it might be a good idea to add a diagnosis feature to the VS Code extension to print out information about the environment.
Yeah I don't use a dev container nor WSL. Still not sure what's happening here. Just coding without autocomplete for now.
The go install
command usually installs templ into a location on your system path. The VS Code extension looks in a number of locations to find the templ
executable, so it could be that you have a couple of versions of templ
in different places.
There's no relationship between the version of templ you have installed in your project (as a library), and the templ binary that is somewhere in your system path.
If you run which templ
, you should see where the templ
binary is installed. And if you run templ version
you should be able to see which version of templ you're running.
this error is on windows, if you do it in WSL it works fine
@JohnKinyanjui - are you and @DreamwareDevelopment the same person? Because the information provided by @DreamwareDevelopment shows Unix style file system path separators, not windows style backslashes.
nope we are not, i had the same issues tried different version of templ and also tried to reinstall golang it didnt work ( did all this on windows) but when i tried using WSL and vscode it worked all of a sudden
Oooh now i see the confusion this how it looks for windows
[Info - 8:25:40 PM] 2024/07/07 20:25:40 Created View (#1)
directory=D:\PProjects\bookme_backend
view_type="GoWork"
root_dir="file:///D:/PProjects/bookme_backend"
go_version="go version go1.22.5 windows/amd64"
build_flags=[]
env={GOOS:windows GOARCH:amd64 GOCACHE:C:\Users\hp\AppData\Local\go-build GOMODCACHE:C:\Users\hp\go\pkg\mod GOPATH:C:\Users\hp\go GOPRIVATE: GOFLAGS: GO111MODULE: GOTOOLCHAIN:auto GoVersion:22 GoVersionOutput:go version go1.22.5 windows/amd64
ExplicitGOWORK: EffectiveGOPACKAGESDRIVER:}
env_overlay=[]
[Info - 8:25:43 PM] 2024/07/07 20:25:43 go/packages.Load #1
view_id="1"
snapshot=0
directory=D:\PProjects\bookme_backend
query=[D:\PProjects\bookme_backend\... builtin]
packages=44
duration=3.2221776s
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x10 pc=0x115a7c0]
goroutine 30 [running]:
github.com/a-h/templ/cmd/templ/lspcmd/proxy.(*Server).CodeAction(0xc0000960a0, {0x133ae50, 0xc000494140}, 0xc0004b2600)
C:/Users/hp/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({0x133ae50, 0xc000494140}, {0x1341150, 0xc0000960a0}, 0xc000492e70, {0x133b128, 0xc00011c600})
C:/Users/hp/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({0x133ae50, 0xc000494140}, 0xc000492e70, {0x133b128, 0xc00011c600})
C:/Users/hp/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({0x133ae50, 0xc000494140}, 0xc000132b88, {0x133b128, 0xc00011c600})
C:/Users/hp/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:35 +0xc6
github.com/a-h/protocol.Handlers.AsyncHandler.func2.2()
C:/Users/hp/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 23
C:/Users/hp/go/pkg/mod/go.lsp.dev/jsonrpc2@v0.10.0/handler.go:112 +0x165
[Error - 8:25:43 PM] Connection to server got closed. Server will not be restarted.
[Error - 8:25:43 PM] Server process exited with code 2.
@JohnKinyanjui - it's hard to see in the log noise, but it's saying it's running templ@v0.2.707
Like I say, the most common problem is not having stuff installed in WSL.
I might update the VS Code extension to auto download templ and install gopls if it can't be found. I think that would solve a lot of problems.
Ok, i update the templ cli using go install github.com/a-h/templ/cmd/templ@latest and its fixed but just make it easier i would suggest something like "templ update" so whenever an older version is running it would recommend to run the command
Go install fixed the issue for me as well, thank you! I'll let you close this @a-h in case you wanted to make changes to the extension under this issue.
EDIT: I just started getting this error in templ files:
could not import github.com/a-h/templ/runtime (no required module provides package "github.com/a-h/templ/runtime")
EDIT 2: I had a 7.07 version in my local module. Upgrading and installing the runtime package fixed it
Thanks a lot folks. You're not the only ones to get tripped up on versions and setup, so I've done a PR for a new templ diagnose
command that should help with future investigations. https://github.com/a-h/templ/pull/840
Once that's in templ, we can add a new feature to the IDE integrations to call it, and print out the results, as a pathway to (in the future) possibly installing updates automatically.
re: the could not import
error, the templ generate
command already prints a warning if the version in the go.mod
file is different to the CLI version, and that warning should also be present in the editors... If we see more of the same issue, I'll investigate further.
Can't get syntax highlighting and autocomplete to work on VSCode because of this. I've quit VSCode, reinstalled the templ extension, no dice.