@@ -20,22 +20,25 @@ function renamerefactor(
20
20
column = 1 , row = 1 , startrow = 0 , context = " " ,
21
21
mod = " Main" ,
22
22
)
23
+ # catch keyword renaming
24
+ iskeyword (old) && return Dict (:warning => " Keywords can't be renamed: `$old `" )
25
+
23
26
mod = getmodule (mod)
24
27
head = first (split (full, ' .' ))
25
28
headval = getfield′ (mod, head)
26
29
27
30
# catch field renaming
28
- if head ≠ old && ! isa (headval, Module)
29
- return Dict ( :warning => " Rename refactoring on a field isn't available: `$obj .$old `" )
30
- end
31
+ head ≠ old && ! isa (headval, Module) && return Dict (
32
+ :warning => " Rename refactoring on a field isn't available: `$obj .$old `"
33
+ )
31
34
32
35
expr = CSTParser. parse (context)
33
36
items = toplevelitems (expr, context)
34
37
ind = findfirst (item -> item isa ToplevelBinding, items)
35
38
bind = ind === nothing ? nothing : items[ind]. bind
36
39
37
40
# local rename refactor if `old` isn't a toplevel binding
38
- if bind === nothing || old ≠ bind . name
41
+ if islocalrefactor ( bind, old)
39
42
try
40
43
refactored = localrefactor (old, new, path, column, row, startrow, context, expr)
41
44
isempty (refactored) || return Dict (
@@ -51,15 +54,8 @@ function renamerefactor(
51
54
try
52
55
val = getfield′ (mod, full)
53
56
54
- # catch keyword renaming
55
- if val isa Undefined && Symbol (old) in keys (Docs. keywords)
56
- return Dict (:warning => " Keywords can't be renamed: `$old `" )
57
- end
58
-
59
57
# catch global refactoring not on definition, e.g.: on a call site
60
- if bind === nothing || old ≠ bind. name
61
- return Dict (:info => contextdescription (old, mod, context))
62
- end
58
+ islocalrefactor (bind, old) && return Dict (:info => contextdescription (old, mod, context))
63
59
64
60
kind, desc = globalrefactor (old, new, mod, expr)
65
61
@@ -83,6 +79,8 @@ function renamerefactor(
83
79
return Dict (:error => " Rename refactoring `$old ` ⟹ `$new ` failed" )
84
80
end
85
81
82
+ islocalrefactor (bind, name) = bind === nothing || name ≠ bind. name
83
+
86
84
# local refactor
87
85
# --------------
88
86
0 commit comments