gleam icon indicating copy to clipboard operation
gleam copied to clipboard

Code Generation: Include file and line attribute

Open inoas opened this issue 1 year ago • 1 comments

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.

  • On target JS if there is any standard solution, that could be used? Otherwise we can just setup a convention?
  • Optional: Maybe the compiler could be told to not include such details for security reasons, by a compiler flag, or is this a no-issue if the pathes are relative not absolute?

inoas avatar May 17 '24 18:05 inoas

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.

lpil avatar May 17 '24 21:05 lpil