Skip to content

Commit

Permalink
alias external submodule behaviour changed in 1.16
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Nov 20, 2023
1 parent 9eedd9a commit 95ae920
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions lib/elixir_sense/core/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1450,22 +1450,31 @@ defmodule ElixirSense.Core.State do
if length(state.namespace) > 2 and is_list(module) and state.protocols |> hd == [] do
namespace = state.namespace |> hd

{alias, expanded} =
case module do
[Elixir, alias] ->
# an edge case with external submodule `Elixir.Some`
# this ends up removing unaliasing `Some`
# see https://github.com/elixir-lang/elixir/pull/12451#issuecomment-1461393633
{Module.concat([alias]), [Elixir, alias]}

_ ->
alias = module |> Enum.take(1) |> Module.concat()
expanded = namespace |> Enum.slice((length(module) - 1)..-2//1) |> Enum.reverse()
{alias, expanded}
end
maybe_tuple = case module do
[Elixir, alias] ->
if Version.match?(System.version(), "< 1.14.0-dev") do
# an edge case with external submodule `Elixir.Some`
# this ends up unaliasing `Some` on elixir < 1.16
# see https://github.com/elixir-lang/elixir/pull/12451#issuecomment-1461393633
{Module.concat([alias]), [Elixir, alias]}
else
# on elixir >= 1.16 no unaliasing is happening
# https://github.com/elixir-lang/elixir/issues/12456
nil
end

state
|> add_alias({alias, expanded})
_ ->
alias = module |> Enum.take(1) |> Module.concat()
expanded = namespace |> Enum.slice((length(module) - 1)..-2//1) |> Enum.reverse()
{alias, expanded}
end

if maybe_tuple do
state
|> add_alias(maybe_tuple)
else
state
end
else
state
end
Expand Down

0 comments on commit 95ae920

Please sign in to comment.