-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/tools/gopls: autocompletion and highlighting for template variables, like GoLand's gotype #64385
Comments
Checked in some very rough work on this here and am pausing on it for now as I couldn't figure out deeply nested fields: golang/tools#462 , it feels like it's possible, although my POC may be very unpalatable. |
This is an interesting idea, but I don't think we should require users to make ad-hoc changes to the text of their templates to enable this kind of tooling assistance. Either the tool should figure out what type of value is passed to the template evaluator, or there should be a standard way to declare this relation. Having the tool deduce the type seems tractable in simple cases. If the source contains a call to t = template.Parse followed by t.Execute, then the two can be reconciled. It gets trickier when the flow of values from Parse to Execute is more complicated, or goes through //go:embed. The standard way has the benefit of being more robust. Also, we could then write a vet check that would statically detect ill-formed templates, and gopls could run it in real time as you edit. Of course, it would require a proposal to change the template package. |
Sadly I am both using I was thinking that an explicit config (in |
I've filed a proposal (#64543) to solicit requirements for an annotation mechanism sufficient to express the most common cases that users care about. |
gopls version
v0.14.2
go env
What did you do?
Configured VSCode to support Go templates with gopls.
What did you expect to see?
A way to tell
gopls
the types of my template variables, and have those types reflected in highlighting and autocomplete. GoLand does this with comments (ref https://www.jetbrains.com/help/go/integration-with-go-templates.html). I think the comments are slightly ugly, so not sure how to address that. Having a way for my custom template functions to work too would be great but isn't as critical.Besides being good for DX, I think this could catch a ton of typing errors in templates. I currently use https://github.com/jba/templatecheck for that in tests, but that won't help me when viewing/writing tempalte code.
This was referenced in this issue by @a-h : #36911, but wasn't really followed up on, which is why I'm filing this feature request.
What did you see instead?
No highlighting or autocomplete for template variable types. Hovering over template variables or functions just says
field or method
.Editor and settings
VSCode with this config:
Logs
No response
The text was updated successfully, but these errors were encountered: