Closed garrettladley closed 1 day ago
Hi @garrettladley thanks for the error report. This is expected as some of the imports being "magic" was causing a few issues and confusion, as well as making some logic a bit more complicated than it needed to be, so we have removed any standard library packages from being "magically" imported to templ files.
I expect that the reason you are seeing an error in the LSP is that the templ binary that is being used as an LSP is different to the one you are using for templ generate
.
But in short yes, this is expected.
Hey @joerdav, thanks for getting back to me! Just for my understanding, when was this change made? I don't see anything mentioning context or imports in any of the recent changelogs. Also, I checked the docs before opening this issue and they didn't mention this change/new feature. The below linked pages about context still suggest using the implicit ctx
. I'd be happy to raise a PR with the update.
It was in the last release https://github.com/a-h/templ/releases/tag/v0.2.731 here's the commit: https://github.com/a-h/templ/pull/793
It's maybe not obvious the side effects of this change, but since the formatter should fix any issues we accepted the risk.
Absolutely happy to take a PR for clarifying the docs too :)
this code that previously worked is now erroring on
templ generate
with reasonpath/to/file_templ.go:[line]:[col]: undefined: context
on my local i had been using v0.2.707, but, in my pipeline i was using a
go install github.com/a-h/templ/cmd/templ@latest
which at the time of writing this is v0.2.731(yes probably my fault to not update my local/pin my pipeline version)
original simplified example code:
in the fix, i simply import context. however, the LSP yells at me in the import statement saying
"context" imported and not used
and within Index it sayscontext redeclared in this block
.i'm fine with this fix since my templ generate and subsequent pipeline steps work again, was just wondering if this change was intended or is a regression