Support .templ files with Go auto complete etc
Req23 opened this issue · comments
When trying to work on a .tmpl
file in a Go project I lose auto completion on structs/packages etc. Also the imports are not found resulting in a warning/error in VSCode.
example:
/views/login/index.templ
package login
import (
"app/models"
)
templ LoginForm(errors models.LoginError) {
<form>
***
<input type="password" name="password" required placeholder="Password" class="input input-bordered w-full"/>
if len(errors.Password) > 0 {
<span class="text-sm text-error">
{ errors.Password }
</span>
}
***
errors.Password
(the errors struct has multiple items, this does not do code auto completion or suggestions)
The package error shows: No packages found for open file /views/login/index.templ
even though this is incorrect as the package is valid.
I would like the IDE in VSCode to be able to handle all the auto completions etc as if it was a .go
file.
I guess you are using a-h/templ. Isn't the templ extension able to handle auto-complete?
https://templ.guide/commands-and-tools/ide-support/#visual-studio-code
cc @a-h
Yeah I am using a-h/templ
along with the vscode-go
extension. I followed the guide for VSC with vscode-go + a-h/templ. I thought maybe the go side of it was responsible for the imports, auto completes, etc.
Auto completion is working with:
gopls v. 0.15.3
and
a-h/templ from @main
The newest version of gopls and templ didn't seem to work together. Just letting you know what I found.
Thanks @Req23. That's helpful!
I don't know the details on how templ
LSP server proxies gopls.
gopls v0.16.0+ started to use InsertReplaceEdits
if the client sets the capability. (https://github.com/golang/tools/blob/master/gopls/internal/protocol/tsprotocol.go#L1024).
If the templ
LSP relies on github.com/a-h/protocol, I see that it does not handle InsertReplaceEdits
type yet
(https://github.com/a-h/protocol/blob/b4eec67c1c223e5a747d39f3d07f62d25236aa4a/language.go#L260).
I think the templ
LSP server needs to either
- update the protocol to support
InsertReplaceEdits
, or - adjust the client capability so
InsertReplaceSupport
is unset before forwarding the capability.
Can you please open an issue to the a-h/templ repo? Thanks!