Skip to content

Commit df13448

Browse files
committed
simplify the refactoring logic
1 parent 75e2592 commit df13448

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

src/refactor.jl

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,27 @@ function renamerefactor(
4141
if islocalrefactor(bind, old)
4242
try
4343
refactored = localrefactor(old, new, path, column, row, startrow, context, expr)
44-
isempty(refactored) || return Dict(
45-
:text => refactored,
46-
:success => "_Local_ rename refactoring `$old` ⟹ `$new` succeeded"
47-
)
44+
return isempty(refactored) ?
45+
# NOTE: global refactoring not on definition, e.g.: on a call site, will be caught here
46+
Dict(:info => contextdescription(old, mod, context)) :
47+
Dict(
48+
:text => refactored,
49+
:success => "_Local_ rename refactoring `$old` ⟹ `$new` succeeded"
50+
)
4851
catch err
4952
@error err
5053
end
5154
end
5255

5356
# global rename refactor if the local rename refactor didn't happen
5457
try
55-
val = getfield′(mod, full)
56-
57-
# catch global refactoring not on definition, e.g.: on a call site
58-
islocalrefactor(bind, old) && return Dict(:info => contextdescription(old, mod, context))
59-
6058
kind, desc = globalrefactor(old, new, mod, expr)
6159

6260
# make description
6361
if kind === :success
62+
val = getfield′(mod, full)
6463
moddesc = if (headval isa Module && headval mod) ||
65-
(applicable(parentmodule, val) && (headval = parentmodule(val)) mod)
64+
(applicable(parentmodule, val) && (headval = parentmodule(val)) mod)
6665
moduledescription(old, headval)
6766
else
6867
""
@@ -175,23 +174,15 @@ function refactorfiles(old, new, mod, files, expr)
175174
@info "Finish global rename refactoring" progress=1 _id=id
176175

177176
return if !isempty(refactoredfiles)
178-
(:success, filedescription(mod, refactoredfiles))
177+
:success, filedescription(mod, refactoredfiles)
179178
else
180-
(:warning, "No rename refactoring occured on `$old` in `$mod` module.")
179+
:warning, "No rename refactoring occured on `$old` in `$mod` module."
181180
end
182181
end
183182

184183
# descriptions
185184
# ------------
186185

187-
function moduledescription(old, parentmod)
188-
gotouri = urigoto(parentmod, old)
189-
"""
190-
**NOTE**: `$old` is defined in `$parentmod` -- you may need the same rename refactorings
191-
in that module as well. <button>[Go to `$parentmod.$old`]($gotouri)</button>
192-
"""
193-
end
194-
195186
function contextdescription(old, mod, context)
196187
gotouri = urigoto(mod, old)
197188
"""
@@ -203,6 +194,14 @@ function contextdescription(old, mod, context)
203194
"""
204195
end
205196

197+
function moduledescription(old, parentmod)
198+
gotouri = urigoto(parentmod, old)
199+
"""
200+
**NOTE**: `$old` is defined in `$parentmod` -- you may need the same rename refactorings
201+
in that module as well. <button>[Go to `$parentmod.$old`]($gotouri)</button>
202+
"""
203+
end
204+
206205
function nonwritabledescription(mod, files)
207206
filelist = join(("<li>[$file]($(uriopen(file)))</li>" for file in files), '\n')
208207
"""

0 commit comments

Comments
 (0)