templ icon indicating copy to clipboard operation
templ copied to clipboard

generator: Implement the go line compiler directive in generated files

Open joerdav opened this issue 2 years ago • 0 comments

There is a Go compiler directive //line, which can be used to reference other files. Historically gopls would support this directive, but subsequently dropped support https://github.com/golang/go/issues/55043

There is an issue in gopls to propose reintroducing this https://github.com/golang/go/issues/65001

It could be valuable for templ to implement this directive for the future, so that if this directive is implemented in gopls it'll work with generated templ files.

Solution

In *_templ.go files, all symbols that could be referenced by .go files should be defined with the //line directive, for example:

Generated file

//line index.templ:20
func Index() templ.Component {
...

This should apply to code generated by all keywords templ, css and script.

joerdav avatar Jan 10 '24 13:01 joerdav