Skip to content

Commit

Permalink
submodule __MODULE__.Some is actually an external submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Oct 1, 2023
1 parent a9ae8bc commit ab47f47
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/elixir_sense/core/metadata_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ defmodule ElixirSense.Core.MetadataBuilder do
end

defp pre_module(ast, state, meta, module, types \\ [], functions \\ []) do
module = normalize_module(module)
module = normalize_module(module, state)

{position = {line, column}, end_position} = extract_range(meta)

Expand Down Expand Up @@ -2016,12 +2016,12 @@ defmodule ElixirSense.Core.MetadataBuilder do
module_parts
end

defp normalize_module([{:__MODULE__, _, nil} | rest]), do: rest

defp normalize_module({[{:__MODULE__, _, nil} | rest], implementations}),
do: {rest, implementations}
defp normalize_module([{:__MODULE__, _, nil} | rest], state) do
list = state |> get_current_module |> Module.split() |> Enum.map(&String.to_atom/1)
[:"Elixir"] ++ list ++ rest
end

defp normalize_module(other), do: other
defp normalize_module(other, _state), do: other

defp maybe_add_protocol_behaviour(state, {_protocol, _}) do
protocol = state.protocols |> hd |> hd |> elem(0)
Expand Down
5 changes: 4 additions & 1 deletion test/elixir_sense/core/metadata_builder/alias_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ defmodule ElixirSense.Core.MetadataBuilder.AliasTest do
Alias.NoUnaliasNested,
Alias.RequireWithAs,
Alias.RequireWithWarnAs,
Alias.AfterStructWithImplementation
Alias.AfterStructWithImplementation,
Alias.AliasSubmoduleExternalSpecial,
Alias.AliasSubmoduleExternalSpecialInside,
Alias.AliasSubmoduleExternalInside
] do
test "alias rules properly handled in #{inspect(module)}" do
state =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ defmodule ElixirSenseExample.Fixtures.MetadataBuilder.Alias.AliasSubmoduleExtern
def env, do: @env
end

@env __ENV__
def env, do: Elixir.SubmoduleExternalInherit.env()
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule ElixirSenseExample.Fixtures.MetadataBuilder.Alias.AliasSubmoduleExternalInside do
alias Some.Sub

defmodule Elixir.SubmoduleExternalInside do
@env __ENV__
def env, do: @env
end

@env __ENV__
def env, do: Elixir.SubmoduleExternalInside.env()
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule ElixirSenseExample.Fixtures.MetadataBuilder.Alias.AliasSubmoduleExternalSpecial do
alias Some.Sub

defmodule __MODULE__.SubmoduleExternal do
end

@env __ENV__
def env, do: @env
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule ElixirSenseExample.Fixtures.MetadataBuilder.Alias.AliasSubmoduleExternalSpecialInside do
alias Some.Sub

defmodule __MODULE__.SubmoduleExternal do
@env __ENV__
def env, do: @env
end

def env, do: __MODULE__.SubmoduleExternal.env()
end

0 comments on commit ab47f47

Please sign in to comment.