mhanberg

mhanberg

Creator of elixir-tools

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

josevalim

Creator of Elixir

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

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New

We're in Beta

About us Mission Statement