sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Macros: Add a way to obtain the StackTrace responsible for generating a code.

Open rrousselGit opened this issue 1 year ago • 3 comments

Hello!

Problem

When using code-generators, one challenge is: It's difficult to know what line was responsible for the generation of a piece of code.

Code-generators can become quite complex. It can take a lot of time to find exactly which line was responsible for generating a specific code.

Proposal

It would be interesting to have a "jump to the macro code that generated this line".
Since macros don't actually write to the file system but rather use some virtual file ; we could use this as an opportunity to store extra metadata.

Specifically, we could associate any piece of generated code with a Stacktrace that points to the exact line responsible for this generation.
The IDE could then use this StackTrace to jump to the macro code ; how could display the whole stacktrace to help debugging.

Of course, accessing the StackTrace can be slow. For the sake of efficiency, I see two possible solutions:

  • Gate this behind a flag ; be it an IDE config or an analysis_options.yaml config or something else
  • Alternatively, we could decide not to collect stacktraces initially. And whenever a the IDE requests for a stacktrace at a given offset, we could re-execute macros that were applied on a file, with StackTrace collection enabled. Considering a macro should have a deterministic output, this shouldn't cause the IDE to jump to the wrong file/line.

rrousselGit avatar Oct 18 '24 14:10 rrousselGit