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 22, 2024
1 parent d08411b commit d747d8c
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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

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

{:__block__, _, _} ->
false

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

[{{:__block__, _, _}, _} | _] ->
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 d747d8c

Please sign in to comment.