Skip to content

Fix import and alias module functions not showing view on hexdocs link on hover #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/language_server/lib/language_server/providers/hover.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ defmodule ElixirLS.LanguageServer.Providers.Hover do
%{subject: ""} ->
nil

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

%{"contents" => contents(docs, subject, project_dir), "range" => range}
%{"contents" => contents(docs, actual_subject, project_dir), "range" => range}
end

{:ok, response}
Expand Down
44 changes: 44 additions & 0 deletions apps/language_server/test/providers/hover_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,50 @@ defmodule ElixirLS.LanguageServer.Providers.HoverTest do
)
end

test "Import function hover" do
text = """
defmodule MyModule do
import Task.Supervisor

def hello() do
start_link()
end
end
"""

{line, char} = {4, 5}

assert {:ok, %{"contents" => %{kind: "markdown", value: v}}} =
Hover.hover(text, line, char, fake_dir())

assert String.starts_with?(
v,
"> Task.Supervisor.start_link(options \\\\\\\\ []) [view on hexdocs](https://hexdocs.pm/elixir/Task.Supervisor.html#start_link/1)"
)
end

test "Alias module function hover" do
text = """
defmodule MyModule do
alias Task.Supervisor

def hello() do
Supervisor.start_link()
end
end
"""

{line, char} = {4, 15}

assert {:ok, %{"contents" => %{kind: "markdown", value: v}}} =
Hover.hover(text, line, char, fake_dir())

assert String.starts_with?(
v,
"> Task.Supervisor.start_link(options \\\\\\\\ []) [view on hexdocs](https://hexdocs.pm/elixir/Task.Supervisor.html#start_link/1)"
)
end

test "Erlang module hover is not support now" do
text = """
defmodule MyModule do
Expand Down