mhanberg
Knowledge of generated code from compilation tracers
I use the compilation tracers for Next LS to power its symbol/reference database used for definition/references/hover/workspace symbols etc.
Is there a way (or could there be a way) to know if a function/macro reference is from generated code?
Example
Consider the following code
%GenLSP.Structures.Hover{
contents: %GenLSP.Structures.MarkupContent{
kind: GenLSP.Enumerations.MarkupKind.markdown(),
value: """
# #{module}
^ hover on this location
#{docs}
"""
},
range: %Range{
start: %Position{line: startl - 1, character: startc - 1},
end: %Position{line: endl - 1, character: endc - 1}
}
}
With the tracers as they are today, if you were to hover on the above location, you would see the documentation for Kernel.to_string/1 as seen here
Now this particular example is because string interpolation syntax is compiled into something similar to <<"# ", to_string(module)::binary>> (I think the particulars of this is incorrect, but it is the gist of it).
Now, I wouldn’t consider this a huge problem, except that the range for this “reference” overlaps with the text of the variable binding module, which will interfere with using definition/references on that.
Question
So my question to end this is, is there a way the code from the trace is actually present in the source code?
cc @josevalim
Thanks!
PS: The mailing list details itself as the place to open proposals, and GitHub issues are for actual bugs, so I think Elixir Forum is still the place to ask clarifying questions like this. Please let me know if that understanding is incorrect
Marked As Solved
josevalim
Thank you, apparently it was on my mind to implement this, but I never did. I just pushed a commit to main that addresses the Enum case.
For the string one, there is now a special key called from_interpolation. Note from_brackets is also used when foo[bar] becomes Access.get. The full list is here: Macro — Elixir v1.15.5









