gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
17.77k stars 743 forks source link

Code Generation: Include file and line attribute #3149

Closed inoas closed 1 week ago

inoas commented 5 months ago

This would allow jumping from the generated source code to the gleam source file.

On target Erlang the file attribute could be used:

Setting File and Line

The same syntax as for module attributes is used for changing the pre-defined macros ?FILE and ?LINE:

-file(File, Line).

This attribute is used by tools, such as Yecc, to inform the compiler that the source program is generated by another tool. It also indicates the correspondence of source files to lines of the original user-written file, from which the source program is produced.

Source: https://www.erlang.org/doc/reference_manual/modules#setting-file-and-line

As one effect, this would help tools like stacky to allow jumping into the gleam source file from the stack trace.

lpil commented 5 months ago

On target JS if there is any standard solution, that could be used?

On JS they use sourcemaps, which is a much better solution and will give perfect results. We have an issue for this.