Skip to content

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

@rrousselGit

Description

@rrousselGit

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-pkgUsed for miscellaneous pkg/ packages not associated with specific area- teams.feature-macrosImplementation of the macros featurepkg-macrosThe experimental package:_macros librarytype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions