Skip to content

Commit be7c0d3

Browse files
committed
improve parent module detection logic
1 parent 39392af commit be7c0d3

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/refactor.jl

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,12 @@ function renamerefactor(
2121
mod = "Main",
2222
)
2323
mod = getmodule(mod)
24+
head = first(split(full, '.'))
25+
headval = getfield′(mod, head)
2426

25-
# check on dot accessor
26-
moddesc = if (obj = first(split(full, '.'))) != old
27-
if (parentmod = getfield′(mod, obj)) isa Module
28-
if parentmod != mod
29-
moduledescription(old, parentmod)
30-
else
31-
""
32-
end
33-
else
34-
# catch field renaming
35-
return Dict(:warning => "Rename refactoring on a field isn't available: `$obj.$old`")
36-
end
37-
else
38-
""
27+
# catch field renaming
28+
if head old && !isa(headval, Module)
29+
return Dict(:warning => "Rename refactoring on a field isn't available: `$obj.$old`")
3930
end
4031

4132
expr = CSTParser.parse(context)
@@ -72,9 +63,11 @@ function renamerefactor(
7263

7364
# make description
7465
if kind === :success
75-
# update modesc
76-
if isempty(moddesc) && applicable(parentmodule, val) && (parentmod = parentmodule(val)) mod
77-
moddesc = moduledescription(old, parentmod)
66+
moddesc = if (headval isa Module && headval mod) ||
67+
(applicable(parentmodule, val) && (headval = parentmodule(val)) mod)
68+
moduledescription(old, headval)
69+
else
70+
""
7871
end
7972

8073
desc = join(("_Global_ rename refactoring `$mod.$old` ⟹ `$mod.$new` succeeded.", moddesc, desc), "\n\n")
@@ -167,7 +160,7 @@ end
167160
function moduledescription(old, parentmod)
168161
gotouri = urigoto(parentmod, old)
169162
"""
170-
**NOTE**: `$old` was defined in `$parentmod` -- you may need the same rename refactorings
163+
**NOTE**: `$old` is defined in `$parentmod` -- you may need the same rename refactorings
171164
in that module as well. <button>[Go to `$parentmod.$old`]($gotouri)</button>
172165
"""
173166
end

0 commit comments

Comments
 (0)