mhanberg
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
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











First 4 of 4 Posts
josevalim
What you could try to do is to set columns: true in the parser options and then see if there is a column in the metadata. IIRC, generated code does not have column information attached to it.
mhanberg
That doesn’t seem to be the case from what I’ve observed.
Just to confirm, these are the traces generated from the following piece of code
Code
Traces
You can note that the Kernel.to_string trace from the string interpolation is emitted as
{:remote_macro, [closing: [line: 9, column: 17], line: 9, column: 12], Kernel, :to_string, 1}and the function and alias traces from the macro are emitted with column information as well.Full code located here.
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. Notefrom_bracketsis also used whenfoo[bar]becomesAccess.get. The full list is here: Macro — Elixir v1.20.2mhanberg
You are amazing
.
Thank you!