Skip to content

Commit

Permalink
fix: minimally support dl tag for Erlang hover docs (#362)
Browse files Browse the repository at this point in the history
This handles the conversion of the description list tag to Markdown.
Markdown doesn't support what can be done with the dl tag, but this
renders something legible for the few cases it's used.

Fixes #361
  • Loading branch information
fhunleth committed Jan 21, 2024
1 parent 8cf06cb commit 47b8c66
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/next_ls/helpers/hover_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ defmodule NextLS.HoverHelpers do
"_#{IO.iodata_to_binary(bins)}_" <> to_markdown(type, rest)
end

def to_markdown("application/erlang+html" = type, [{:dl, _, lis} | rest]) do
"#{to_markdown(type, lis)}\n" <> to_markdown(type, rest)
end

def to_markdown("application/erlang+html" = type, [{:dt, _, children} | rest]) do
"* #{to_markdown(type, children)}\n" <> to_markdown(type, rest)
end

def to_markdown("application/erlang+html" = type, [{:dd, _, children} | rest]) do
"#{to_markdown(type, children)}\n" <> to_markdown(type, rest)
end

def to_markdown("application/erlang+html", []) do
""
end
Expand Down
60 changes: 60 additions & 0 deletions test/next_ls/helpers/hover_helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,65 @@ defmodule NextLS.HoverHelpersTest do
* Repeat until there is no path between `V1` and `V2`.
""")
end

test "dl, dt, and dd" do
html = [
{:dl, [],
[
{:dt, [], [{:code, [], ["root"]}]},
{:dd, [],
[
{:p, [], ["The installation directory of Erlang/OTP, ", {:code, [], ["$ROOT"]}, ":"]},
{:pre, [],
[
{:code, [],
["2> init:get_argument(root).\n{ok,[[\"/usr/local/otp/releases/otp_beam_solaris8_r10b_patched\"]]}"]}
]}
]},
{:dt, [], [{:code, [], ["progname"]}]},
{:dd, [],
[
{:p, [], ["The name of the program which started Erlang:"]},
{:pre, [], [{:code, [], ["3> init:get_argument(progname).\n{ok,[[\"erl\"]]}"]}]}
]},
{:dt, [], [{:a, [id: "home"], []}, {:code, [], ["home"]}]},
{:dd, [],
[
{:p, [], ["The home directory (on Unix, the value of $HOME):"]},
{:pre, [], [{:code, [], ["4> init:get_argument(home).\n{ok,[[\"/home/harry\"]]}"]}]}
]}
]},
{:p, [], ["Returns ", {:code, [], ["error"]}, " if no value is associated with ", {:code, [], ["Flag"]}, "."]}
]

actual = HoverHelpers.to_markdown("application/erlang+html", html)

assert String.trim(actual) ==
String.trim("""
* `root`
The installation directory of Erlang/OTP, `$ROOT`:
```erlang
2> init:get_argument(root).
{ok,[[\"/usr/local/otp/releases/otp_beam_solaris8_r10b_patched\"]]}
```
* `progname`
The name of the program which started Erlang:
```erlang
3> init:get_argument(progname).
{ok,[[\"erl\"]]}
```
* []()`home`
The home directory (on Unix, the value of $HOME):
```erlang
4> init:get_argument(home).
{ok,[[\"/home/harry\"]]}
```
Returns `error` if no value is associated with `Flag`.
""")
end
end
end

0 comments on commit 47b8c66

Please sign in to comment.