Skip to content

Commit

Permalink
do not return types and callbacks on docs
Browse files Browse the repository at this point in the history
this was never used by downstream
  • Loading branch information
lukaszsamson committed Jul 20, 2023
1 parent 4c6941a commit 89905d4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 247 deletions.
4 changes: 1 addition & 3 deletions lib/elixir_sense.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ defmodule ElixirSense do
...> MyEnum.to_list(1..3)
...> end
...> '''
iex> %{docs: %{types: types, docs: docs}} = ElixirSense.docs(code, 3, 11)
iex> %{docs: %{docs: docs}} = ElixirSense.docs(code, 3, 11)
iex> docs |> String.split("\n") |> Enum.at(8)
"Converts `enumerable` to a list."
iex> types |> String.split("\n") |> Enum.at(4)
"@type default :: any"
"""
@spec docs(String.t(), pos_integer, pos_integer) ::
%{
Expand Down
45 changes: 4 additions & 41 deletions lib/elixir_sense/core/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ defmodule ElixirSense.Core.Introspection do

@type mod_fun :: {module | nil, atom | nil}
@type markdown :: String.t()
@type mod_docs :: %{docs: markdown, types: markdown, callbacks: markdown}
@type fun_docs :: %{docs: markdown, types: markdown}
@type docs :: mod_docs | fun_docs
@type docs :: %{docs: markdown}

@type module_subtype ::
:exception | :protocol | :implementation | :behaviour | :struct | :task | :alias | nil
Expand Down Expand Up @@ -125,7 +123,7 @@ defmodule ElixirSense.Core.Introspection do
end

def get_all_docs({mod, nil}, :mod_fun, _) do
%{docs: get_docs_md(mod), types: get_types_md(mod), callbacks: get_callbacks_md(mod)}
%{docs: get_docs_md(mod)}
end

def get_all_docs({mod, fun}, :mod_fun, _scope) do
Expand All @@ -138,7 +136,7 @@ defmodule ElixirSense.Core.Introspection do
Enum.join(docs, "\n\n---\n\n") <> "\n"
end

%{docs: docs, types: get_types_md(mod)}
%{docs: docs}
end

def get_all_docs({mod, fun}, :type, scope) do
Expand All @@ -151,7 +149,7 @@ defmodule ElixirSense.Core.Introspection do
Enum.join(docs, "\n\n---\n\n") <> "\n"
end

%{docs: docs, types: get_types_md(mod)}
%{docs: docs}
end

def count_defaults(nil), do: 0
Expand Down Expand Up @@ -532,41 +530,6 @@ defmodule ElixirSense.Core.Introspection do
end
end

def get_types_md(mod) when is_atom(mod) do
for %{type_name: type_name, type_args: type_args, type: type, doc: doc, metadata: metadata} <-
get_types_with_docs(mod) do
"""
> #{inspect(mod)}.#{type_name}(#{type_args})
#{get_metadata_md(metadata)}### Specs
```
#{type}
```
#{doc}
"""
end
|> Enum.join("\n\n---\n\n")
end

def get_callbacks_md(mod) when is_atom(mod) do
for %{callback: callback, signature: signature, doc: doc, metadata: metadata} <-
get_callbacks_with_docs(mod) do
"""
> #{signature}
#{get_metadata_md(metadata)}### Specs
```
#{callback}
```
#{doc}
"""
end
|> Enum.join("\n\n---\n\n")
end

def get_callbacks_with_docs(mod) when is_atom(mod) do
mod =
@wrapped_behaviours
Expand Down
77 changes: 0 additions & 77 deletions test/elixir_sense/core/introspection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -846,82 +846,5 @@ defmodule ElixirSense.Core.IntrospectionTest do
An example module
"""
end

test "returns since metadata on callbacks" do
assert %{callbacks: callbacks} =
get_all_docs({ElixirSenseExample.ModuleWithDocs, nil}, :mod_fun, SomeModule)

assert callbacks =~ """
> some_callback(integer)
**Since**
1.1.0
### Specs
```
@callback some_callback(integer) :: atom
```
An example callback
"""
end

test "returns optional metadata on callbacks" do
assert %{callbacks: callbacks} =
get_all_docs({ElixirSenseExample.ModuleWithDocs, nil}, :mod_fun, SomeModule)

assert callbacks =~ """
> soft_deprecated_callback(integer)
**Deprecated**
This callback will be removed in a future release
**Optional**
### Specs
```
@callback soft_deprecated_callback(integer) :: atom
```
An example callback
---
> soft_deprecated_macrocallback(integer)
**Deprecated**
This callback will be removed in a future release
**Optional**
### Specs
```
@macrocallback soft_deprecated_macrocallback(integer) :: atom
```
An example macrocallback
"""
end

test "returns since metadata on types (module)" do
assert %{types: types} =
get_all_docs({ElixirSenseExample.ModuleWithDocs, nil}, :mod_fun, SomeModule)

assert types =~ """
> ElixirSenseExample.ModuleWithDocs.opaque_type()
**Opaque**
### Specs
```
@opaque opaque_type
```
An example opaque type
"""
end
end
end
126 changes: 0 additions & 126 deletions test/elixir_sense/docs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -343,43 +343,6 @@ defmodule ElixirSense.DocsTest do
end
end

test "retrieve type information from modules" do
buffer = """
defmodule MyModule do
use GenServer
end
"""

%{actual_subject: actual_subject, docs: %{types: docs}} = ElixirSense.docs(buffer, 2, 8)

assert actual_subject == "GenServer"

assert docs =~ """
```
@type from :: {pid, tag :: term}
```
Tuple describing the client of a call request.
"""
end

test "retrieve fallback type information from erlang modules" do
buffer = """
defmodule MyModule do
alias :erlang, as: Erl
end
"""

%{actual_subject: actual_subject, docs: %{types: docs}} = ElixirSense.docs(buffer, 2, 11)

assert actual_subject == ":erlang"

assert docs =~ """
```
@type time_unit ::\
"""
end

test "retrieve documentation from modules in 1.2 alias syntax" do
buffer = """
defmodule MyModule do
Expand All @@ -402,95 +365,6 @@ defmodule ElixirSense.DocsTest do
assert docs_1 == docs_2
end

test "does not reveal opaque types" do
buffer = """
defmodule MyModule do
@behaviour ElixirSenseExample.CallbackOpaque
end
"""

%{actual_subject: actual_subject, docs: %{types: docs}} = ElixirSense.docs(buffer, 2, 40)

assert actual_subject == "ElixirSenseExample.CallbackOpaque"

assert docs =~ """
```
@opaque t(x)
```
"""
end

test "retrieve callback information from modules" do
buffer = """
defmodule MyModule do
use Application
end
"""

%{actual_subject: actual_subject, docs: %{callbacks: docs}} = ElixirSense.docs(buffer, 2, 8)

assert actual_subject == "Application"

assert docs =~ """
> config_change(changed, new, removed)
**Optional**
### Specs
```
@callback config_change(changed, new, removed) :: :ok when changed: keyword, new: keyword, removed: [atom]
```
Callback invoked after code upgrade\
"""
end

test "retrieve fallback callback information from erlang modules" do
buffer = """
defmodule MyModule do
@behaviour :gen_statem
end
"""

%{actual_subject: actual_subject, docs: %{callbacks: docs}} =
ElixirSense.docs(buffer, 2, 16)

assert actual_subject == ":gen_statem"

assert docs =~ """
```
@callback state_name\
"""
end

test "retrieve macrocallback information from modules" do
buffer = """
defmodule MyModule do
@behaviour ElixirSenseExample.BehaviourWithMacrocallback
end
"""

%{actual_subject: actual_subject, docs: %{callbacks: docs}} =
ElixirSense.docs(buffer, 2, 40)

assert actual_subject == "ElixirSenseExample.BehaviourWithMacrocallback"

assert docs =~ """
> optional(a)
**Optional**
### Specs
```
@macrocallback optional(a) :: Macro.t when a: atom
```
An optional macrocallback
"""
end

test "existing module with no docs" do
buffer = """
defmodule MyModule do
Expand Down

0 comments on commit 89905d4

Please sign in to comment.