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

Refactor docs #280

Merged
merged 5 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
#
## Readability Checks
#
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.AliasOrder, false},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 135]},
Expand Down
18 changes: 8 additions & 10 deletions lib/elixir_sense.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ defmodule ElixirSense do
...> MyEnum.to_list(1..3)
...> end
...> '''
iex> %{docs: docs} = ElixirSense.docs(code, 3, 11)
iex> docs |> String.split("\n") |> Enum.at(8)
iex> %{docs: [doc]} = ElixirSense.docs(code, 3, 11)
iex> doc.docs |> String.split("\n") |> Enum.at(0)
"Converts `enumerable` to a list."
"""
@spec docs(String.t(), pos_integer, pos_integer) ::
%{
actual_subject: String.t(),
docs: nil | String.t(),
docs: nonempty_list(Docs.doc()),
range: %{
begin: {pos_integer, pos_integer},
end: {pos_integer, pos_integer}
Expand All @@ -69,18 +68,17 @@ defmodule ElixirSense do
env = Metadata.get_env(metadata, {line, column})

case Docs.all(context, env, metadata) do
{actual_subject, docs} ->
[] ->
nil

list ->
%{
actual_subject: actual_subject,
docs: docs,
docs: list,
range: %{
begin: begin_pos,
end: end_pos
}
}

nil ->
nil
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_sense/core/applications.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule ElixirSense.Core.Applications do
@spec get_modules_from_applications() :: [module]
# TODO use :code.all_available |> Enum.map(fn {m, _, _} -> :"#{m}" end) on otp 23+
# as it returns more
# NOTE this function does not return modules from :erts app as it is not loaded
def get_modules_from_applications do
for [app] <- loaded_applications(),
{:ok, modules} = :application.get_key(app, :modules),
Expand Down
3 changes: 2 additions & 1 deletion lib/elixir_sense/core/erlang_html.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule ElixirSense.Core.ErlangHtml do
@moduledoc false

# those typedefs mimic erl_docgen types (as of OTP 24) to not introduce dependency
# those typedefs mimic erl_docgen types (as of OTP 26) to not introduce dependency
@type chunk_elements() :: [chunk_element()]
@type chunk_element() ::
{chunk_element_type(), chunk_element_attrs(), chunk_elements()}
Expand Down Expand Up @@ -104,6 +104,7 @@ defmodule ElixirSense.Core.ErlangHtml do

def to_markdown({:pre, _attrs1, [{:code, _attrs2, inner}]}, parents, _sanitize_mode) do
prefix = build_prefix(parents)
# TODO should we fence it as erlang?
"```\n" <> prefix <> to_markdown(inner, parents, :none) <> "\n" <> prefix <> "```\n" <> prefix
end

Expand Down
Loading
Loading