Skip to content

Commit

Permalink
Determine immediate_parent is :defmodule or not
Browse files Browse the repository at this point in the history
  • Loading branch information
scottming committed Jun 21, 2024
1 parent da6b362 commit 625c698
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,31 @@ defmodule Lexical.RemoteControl.CodeAction.Handlers.OrganizeAliases do
# |
case Analysis.module_scope(analysis, range) do
%Scope{aliases: [_ | _]} ->
token_at_cursor_is_blank?(analysis, range.start)
cursor_path = Ast.cursor_path(analysis, range.start)

immediate_parent =
Enum.find(cursor_path, fn
[{:__cursor__, _, _} | _] ->
false

{:__block__, _, _} ->
false

{{:__block__, _, _}, _} ->
false

[{{:__block__, _, _}, _} | _] ->
false

{:__cursor__, _, _} ->
false

_ ->
true
end)

immediate_parent_is_defmodule? = match?({:defmodule, _, _}, immediate_parent)
token_at_cursor_is_blank?(analysis, range.start) and immediate_parent_is_defmodule?

_ ->
false
Expand Down

0 comments on commit 625c698

Please sign in to comment.