Skip to content

Commit d746383

Browse files
committed
organize description
1 parent e4d7ee4 commit d746383

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

src/refactor.jl

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ function renamerefactor(
2323
mod = getmodule(mod)
2424

2525
# check on dot accessor
26-
modnote = if (obj = first(split(full, '.'))) != old
27-
if (parent = getfield′(mod, obj)) isa Module
28-
if parent != mod
29-
modulenote(old, parent)
26+
moddesc = if (obj = first(split(full, '.'))) != old
27+
if (parentmod = getfield′(mod, obj)) isa Module
28+
if parentmod != mod
29+
moduledescription(old, parentmod)
3030
else
3131
""
3232
end
@@ -66,19 +66,19 @@ function renamerefactor(
6666
# catch global refactoring not on definition, e.g.: on a call site
6767
if bind === nothing || old bind.name
6868
# TODO: `goto` uri
69-
return Dict(:info => contextnote(old, mod, context))
69+
return Dict(:info => contextdescription(old, mod, context))
7070
end
7171

7272
kind, desc = globalrefactor(old, new, mod, expr)
7373

7474
# make description
7575
if kind === :success
76-
# update modnote
77-
if isempty(modnote) && applicable(parentmodule, val) && (parent = parentmodule(val)) mod
78-
modnote = modulenote(old, parent)
76+
# update modesc
77+
if isempty(moddesc) && applicable(parentmodule, val) && (parentmod = parentmodule(val)) mod
78+
moddesc = moduledescription(old, parentmod)
7979
end
8080

81-
desc = join(("_Global_ rename refactoring `$old` ⟹ `$new` succeeded.", modnote, desc), "\n\n")
81+
desc = join(("_Global_ rename refactoring `$old` ⟹ `$new` succeeded.", moddesc, desc), "\n\n")
8282
end
8383

8484
return Dict(kind => desc)
@@ -89,18 +89,6 @@ function renamerefactor(
8989
return Dict(:error => "Rename refactoring `$old` ⟹ `$new` failed")
9090
end
9191

92-
modulenote(old, parentmod) = """
93-
**NOTE**: `$old` is defined in `$parentmod`
94-
-- you may need the same rename refactorings in that module as well.
95-
"""
96-
97-
contextnote(old, mod, context) = """
98-
`$old` isn't found in local bindings in the current context:
99-
<details><summary>Context</summary><pre><code>$(strip(context))</code></p></details>
100-
101-
If you want a global rename refactoring on `$mod.$old`, you need to call from its definition.
102-
"""
103-
10492
# local refactor
10593
# --------------
10694

@@ -164,9 +152,32 @@ function refactorfiles(old, new, mod, files, expr)
164152
@info "Finish global rename refactoring" progress=1 _id=id
165153

166154
return if !isempty(refactoredfiles)
167-
filelist = ("- [$file]($(uriopen(file)))" for file in refactoredfiles)
168-
(:success, string("Refactored files (all in `$mod` module):\n\n", join(filelist, '\n')))
155+
(:success, filedescription(mod, refactoredfiles))
169156
else
170157
(:warning, "No rename refactoring occured on `$old` in `$mod` module.")
171158
end
172159
end
160+
161+
# descriptions
162+
# ------------
163+
164+
moduledescription(old, parentmod) = """
165+
**NOTE**: `$old` is defined in `$parentmod`
166+
-- you may need the same rename refactorings in that module as well.
167+
"""
168+
169+
contextdescription(old, mod, context) = """
170+
`$old` isn't found in local bindings in the current context:
171+
<details><summary>Context</summary><pre><code>$(strip(context))</code></p></details>
172+
173+
If you want a global rename refactoring on `$mod.$old`, you need to call from its definition.
174+
"""
175+
176+
function filedescription(mod, files)
177+
filelist = join(("<li>[$file]($(uriopen(file)))</li>" for file in files), '\n')
178+
"""
179+
<details><summary>
180+
Refactored files (all in `$mod` module):
181+
</summary><ul>$(filelist)</ul></details>
182+
"""
183+
end

0 commit comments

Comments
 (0)