Skip to content

Commit

Permalink
fix crash when rendering edoc
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Oct 13, 2024
1 parent 1a23c9c commit ac76304
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
13 changes: 11 additions & 2 deletions lib/elixir_sense/core/compiler/quote.ex
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,12 @@ defmodule ElixirSense.Core.Compiler.Quote do
when is_atom(h) and h != Elixir and is_list(meta) do
annotation =
case NormalizedMacroEnv.expand_alias(e, meta, list, trace: false) do
{:alias, atom} -> atom
:error -> false
{:alias, atom} ->
# TODO track alias
atom

:error ->
false
end

alias_meta = keystore(:alias, Keyword.delete(meta, :counter), annotation)
Expand Down Expand Up @@ -249,6 +253,9 @@ defmodule ElixirSense.Core.Compiler.Quote do
meta

receiver ->
# TODO trace call here?
# import capture is precise
# elixir emits function/macro_imported
keystore(:context, keystore(:imports, meta, [{a, receiver}]), q.context)
end

Expand All @@ -266,6 +273,7 @@ defmodule ElixirSense.Core.Compiler.Quote do

import_meta = import_meta(meta, name, arity, q, e)
annotated = annotate({name, import_meta, args_or_context}, q.context)
# TODO register call here? elixir emits import_quoted
do_quote_tuple(annotated, q)
end

Expand Down Expand Up @@ -327,6 +335,7 @@ defmodule ElixirSense.Core.Compiler.Quote do
defp do_quote_call(left, meta, expr, args, q) do
all = [left, {:unquote, meta, [expr]}, args, q.context]
tall = Enum.map(all, fn x -> do_quote(x, q) end)
# TODO track call? elixir does not emit remote_function in quoted
{{:., meta, [:elixir_quote, :dot]}, meta, [meta(meta, q) | tall]}
end

Expand Down
19 changes: 17 additions & 2 deletions 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 26) to not introduce dependency
# those typedefs mimic edoc types (as of OTP 27) to not introduce dependency
@type chunk_elements() :: [chunk_element()]
@type chunk_element() ::
{chunk_element_type(), chunk_element_attrs(), chunk_elements()}
Expand Down Expand Up @@ -33,6 +33,7 @@ defmodule ElixirSense.Core.ErlangHtml do
Transform application/erlang+html AST into markdown string.
Document AST is defined in http://erlang.org/doc/apps/erl_docgen/doc_storage.html
since OTP 27 definition moved to https://www.erlang.org/doc/apps/edoc/doc_storage.html
"""

@spec to_markdown(chunk_element(), module(), atom()) :: String.t()
Expand Down Expand Up @@ -113,7 +114,21 @@ defmodule ElixirSense.Core.ErlangHtml do
app
) do
prefix = build_prefix(parents)
# TODO should we fence it as erlang?

"```\n" <>
prefix <>
to_markdown(inner, parents, :none, module, app) <> "\n" <> prefix <> "```\n" <> prefix
end

def to_markdown(
{:pre, _attrs1, [inner]},
parents,
_sanitize_mode,
module,
app
) do
prefix = build_prefix(parents)

"```\n" <>
prefix <>
to_markdown(inner, parents, :none, module, app) <> "\n" <> prefix <> "```\n" <> prefix
Expand Down
1 change: 1 addition & 0 deletions lib/elixir_sense/core/introspection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ defmodule ElixirSense.Core.Introspection do
iex> ElixirSense.Core.Introspection.expand_alias(nil, [])
nil
"""
# TODO remove this function
def expand_alias(mod, aliases) do
if elixir_module?(mod) do
[mod_head | mod_tail] = Module.split(mod)
Expand Down
12 changes: 12 additions & 0 deletions test/elixir_sense/core/erlang_html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ defmodule ElixirSense.Core.ErlangHtmlTest do
""" == to_markdown(ast)
end

test "prerendered" do
ast = [
{:pre, [], ["var = asd()"]}
]

assert """
```
var = asd()
```
""" == to_markdown(ast)
end

test "link" do
ast = [
{:a, [href: "asd"], ["some link"]},
Expand Down

0 comments on commit ac76304

Please sign in to comment.