Skip to content

Commit ac76304

Browse files
committed
fix crash when rendering edoc
1 parent 1a23c9c commit ac76304

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

lib/elixir_sense/core/compiler/quote.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,12 @@ defmodule ElixirSense.Core.Compiler.Quote do
189189
when is_atom(h) and h != Elixir and is_list(meta) do
190190
annotation =
191191
case NormalizedMacroEnv.expand_alias(e, meta, list, trace: false) do
192-
{:alias, atom} -> atom
193-
:error -> false
192+
{:alias, atom} ->
193+
# TODO track alias
194+
atom
195+
196+
:error ->
197+
false
194198
end
195199

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

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

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

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

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

lib/elixir_sense/core/erlang_html.ex

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule ElixirSense.Core.ErlangHtml do
22
@moduledoc false
33

4-
# those typedefs mimic erl_docgen types (as of OTP 26) to not introduce dependency
4+
# those typedefs mimic edoc types (as of OTP 27) to not introduce dependency
55
@type chunk_elements() :: [chunk_element()]
66
@type chunk_element() ::
77
{chunk_element_type(), chunk_element_attrs(), chunk_elements()}
@@ -33,6 +33,7 @@ defmodule ElixirSense.Core.ErlangHtml do
3333
Transform application/erlang+html AST into markdown string.
3434
3535
Document AST is defined in http://erlang.org/doc/apps/erl_docgen/doc_storage.html
36+
since OTP 27 definition moved to https://www.erlang.org/doc/apps/edoc/doc_storage.html
3637
"""
3738

3839
@spec to_markdown(chunk_element(), module(), atom()) :: String.t()
@@ -113,7 +114,21 @@ defmodule ElixirSense.Core.ErlangHtml do
113114
app
114115
) do
115116
prefix = build_prefix(parents)
116-
# TODO should we fence it as erlang?
117+
118+
"```\n" <>
119+
prefix <>
120+
to_markdown(inner, parents, :none, module, app) <> "\n" <> prefix <> "```\n" <> prefix
121+
end
122+
123+
def to_markdown(
124+
{:pre, _attrs1, [inner]},
125+
parents,
126+
_sanitize_mode,
127+
module,
128+
app
129+
) do
130+
prefix = build_prefix(parents)
131+
117132
"```\n" <>
118133
prefix <>
119134
to_markdown(inner, parents, :none, module, app) <> "\n" <> prefix <> "```\n" <> prefix

lib/elixir_sense/core/introspection.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ defmodule ElixirSense.Core.Introspection do
857857
iex> ElixirSense.Core.Introspection.expand_alias(nil, [])
858858
nil
859859
"""
860+
# TODO remove this function
860861
def expand_alias(mod, aliases) do
861862
if elixir_module?(mod) do
862863
[mod_head | mod_tail] = Module.split(mod)

test/elixir_sense/core/erlang_html_test.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,18 @@ defmodule ElixirSense.Core.ErlangHtmlTest do
297297
""" == to_markdown(ast)
298298
end
299299

300+
test "prerendered" do
301+
ast = [
302+
{:pre, [], ["var = asd()"]}
303+
]
304+
305+
assert """
306+
```
307+
var = asd()
308+
```
309+
""" == to_markdown(ast)
310+
end
311+
300312
test "link" do
301313
ast = [
302314
{:a, [href: "asd"], ["some link"]},

0 commit comments

Comments
 (0)