@@ -23,8 +23,14 @@ function renamerefactor(
23
23
mod = getmodule (mod)
24
24
25
25
# catch field renaming
26
- if (obj = first (split (full, ' .' ))) != old && ! isa (getfield′ (mod, obj), Module)
27
- return Dict (:warning => " Rename refactoring on a field isn't available: `$obj .$old `" )
26
+ modulenote = if (obj = first (split (full, ' .' ))) != old
27
+ if (parentmod = getfield′ (mod, obj)) isa Module && parentmod != mod
28
+ " **NOTE**: `$old ` is defined in `$parentmod ` -- you may need the same rename refactorings in that module as well."
29
+ else
30
+ return Dict (:warning => " Rename refactoring on a field isn't available: `$obj .$old `" )
31
+ end
32
+ else
33
+ " "
28
34
end
29
35
30
36
# local refactor only if `old` is really a local binding
@@ -34,20 +40,29 @@ function renamerefactor(
34
40
refactored = localrefactor (old, new, path, column, row, startrow, context)
35
41
isempty (refactored) || return Dict (
36
42
:text => refactored,
37
- :success => " Local rename refactoring `$old ` ⟹ `$new ` succeeded"
43
+ :success => " _Local_ rename refactoring `$old ` ⟹ `$new ` succeeded"
38
44
)
39
45
catch err
40
46
@error err
41
47
end
42
48
end
43
49
44
50
try
45
- val = getfield′ (mod, old)
46
- kind, description = globalrefactor (old, new, mod, val)
51
+ val = getfield′ (mod, full)
52
+ # catch keyword renaming
53
+ if val isa Undefined && Symbol (old) in keys (Docs. keywords)
54
+ return Dict (:warning => " Keywords can't be renamed: `$old `" )
55
+ end
56
+ # update modulenote
57
+ if isempty (modulenote) && applicable (parentmodule, val) && (parentmod = parentmodule (val)) != mod
58
+ modulenote =
59
+ " **NOTE**: `$old ` is defined in `$parentmod ` -- you may need the same rename refactorings in that module as well."
60
+ end
61
+ kind, desc = globalrefactor (old, new, mod)
47
62
return Dict (
48
- kind => description,
49
- :success => kind != = :info ? false :
50
- " Global rename refactoring ` $old ` ⟹ ` $new ` succeeded "
63
+ kind => kind === :success ?
64
+ join (( " _Global_ rename refactoring ` $old ` ⟹ ` $new ` succeeded. " , modulenote, desc), " \n\n " ) :
65
+ desc
51
66
)
52
67
catch err
53
68
@error err
74
89
# global refactor
75
90
# ---------------
76
91
77
- globalrefactor (old, new, mod, @nospecialize (val)) = _globalrefactor (old, new, mod) # general case
78
- function globalrefactor (old, new, mod, val:: Undefined )
79
- Symbol (old) in keys (Docs. keywords) ?
80
- (:warning , " Keywords can't be renamed: `$old `" ) :
81
- _globalrefactor (old, new, mod)
82
- end
83
-
84
- function _globalrefactor (old, new, mod)
92
+ function globalrefactor (old, new, mod)
85
93
entrypath, line = moduledefinition (mod)
86
94
files = modulefiles (entrypath)
87
95
@@ -97,18 +105,18 @@ function refactorfiles(old, new, mod, files)
97
105
oldsym = Symbol (old)
98
106
newsym = Symbol (new)
99
107
total = length (files)
100
- desc = " "
108
+
109
+ # TODO : enable line location information (the upstream needs to be enhanced)
110
+ refactoredfiles = Set {String} ()
101
111
102
112
for (i, file) ∈ enumerate (files)
103
113
@info " Refactoring: $file ($i / $total )" progress= i/ total _id= id
104
114
MacroTools. sourcewalk (file) do ex
105
115
return if ex === oldsym
116
+ push! (refactoredfiles, fullpath (file))
106
117
newsym
107
118
elseif @capture (ex, m_.$ oldsym) && getfield′ (mod, Symbol (m)) isa Module
108
- # TODO : enable line location information (the upstream needs to be enhanced)
109
- file = fullpath (file)
110
- link = " atom://julia-client/?open=true&file=$(file) &line=0"
111
- desc *= " - `$m .$old ` ⟹ `$m .$new ` in [$file ]($link )\n "
119
+ push! (refactoredfiles, fullpath (file))
112
120
Expr (:., m, newsym)
113
121
else
114
122
ex
@@ -118,5 +126,10 @@ function refactorfiles(old, new, mod, files)
118
126
119
127
@info " Finish global rename refactoring" progress= 1 _id= id
120
128
121
- (:info , isempty (desc) ? " " : " Refactorings across modules\n " * desc)
129
+ return if ! isempty (refactoredfiles)
130
+ filelist = (" - [$file ](atom://julia-client/?open=true&file=$(file) &line=0)" for file in refactoredfiles)
131
+ (:success , string (" Refactored files (all in `$mod ` module):\n\n " , join (filelist, ' \n ' )))
132
+ else
133
+ (:warning , " No rename refactoring occured on `$old `" )
134
+ end
122
135
end
0 commit comments