Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column info in Module.get_definition/2 #13029

Closed
mhanberg opened this issue Oct 22, 2023 · 4 comments
Closed

Column info in Module.get_definition/2 #13029

mhanberg opened this issue Oct 22, 2023 · 4 comments

Comments

@mhanberg
Copy link
Contributor

Originally opened on the Elixir Forum (https://elixirforum.com/t/how-to-find-function-clause-column-information/59177), cross posting here at the request of Jose.


Currently I am able to acquire the line for a function clause definition using the :on_module tracer event, similar to the following code

  def trace({:on_module, bytecode, _}, env) do
    defs = Module.definitions_in(env.module)

    defs =
      for {name, arity} = _def <- defs do
        {name, Module.get_definition(env.module, {name, arity})}
      end
  
    :ok
  end

When I eventually loop through each function and its clauses, I get a structure that looks like this:

{[line: 943], ["defmodule"], [],
 {{:., [line: 943, column: 80], [GenLSP.Enumerations.SymbolKind, :module]},
  [closing: [line: 943, column: 88], line: 943, column: 81], []}}

which corresponds to the following code snippet:

  defp elixir_kind_to_lsp_kind("defmodule"), do: GenLSP.Enumerations.SymbolKind.module()

As you can see here, the metadata includes the line [line: 943], but not the column. I currently use columns: true for the compiler options, but the column doesn't seem to show up here.

Would you know if I'm doing something wrong here?

@josevalim
Copy link
Member

Can you please provide a small app or script that reproduces this btw? :)

@mhanberg
Copy link
Contributor Author

Yes, I'll get you that today!

@mhanberg
Copy link
Contributor Author

@josevalim luckily I already had a demo app that was 90% of the way there: https://github.com/mhanberg/tracer_demo

Thanks!

@mhanberg
Copy link
Contributor Author

Thanks José!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants