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: Autocomplete seems broken #816

Closed eikster-dk closed 6 days ago

eikster-dk commented 1 week ago

I'm unsure if it's templ or my setup, but it seems like the autocomplete functionality has stopped working. I'm currently using Neovim with lazyvim, and it has been working fine, but I updated both templ + my plugins, but afterwards, it doesn't work. I've been trying to downgrade to an earlier version with no luck, so I'm a bit confused if it's templ or somewhere in my config, even tho my config is pretty simple and only contains very very few tweaks to the default lazyvim setup.

Here are the logs from templ:

{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:392","msg":"completion: received items","count":6}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:420","msg":"client -> server: Completion end"}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/client.go:52","msg":"client <- server: PublishDiagnostics"}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/client.go:59","msg":"client <- server: PublishDiagnostics: [0]","diagnostic":{"range":{"start":{"line":37,"character":71},"end":{"line":37,"character":74}},"severity":1,"code":"UndeclaredImportedName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredImportedName"},"source":"compiler","message":"undefined: templ.Saf"}}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/client.go:83","msg":"diagnostic [0] rewritten","diagnostic":{"range":{"start":{"line":29,"character":16},"end":{"line":29,"character":19}},"severity":1,"code":"UndeclaredImportedName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredImportedName"},"source":"compiler","message":"undefined: templ.Saf"}}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:534","msg":"client -> server: DidChange","params":{"textDocument":{"uri":"file:///...../views/components/carousel/component.templ","version":42},"contentChanges":[{"text":"package carousel\n\ntype x struct {\n\tY  string\n\tYY string\n}\n\ntempl Carousel() {\n\t<div\n\t\tclass=\"w-full h-full\"\n\t\tx-data=\"{\n        init() {\n            new Splide(this.$refs.splide, {\n                autoplay: true,\n                pauseOnHover: true,\n                pauseOnFocus: true,\n                type: 'loop',\n                rewind: true,\n                arrows: false,\n                perPage: 1,\n                interval: 7000\n\n            }).mount()\n        },\n    }\"\n\t>\n\t\t<section x-ref=\"splide\" class=\"splide h-full\">\n\t\t\t<div class=\"splide__track h-full\">\n\t\t\t\t<div class=\"splide__list flex items-center\">\n        { templ.Safe}\n\t\t\t\t\t@Item() {\n\t\t\t\t\t\t<span>test</span>\n\t\t\t\t\t}\n\t\t\t\t\t@Item() {\n\t\t\t\t\t\t<span>test 2</span>\n\t\t\t\t\t}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</section>\n\t</div>\n}\n\ntempl Item() {\n\t<div class=\"splide__slide\">\n\t\t{ children... }\n\t</div>\n}\n"}]}}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:548","msg":"parsing template"}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:563","msg":"setting cache","uri":"file:///....../views/components/carousel/component.templ"}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:573","msg":"client -> server: DidChange end"}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:367","msg":"client -> server: Completion"}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:75","msg":"updatePosition: found","uri":"file:///..../views/components/carousel/component.templ","fromTempl":"29:20","toGo":"37:75"}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:392","msg":"completion: received items","count":6}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:420","msg":"client -> server: Completion end"}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/client.go:52","msg":"client <- server: PublishDiagnostics"}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/client.go:59","msg":"client <- server: PublishDiagnostics: [0]","diagnostic":{"range":{"start":{"line":37,"character":71},"end":{"line":37,"character":75}},"severity":1,"code":"UndeclaredImportedName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredImportedName"},"source":"compiler","message":"undefined: templ.Safe"}}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/client.go:83","msg":"diagnostic [0] rewritten","diagnostic":{"range":{"start":{"line":29,"character":16},"end":{"line":29,"character":20}},"severity":1,"code":"UndeclaredImportedName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredImportedName"},"source":"compiler","message":"undefined: templ.Safe"}}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:676","msg":"client -> server: DocumentHighlight"}
{"level":"info","ts":"2024-06-28T09:50:36+02:00","caller":"proxy/server.go:678","msg":"client -> server: DocumentHighlight end"}

So it looks like templ finds completions but nvim-cmp doesn't pick them up. Performing CmpStatus also shows that templ is ready as source and templ as LSP is running as I get type errors / hints within a templ file as well.

This morning I tried vsCode + templ and go plugin but vs code reports a code action error whenever I type something and want completions:

[Error - 09:49:17] Request textDocument/codeAction failed.
  Message: column is beyond end of line
  Code: 0 

So that's why I'm a bit puzzled.. Appreciate any help that can point me in the right direction

a-h commented 1 week ago

The codeAction issue is unrelated, see #801 and the PR #817 that fixes it. For that issue, I think that the VS Code extension has started checking for Code Actions more commonly, highlighting the issue, or gopls has started reporting when a text position is past the end of the line (unexpected since IIRC, the LSP spec says that servers should assume that if a position is past the end of the line, the client means the end of the line).

I use Neovim, and it's all working OK for me, including using the very latest version of templ. So I suspect it's something to do with your Neovim configuration.

If you want a reference implementation, my Neovim configuration is here: https://github.com/a-h/dotfiles/tree/master/.config/nvim/lua

I also recently updated all my plugins and Neovim version too, I use Nix for that, so all of the packages I use, including specific versions are defined here: https://github.com/a-h/dotfiles/blob/master/.config/nixpkgs/nvim.nix

eikster-dk commented 1 week ago

Alright, Thanks, @a-h. I will look at my configuration to see if I can figure out why it happens.