Skip to content

Commit 46a560d

Browse files
committed
fix crash on invalid multialias
1 parent 0cac2b1 commit 46a560d

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

apps/language_server/lib/language_server/providers/definition/locator.ex

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ defmodule ElixirLS.LanguageServer.Providers.Definition.Locator do
129129
{:., _, [{:__aliases__, _, _}, :{}]} -> true
130130
_ -> false
131131
end) do
132-
[{:., _, [{:__aliases__, _, outer_alias}, :{}]} | _] ->
132+
[{:., _, [{:__aliases__, _, outer_alias = [head | _]}, :{}]} | _]
133+
when is_atom(head) ->
133134
# Combine outer alias with the one under cursor
134135
expanded = Module.concat(outer_alias ++ [alias])
135136

@@ -141,6 +142,29 @@ defmodule ElixirLS.LanguageServer.Providers.Definition.Locator do
141142
binding_env
142143
)
143144

145+
[{:., _, [{:__aliases__, _, [{:__MODULE__, _, _} | outer_alias_rest]}, :{}]} | _] ->
146+
# Combine __MODULE__ with the one under cursor
147+
expanded = Module.concat([module | outer_alias_rest] ++ [alias])
148+
149+
find_function_or_module(
150+
{{:atom, expanded}, nil},
151+
context,
152+
env,
153+
metadata,
154+
binding_env
155+
)
156+
157+
[{:., _, [{:__MODULE__, _, _}, :{}]} | _] ->
158+
expanded = Module.concat([module] ++ [alias])
159+
160+
find_function_or_module(
161+
{{:atom, expanded}, nil},
162+
context,
163+
env,
164+
metadata,
165+
binding_env
166+
)
167+
144168
_ ->
145169
find_function_or_module(
146170
{{:atom, alias}, nil},

apps/language_server/lib/language_server/providers/hover/docs.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,21 @@ defmodule ElixirLS.LanguageServer.Providers.Hover.Docs do
162162
{:., _, [{:__aliases__, _, _}, :{}]} -> true
163163
_ -> false
164164
end) do
165-
[{:., _, [{:__aliases__, _, outer_alias}, :{}]} | _] ->
165+
[{:., _, [{:__aliases__, _, outer_alias = [head | _]}, :{}]} | _]
166+
when is_atom(head) ->
166167
# Combine outer alias with the one under cursor
167168
expanded = Module.concat(outer_alias ++ [alias])
168169
mod_fun_docs({{:atom, expanded}, nil}, context, binding_env, env, metadata)
169170

171+
[{:., _, [{:__aliases__, _, [{:__MODULE__, _, _} | outer_alias_rest]}, :{}]} | _] ->
172+
# Combine __MODULE__ with the one under cursor
173+
expanded = Module.concat([module | outer_alias_rest] ++ [alias])
174+
mod_fun_docs({{:atom, expanded}, nil}, context, binding_env, env, metadata)
175+
176+
[{:., _, [{:__MODULE__, _, _}, :{}]} | _] ->
177+
expanded = Module.concat([module] ++ [alias])
178+
mod_fun_docs({{:atom, expanded}, nil}, context, binding_env, env, metadata)
179+
170180
_ ->
171181
mod_fun_docs({{:atom, alias}, nil}, context, binding_env, env, metadata)
172182
end

apps/language_server/lib/language_server/providers/references/locator.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,21 @@ defmodule ElixirLS.LanguageServer.Providers.References.Locator do
222222
{:., _, [{:__aliases__, _, _}, :{}]} -> true
223223
_ -> false
224224
end) do
225-
[{:., _, [{:__aliases__, _, outer_alias}, :{}]} | _] ->
225+
[{:., _, [{:__aliases__, _, outer_alias = [head | _]}, :{}]} | _]
226+
when is_atom(head) ->
226227
# Combine outer alias with the one under cursor
227228
expanded = Module.concat(outer_alias ++ [alias])
228229
refs_for_mod_fun.({{:atom, expanded}, nil})
229230

231+
[{:., _, [{:__aliases__, _, [{:__MODULE__, _, _} | outer_alias_rest]}, :{}]} | _] ->
232+
# Combine __MODULE__ with the one under cursor
233+
expanded = Module.concat([module | outer_alias_rest] ++ [alias])
234+
refs_for_mod_fun.({{:atom, expanded}, nil})
235+
236+
[{:., _, [{:__MODULE__, _, _}, :{}]} | _] ->
237+
expanded = Module.concat([module] ++ [alias])
238+
refs_for_mod_fun.({{:atom, expanded}, nil})
239+
230240
_ ->
231241
refs_for_mod_fun.({{:atom, alias}, nil})
232242
end

0 commit comments

Comments
 (0)