@@ -37,7 +37,7 @@ function renamerefactor(
37
37
# local rename refactor if `old` isn't a toplevel binding
38
38
if bind === nothing || old ≠ bind. name
39
39
try
40
- refactored = localrefactor (old, new, path, column, row, startrow, context)
40
+ refactored = localrefactor (old, new, path, column, row, startrow, context, expr )
41
41
isempty (refactored) || return Dict (
42
42
:text => refactored,
43
43
:success => " _Local_ rename refactoring `$old ` ⟹ `$new ` succeeded"
86
86
# local refactor
87
87
# --------------
88
88
89
- function localrefactor (old, new, path, column, row, startrow, context)
90
- return if old ∈ map (l -> l[:name ], locals (context, row - startrow, column))
91
- oldsym = Symbol (old)
92
- newsym = Symbol (new)
93
- MacroTools. textwalk (context) do sym
94
- sym === oldsym ? newsym : sym
89
+ function localrefactor (old, new, path, column, row, startrow, context, expr)
90
+ bindings = local_bindings (expr, context)
91
+ line = row - startrow
92
+ scope = current_scope (old, bindings, byteoffset (context, line, column))
93
+ scope === nothing && return " "
94
+
95
+ current_context = scope. bindstr
96
+ oldsym = Symbol (old)
97
+ newsym = Symbol (new)
98
+ new_context = MacroTools. textwalk (current_context) do sym
99
+ sym === oldsym ? newsym : sym
100
+ end
101
+
102
+ replace (context, current_context => new_context)
103
+ end
104
+
105
+ function current_scope (name, bindings, byteoffset)
106
+ for binding in bindings
107
+ isa (binding, LocalScope) || continue
108
+
109
+ scope = binding
110
+ if byteoffset in scope. span &&
111
+ any (bind -> bind isa LocalBinding && name == bind. name, scope. children)
112
+ return scope
113
+ else
114
+ let scope = current_scope (name, scope. children, byteoffset)
115
+ scope != = nothing && return scope
116
+ end
95
117
end
96
- else
97
- " "
98
118
end
119
+
120
+ return nothing
99
121
end
100
122
101
123
# global refactor
0 commit comments