Skip to content

Commit

Permalink
Include column information on definition metadata
Browse files Browse the repository at this point in the history
Closes #13029.
  • Loading branch information
josevalim committed Oct 23, 2023
1 parent e94ff76 commit 09946ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/elixir/src/elixir_def.erl
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,16 @@ store_definition(Kind, HasNoUnquote, Call, Body, #{line := Line} = E) ->
%% extract meta information like file and context.
{_, Meta, _} = Call,

Context = case lists:keyfind(context, 1, Meta) of
{context, _} = ContextPair -> [ContextPair];
Column = case lists:keyfind(column, 1, Meta) of
{column, _} = ColumnPair -> [ColumnPair];
_ -> []
end,

Context = case lists:keyfind(context, 1, Meta) of
{context, _} = ContextPair -> [ContextPair | Column];
_ -> Column
end,

Generated = case lists:keyfind(generated, 1, Meta) of
{generated, true} -> ?generated(Context);
_ -> Context
Expand Down
6 changes: 4 additions & 2 deletions lib/elixir/test/elixir/module_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,14 @@ defmodule ModuleTest do
in_module do
def foo(a, b), do: a + b

assert {:v1, :def, _,
assert {:v1, :def, def_meta,
[
{_, [{:a, _, nil}, {:b, _, nil}], [],
{clause_meta, [{:a, _, nil}, {:b, _, nil}], [],
{{:., _, [:erlang, :+]}, _, [{:a, _, nil}, {:b, _, nil}]}}
]} = Module.get_definition(__MODULE__, {:foo, 2})

assert [line: _, column: _] = Keyword.take(def_meta, [:line, :column])
assert [line: _, column: _] = Keyword.take(clause_meta, [:line, :column])
assert {:v1, :def, _, []} = Module.get_definition(__MODULE__, {:foo, 2}, skip_clauses: true)

assert Module.delete_definition(__MODULE__, {:foo, 2})
Expand Down

0 comments on commit 09946ee

Please sign in to comment.