Skip to content

Commit 47b8c66

Browse files
authored
fix: minimally support dl tag for Erlang hover docs (#362)
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
1 parent 8cf06cb commit 47b8c66

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

Diff for: lib/next_ls/helpers/hover_helpers.ex

+12
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ defmodule NextLS.HoverHelpers do
5050
"_#{IO.iodata_to_binary(bins)}_" <> to_markdown(type, rest)
5151
end
5252

53+
def to_markdown("application/erlang+html" = type, [{:dl, _, lis} | rest]) do
54+
"#{to_markdown(type, lis)}\n" <> to_markdown(type, rest)
55+
end
56+
57+
def to_markdown("application/erlang+html" = type, [{:dt, _, children} | rest]) do
58+
"* #{to_markdown(type, children)}\n" <> to_markdown(type, rest)
59+
end
60+
61+
def to_markdown("application/erlang+html" = type, [{:dd, _, children} | rest]) do
62+
"#{to_markdown(type, children)}\n" <> to_markdown(type, rest)
63+
end
64+
5365
def to_markdown("application/erlang+html", []) do
5466
""
5567
end

Diff for: test/next_ls/helpers/hover_helpers_test.exs

+60
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,65 @@ defmodule NextLS.HoverHelpersTest do
200200
* Repeat until there is no path between `V1` and `V2`.
201201
""")
202202
end
203+
204+
test "dl, dt, and dd" do
205+
html = [
206+
{:dl, [],
207+
[
208+
{:dt, [], [{:code, [], ["root"]}]},
209+
{:dd, [],
210+
[
211+
{:p, [], ["The installation directory of Erlang/OTP, ", {:code, [], ["$ROOT"]}, ":"]},
212+
{:pre, [],
213+
[
214+
{:code, [],
215+
["2> init:get_argument(root).\n{ok,[[\"/usr/local/otp/releases/otp_beam_solaris8_r10b_patched\"]]}"]}
216+
]}
217+
]},
218+
{:dt, [], [{:code, [], ["progname"]}]},
219+
{:dd, [],
220+
[
221+
{:p, [], ["The name of the program which started Erlang:"]},
222+
{:pre, [], [{:code, [], ["3> init:get_argument(progname).\n{ok,[[\"erl\"]]}"]}]}
223+
]},
224+
{:dt, [], [{:a, [id: "home"], []}, {:code, [], ["home"]}]},
225+
{:dd, [],
226+
[
227+
{:p, [], ["The home directory (on Unix, the value of $HOME):"]},
228+
{:pre, [], [{:code, [], ["4> init:get_argument(home).\n{ok,[[\"/home/harry\"]]}"]}]}
229+
]}
230+
]},
231+
{:p, [], ["Returns ", {:code, [], ["error"]}, " if no value is associated with ", {:code, [], ["Flag"]}, "."]}
232+
]
233+
234+
actual = HoverHelpers.to_markdown("application/erlang+html", html)
235+
236+
assert String.trim(actual) ==
237+
String.trim("""
238+
* `root`
239+
The installation directory of Erlang/OTP, `$ROOT`:
240+
241+
```erlang
242+
2> init:get_argument(root).
243+
{ok,[[\"/usr/local/otp/releases/otp_beam_solaris8_r10b_patched\"]]}
244+
```
245+
* `progname`
246+
The name of the program which started Erlang:
247+
248+
```erlang
249+
3> init:get_argument(progname).
250+
{ok,[[\"erl\"]]}
251+
```
252+
* []()`home`
253+
The home directory (on Unix, the value of $HOME):
254+
255+
```erlang
256+
4> init:get_argument(home).
257+
{ok,[[\"/home/harry\"]]}
258+
```
259+
260+
Returns `error` if no value is associated with `Flag`.
261+
""")
262+
end
203263
end
204264
end

0 commit comments

Comments
 (0)