Skip to content

Commit

Permalink
improve rendering of builtin type docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Jul 28, 2023
1 parent b0f45bf commit 33cf5ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions lib/elixir_sense/core/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,15 @@ defmodule ElixirSense.Core.Introspection do
matches_arity?(length(info.params), arity) do
{spec, args} =
case info do
%{signature: sig, params: params} ->
{sig, Enum.map_join(params, ", ", &(&1 |> Atom.to_string()))}
%{signature: signature, params: params} ->
{"@type #{signature}", Enum.map_join(params, ", ", &(&1 |> Atom.to_string()))}

%{spec: spec_ast, params: params} ->
{TypeInfo.format_type_spec_ast(spec_ast, :type),
Enum.map_join(params, ", ", &(&1 |> Atom.to_string()))}

_ ->
{"#{fun}()", ""}
{"@type #{fun}()", ""}
end

format_type_doc_md({nil, fun}, args, info[:doc], spec, %{builtin: true})
Expand Down Expand Up @@ -1429,7 +1429,7 @@ defmodule ElixirSense.Core.Introspection do
atom -> inspect(atom) <> "."
end

"> #{mod_formatted}#{fun}(#{type_args})\n\n#{get_metadata_md(metadata)}### Specs\n\n#{formatted_spec}\n\n#{doc}"
"> #{mod_formatted}#{fun}(#{type_args})\n\n#{get_metadata_md(metadata)}### Definition\n\n#{formatted_spec}\n\n#{doc}"
end

def is_pub(type), do: type in [:def, :defmacro, :defdelegate, :defguard]
Expand Down
2 changes: 1 addition & 1 deletion test/elixir_sense/core/introspection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ defmodule ElixirSense.Core.IntrospectionTest do
**Since**
1.1.0
### Specs
### Definition
```
@type some_type() :: integer()
Expand Down
20 changes: 10 additions & 10 deletions test/elixir_sense/docs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ defmodule ElixirSense.DocsTest do
assert docs == """
> ElixirSenseExample.ModuleWithTypespecs.Remote.remote_t()
### Specs
### Definition
```
@type remote_t() :: atom()
Expand Down Expand Up @@ -438,7 +438,7 @@ defmodule ElixirSense.DocsTest do
**Opaque**
### Specs
### Definition
```
@opaque t(x)
Expand Down Expand Up @@ -468,7 +468,7 @@ defmodule ElixirSense.DocsTest do
assert docs =~ """
> :erlang.time_unit()
### Specs
### Definition
```
@type time_unit() ::
Expand Down Expand Up @@ -512,7 +512,7 @@ defmodule ElixirSense.DocsTest do
**Built-in**
### Specs
### Definition
```
@type keyword() :: [{atom(), any()}]
Expand All @@ -533,7 +533,7 @@ defmodule ElixirSense.DocsTest do
**Built-in**
### Specs
### Definition
```
@type keyword(t) :: [{atom(), t}]
Expand Down Expand Up @@ -563,10 +563,10 @@ defmodule ElixirSense.DocsTest do
**Built-in**
### Specs
### Definition
```
integer()
@type integer()
```
An integer number
Expand Down Expand Up @@ -595,7 +595,7 @@ defmodule ElixirSense.DocsTest do
**Built-in**
### Specs
### Definition
```
@type list() :: [any()]
Expand All @@ -616,10 +616,10 @@ defmodule ElixirSense.DocsTest do
**Built-in**
### Specs
### Definition
```
list(t)
@type list(t)
```
Proper list ([]-terminated)
Expand Down

0 comments on commit 33cf5ab

Please sign in to comment.