From da9ced632c7ca54e2c99c46b183155f3bbaef3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20V=C4=83n=20=C4=90=E1=BB=A9c?= <35915460+Goose97@users.noreply.github.com> Date: Thu, 13 Jul 2023 15:15:50 +0700 Subject: [PATCH] Fix Elixir root module completion (#236) Fixes #230 --- lib/elixir_sense/providers/suggestion/complete.ex | 7 ++++++- test/elixir_sense/providers/suggestion/complete_test.exs | 2 +- test/elixir_sense/suggestions_test.exs | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/elixir_sense/providers/suggestion/complete.ex b/lib/elixir_sense/providers/suggestion/complete.ex index e7970b6d..d9c4e244 100644 --- a/lib/elixir_sense/providers/suggestion/complete.ex +++ b/lib/elixir_sense/providers/suggestion/complete.ex @@ -542,6 +542,11 @@ defmodule ElixirSense.Providers.Suggestion.Complete do depth = length(String.split(name, ".")) + 1 base = name <> "." <> hint + concat_module = fn + ["Elixir", "Elixir" | _] = parts -> parts |> tl() |> Module.concat() + parts -> Module.concat(parts) + end + for mod <- match_modules(base, module === Elixir, env), mod_as_atom = mod |> String.to_atom(), filter.(mod_as_atom), @@ -549,7 +554,7 @@ defmodule ElixirSense.Providers.Suggestion.Complete do depth <= length(parts), name = Enum.at(parts, depth - 1), valid_alias_piece?("." <> name), - concatted = parts |> Enum.take(depth) |> Module.concat(), + concatted = parts |> Enum.take(depth) |> concat_module.(), filter.(concatted) do {name, concatted, false} end diff --git a/test/elixir_sense/providers/suggestion/complete_test.exs b/test/elixir_sense/providers/suggestion/complete_test.exs index dbe9f7c1..3dad1047 100644 --- a/test/elixir_sense/providers/suggestion/complete_test.exs +++ b/test/elixir_sense/providers/suggestion/complete_test.exs @@ -71,7 +71,7 @@ defmodule ElixirSense.Providers.Suggestion.CompleteTest do test "elixir proxy" do list = expand(~c"E") - assert list |> Enum.find(&(&1.name == "Elixir" and &1.full_name == "Elixir.Elixir")) + assert list |> Enum.find(&(&1.name == "Elixir" and &1.full_name == "Elixir")) end test "elixir completion" do diff --git a/test/elixir_sense/suggestions_test.exs b/test/elixir_sense/suggestions_test.exs index 4ba82522..c942cb36 100644 --- a/test/elixir_sense/suggestions_test.exs +++ b/test/elixir_sense/suggestions_test.exs @@ -1976,7 +1976,7 @@ defmodule ElixirSense.SuggestionsTest do assert %{ type: :module, name: "Elixir", - full_name: "Elixir.Elixir", + full_name: "Elixir", subtype: nil, summary: "", metadata: %{}