From ac76304976b22efe39d8d0d55e26797dd114a9f7 Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Sun, 13 Oct 2024 09:00:00 +0200 Subject: [PATCH] fix crash when rendering edoc --- lib/elixir_sense/core/compiler/quote.ex | 13 +++++++++++-- lib/elixir_sense/core/erlang_html.ex | 19 +++++++++++++++++-- lib/elixir_sense/core/introspection.ex | 1 + test/elixir_sense/core/erlang_html_test.exs | 12 ++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/lib/elixir_sense/core/compiler/quote.ex b/lib/elixir_sense/core/compiler/quote.ex index ca2dda74..c818754f 100644 --- a/lib/elixir_sense/core/compiler/quote.ex +++ b/lib/elixir_sense/core/compiler/quote.ex @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/lib/elixir_sense/core/erlang_html.ex b/lib/elixir_sense/core/erlang_html.ex index 0da511d0..e1512d72 100644 --- a/lib/elixir_sense/core/erlang_html.ex +++ b/lib/elixir_sense/core/erlang_html.ex @@ -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()} @@ -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() @@ -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 diff --git a/lib/elixir_sense/core/introspection.ex b/lib/elixir_sense/core/introspection.ex index d08f049d..153bb6d4 100644 --- a/lib/elixir_sense/core/introspection.ex +++ b/lib/elixir_sense/core/introspection.ex @@ -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) diff --git a/test/elixir_sense/core/erlang_html_test.exs b/test/elixir_sense/core/erlang_html_test.exs index be742e5f..49e7d475 100644 --- a/test/elixir_sense/core/erlang_html_test.exs +++ b/test/elixir_sense/core/erlang_html_test.exs @@ -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"]},