Skip to content

Commit 9aebbe8

Browse files
authored
Fix import and alias module functions not showing view on hexdocs link on hover (#712)
1 parent 9e83aa2 commit 9aebbe8

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

apps/language_server/lib/language_server/providers/hover.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do
2525
%{subject: ""} ->
2626
nil
2727

28-
%{subject: subject, docs: docs} ->
28+
%{subject: subject, docs: docs, actual_subject: actual_subject} ->
2929
line_text = Enum.at(SourceFile.lines(text), line - 1)
3030
range = highlight_range(line_text, line - 1, character - 1, subject)
3131

32-
%{"contents" => contents(docs, subject, project_dir), "range" => range}
32+
%{"contents" => contents(docs, actual_subject, project_dir), "range" => range}
3333
end
3434

3535
{:ok, response}

apps/language_server/test/providers/hover_test.exs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,50 @@ defmodule ElixirLS.LanguageServer.Providers.HoverTest do
101101
)
102102
end
103103

104+
test "Import function hover" do
105+
text = """
106+
defmodule MyModule do
107+
import Task.Supervisor
108+
109+
def hello() do
110+
start_link()
111+
end
112+
end
113+
"""
114+
115+
{line, char} = {4, 5}
116+
117+
assert {:ok, %{"contents" => %{kind: "markdown", value: v}}} =
118+
Hover.hover(text, line, char, fake_dir())
119+
120+
assert String.starts_with?(
121+
v,
122+
"> Task.Supervisor.start_link(options \\\\\\\\ []) [view on hexdocs](https://hexdocs.pm/elixir/Task.Supervisor.html#start_link/1)"
123+
)
124+
end
125+
126+
test "Alias module function hover" do
127+
text = """
128+
defmodule MyModule do
129+
alias Task.Supervisor
130+
131+
def hello() do
132+
Supervisor.start_link()
133+
end
134+
end
135+
"""
136+
137+
{line, char} = {4, 15}
138+
139+
assert {:ok, %{"contents" => %{kind: "markdown", value: v}}} =
140+
Hover.hover(text, line, char, fake_dir())
141+
142+
assert String.starts_with?(
143+
v,
144+
"> Task.Supervisor.start_link(options \\\\\\\\ []) [view on hexdocs](https://hexdocs.pm/elixir/Task.Supervisor.html#start_link/1)"
145+
)
146+
end
147+
104148
test "Erlang module hover is not support now" do
105149
text = """
106150
defmodule MyModule do

0 commit comments

Comments
 (0)