Skip to content

Commit

Permalink
Revert docs.ex changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aleDsz committed Aug 23, 2024
1 parent fed73dc commit f15627a
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions lib/livebook/intellisense/docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -186,29 +186,26 @@ defmodule Livebook.Intellisense.Docs do
The function returns the line where the identifier is located.
"""
@spec locate_definition(list() | binary(), definition()) :: {:ok, pos_integer()} | :error
def locate_definition(path_or_bytecode, identifier)
def locate_definition(path, identifier)

def locate_definition(path_or_bytecode, {:module, module}) do
with {:ok, {:raw_abstract_v1, annotations}} <-
beam_lib_chunks(path_or_bytecode, :abstract_code) do
def locate_definition(path, {:module, module}) do
with {:ok, {:raw_abstract_v1, annotations}} <- beam_lib_chunks(path, :abstract_code) do
{:attribute, anno, :module, ^module} =
Enum.find(annotations, &match?({:attribute, _, :module, _}, &1))

{:ok, :erl_anno.line(anno)}
end
end

def locate_definition(path_or_bytecode, {:function, name, arity}) do
with {:ok, {:debug_info_v1, _, {:elixir_v1, meta, _}}} <-
beam_lib_chunks(path_or_bytecode, :debug_info),
def locate_definition(path, {:function, name, arity}) do
with {:ok, {:debug_info_v1, _, {:elixir_v1, meta, _}}} <- beam_lib_chunks(path, :debug_info),
{_pair, _kind, kw, _body} <- keyfind(meta.definitions, {name, arity}) do
Keyword.fetch(kw, :line)
end
end

def locate_definition(path_or_bytecode, {:type, name, arity}) do
with {:ok, {:raw_abstract_v1, annotations}} <-
beam_lib_chunks(path_or_bytecode, :abstract_code) do
def locate_definition(path, {:type, name, arity}) do
with {:ok, {:raw_abstract_v1, annotations}} <- beam_lib_chunks(path, :abstract_code) do
fetch_type_line(annotations, name, arity)
end
end
Expand All @@ -223,8 +220,8 @@ defmodule Livebook.Intellisense.Docs do
end
end

defp beam_lib_chunks(path_or_bytecode, key) do
case :beam_lib.chunks(path_or_bytecode, [key]) do
defp beam_lib_chunks(path, key) do
case :beam_lib.chunks(path, [key]) do
{:ok, {_, [{^key, value}]}} -> {:ok, value}
_ -> :error
end
Expand Down

0 comments on commit f15627a

Please sign in to comment.