-
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: ctrl-click should jump to source, not to autogenerated code #65001
Comments
This would require something akin to sourcemaps. |
@icholy templ does in fact maintain sourcemaps, I think the main question is around whether templ can hook in to gopls to override the jump to definition, or if it would require using templ as the main lsp for go code (which I don't think would be ideal) |
So, a while back gopls would maintain two positions for every position: the "compiled" position, and whichever position was referenced by A cleaner solution would be to only handle line directives at API boundaries, for example in a Does templ produce |
Currently templ does not produce line directives. Though, I believe it could quite easily, as a source map is already maintained. I imagine it would look something like this in a generated file, if I understand correctly (index_templ.go): //line index.templ:20
func Index() templ.Component {
... |
@joerdav yes, that looks right. |
I'll give this a go in templ. Given that this isn't currently supported in gopls does the compiler directive have any effect at the moment? |
The compiler directive may affect the location of error messages. Since I wouldn't expect generated code to have errors, this may not matter. Can you point me to an example of templ's current sourcemaps? |
Cool makes sense, ah I think you're talking about some sourcemap files, whereas templ only really holds it in memory for LSP purposes: https://github.com/a-h/templ/blob/main/parser/v2/sourcemap.go |
@findleyr We currently are processing a PR in templ to add I've also done a proof-of-concept to check if this is possible in gopls, I fully would intend to tidy this up and add tests, but just wanted to check if I was on the right track here: joerdav/tools@63456ed This does work on an example project. |
gopls version
(does not matter here)
go env
What did you do?
I use Go, vscode and templ.guide
The tool
templ
creates Go code from templates.I am looking at my Go file and I use a function which was auto-generated by
templ
:If I ctrl-click on
page()
then ...then I get to the autogenerated Go code:
It would be great if I could get to the templ-file instead:
As a user, the experience is not great, because I would like to jump to the original source (the templ template).
Does gpls provide hooks, which templ could implement, so that ctrl-click jumps directly to the templ template?
Related issue: a-h/templ#387
The text was updated successfully, but these errors were encountered: