Skip to content

Commit

Permalink
return full module name in completions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Dec 11, 2022
1 parent a4f15ec commit a3fffa7
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 18 deletions.
53 changes: 45 additions & 8 deletions lib/elixir_sense/providers/suggestion/complete.ex
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ defmodule ElixirSense.Providers.Suggestion.Complete do
{"", %{}}
end

%{kind: :module, name: ":" <> mod, type: :erlang, desc: desc, subtype: subtype}
name = ":" <> mod
%{kind: :module, name: name, full_name: name, type: :erlang, desc: desc, subtype: subtype}
end
end

Expand Down Expand Up @@ -520,10 +521,17 @@ defmodule ElixirSense.Providers.Suggestion.Complete do
end

defp match_aliases(hint, env) do
for {alias, _mod} <- env.aliases,
for {alias, mod} <- env.aliases,
[name] = Module.split(alias),
Matcher.match?(name, hint) do
%{kind: :module, type: :alias, name: name, desc: {"", %{}}, subtype: nil}
%{
kind: :module,
type: :alias,
name: name,
full_name: inspect(mod),
desc: {"", %{}},
subtype: nil
}
end
end

Expand Down Expand Up @@ -557,7 +565,15 @@ defmodule ElixirSense.Providers.Suggestion.Complete do
|> Enum.map(fn {name, module, required_alias?} ->
{desc, meta} = Introspection.get_module_docs_summary(module)
subtype = Introspection.get_module_subtype(module)
result = %{kind: :module, type: :elixir, name: name, desc: {desc, meta}, subtype: subtype}

result = %{
kind: :module,
type: :elixir,
name: name,
full_name: inspect(module),
desc: {desc, meta},
subtype: subtype
}

if required_alias? do
Map.put(result, :required_alias, module)
Expand All @@ -566,8 +582,12 @@ defmodule ElixirSense.Providers.Suggestion.Complete do
end
end)
|> Enum.reject(fn
%{required_alias: _, subtype: :implementation} -> true
_ -> false
%{required_alias: _, subtype: :implementation} ->
# reject protocol implementations, there is rarely a reason to alias them
true

_ ->
false
end)
end

Expand Down Expand Up @@ -937,6 +957,7 @@ defmodule ElixirSense.Providers.Suggestion.Complete do
defp to_entries(%{
kind: :module,
name: name,
full_name: full_name,
required_alias: module,
desc: {desc, metadata},
subtype: subtype
Expand All @@ -945,6 +966,7 @@ defmodule ElixirSense.Providers.Suggestion.Complete do
%{
type: :module,
name: name,
full_name: full_name,
required_alias: module,
subtype: subtype,
summary: desc,
Expand All @@ -953,8 +975,23 @@ defmodule ElixirSense.Providers.Suggestion.Complete do
]
end

defp to_entries(%{kind: :module, name: name, desc: {desc, metadata}, subtype: subtype}) do
[%{type: :module, name: name, subtype: subtype, summary: desc, metadata: metadata}]
defp to_entries(%{
kind: :module,
full_name: full_name,
name: name,
desc: {desc, metadata},
subtype: subtype
}) do
[
%{
type: :module,
name: name,
full_name: full_name,
subtype: subtype,
summary: desc,
metadata: metadata
}
]
end

defp to_entries(%{kind: :variable, name: name}) do
Expand Down
40 changes: 31 additions & 9 deletions test/elixir_sense/providers/suggestion/complete_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do
assert [
%{
name: ":zlib",
full_name: ":zlib",
subtype: nil,
summary: summary,
type: :module,
Expand Down Expand Up @@ -64,13 +65,14 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do

test "elixir proxy" do
list = expand('E')
assert list |> Enum.find(&(&1.name == "Elixir"))
assert list |> Enum.find(&(&1.name == "Elixir" and &1.full_name == "Elixir.Elixir"))
end

test "elixir completion" do
assert [_ | _] = expand('En')

assert [%{name: "Enumerable", subtype: :protocol, type: :module}] = expand('Enumera')
assert [%{name: "Enumerable", full_name: "Enumerable", subtype: :protocol, type: :module}] =
expand('Enumera')
end

test "elixir module completion with @moduledoc false" do
Expand Down Expand Up @@ -235,8 +237,13 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do
end

test "elixir root submodule completion" do
assert [%{name: "Access", summary: "Key-based access to data structures."}] =
expand('Elixir.Acce')
assert [
%{
name: "Access",
full_name: "Access",
summary: "Key-based access to data structures."
}
] = expand('Elixir.Acce')

assert [_ | _] = expand('Elixir.')
end
Expand All @@ -245,6 +252,7 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do
assert [
%{
name: "Chars",
full_name: "String.Chars",
subtype: :protocol,
summary:
"The `String.Chars` protocol is responsible for\nconverting a structure to a binary (only if applicable)."
Expand All @@ -257,6 +265,7 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do
assert [
%{
name: "Chars",
full_name: "String.Chars",
subtype: :protocol,
summary:
"The `String.Chars` protocol is responsible for\nconverting a structure to a binary (only if applicable)."
Expand All @@ -269,6 +278,7 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do
assert [
%{
name: "Chars",
full_name: "String.Chars",
subtype: :protocol,
summary:
"The `String.Chars` protocol is responsible for\nconverting a structure to a binary (only if applicable)."
Expand All @@ -286,11 +296,18 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do

test "find elixir modules that require alias" do
assert [
%{metadata: %{}, name: "Chars", required_alias: String.Chars},
%{metadata: %{}, name: "Chars", required_alias: List.Chars},
%{
metadata: %{},
name: "Chars",
full_name: "String.Chars",
required_alias: String.Chars
},
%{metadata: %{}, name: "Chars", full_name: "List.Chars", required_alias: List.Chars},
%{
metadata: %{},
name: "CallerWithAliasesAndImports",
full_name:
"ElixirSense.Providers.ReferencesTest.Modules.CallerWithAliasesAndImports",
required_alias:
ElixirSense.Providers.ReferencesTest.Modules.CallerWithAliasesAndImports
}
Expand Down Expand Up @@ -1088,9 +1105,13 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do
}
}

assert [%{name: "Some", type: :module}] = expand('Som', env)
assert [%{name: "OtherModule", type: :module}] = expand('Some.', env)
assert [%{name: "MyAlias", type: :module}] = expand('MyA', env)
assert [%{name: "Some", full_name: "Some", type: :module}] = expand('Som', env)

assert [%{name: "OtherModule", full_name: "Some.OtherModule", type: :module}] =
expand('Some.', env)

assert [%{name: "MyAlias", full_name: "Some.OtherModule.Nested", type: :module}] =
expand('MyA', env)
end

test "alias rules" do
Expand Down Expand Up @@ -1626,6 +1647,7 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do
assert [
%{
name: "File",
full_name: "File",
type: :module,
metadata: %{},
subtype: nil,
Expand Down
12 changes: 11 additions & 1 deletion test/elixir_sense/suggestions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,28 @@ defmodule ElixirSense.SuggestionsTest do
assert list == [
%{
name: "ModuleWithDocFalse",
full_name: "ElixirSenseExample.ModuleWithDocFalse",
subtype: nil,
summary: "",
type: :module,
metadata: %{}
},
%{
name: "ModuleWithDocs",
full_name: "ElixirSenseExample.ModuleWithDocs",
subtype: :behaviour,
summary: "An example module\n",
type: :module,
metadata: %{since: "1.2.3"}
},
%{metadata: %{}, name: "ModuleWithNoDocs", subtype: nil, summary: "", type: :module}
%{
metadata: %{},
name: "ModuleWithNoDocs",
full_name: "ElixirSenseExample.ModuleWithNoDocs",
subtype: nil,
summary: "",
type: :module
}
]
end

Expand Down Expand Up @@ -1805,6 +1814,7 @@ defmodule ElixirSense.SuggestionsTest do
assert Enum.at(list, 0) == %{
type: :module,
name: "Elixir",
full_name: "Elixir.Elixir",
subtype: nil,
summary: "",
metadata: %{}
Expand Down

0 comments on commit a3fffa7

Please sign in to comment.