Skip to content

Commit 13f21cb

Browse files
committed
Be even less precise about renaming with imports
Renaming a symbol that has been import-renamed will now rename all occurrences of that symbol with the new name in the whole file, regardless of scope.
1 parent 01124d7 commit 13f21cb

File tree

3 files changed

+29
-68
lines changed

3 files changed

+29
-68
lines changed

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -675,36 +675,10 @@ object Interactive {
675675
* @return All the references to the symbol under the cursor that are using `toName`.
676676
*/
677677
def findTreesMatchingRenaming(toName: Name,
678-
enclosing: Option[Tree],
679678
syms: List[Symbol],
680-
allTrees: List[Tree],
681-
source: SourceFile
679+
trees: List[SourceTree]
682680
)(implicit ctx: Context): List[SourceNamedTree] = {
683681

684-
val trees = {
685-
val enclosedTrees = enclosing match {
686-
case Some(pkg: PackageDef) =>
687-
pkg.stats
688-
case Some(template: Template) =>
689-
template.body
690-
case Some(block: Block) =>
691-
block.expr :: block.stats
692-
case _ =>
693-
// No enclosing tree; we'll search in the whole file.
694-
allTrees
695-
}
696-
697-
// Some of these trees may not be `NameTrees`. Those that are not are wrapped in a
698-
// synthetic val def, so that everything can go inside `SourceNamedTree`s.
699-
enclosedTrees.map {
700-
case tree: NameTree =>
701-
SourceNamedTree(tree, source)
702-
case tree =>
703-
val valDef = tpd.SyntheticValDef(NameKinds.UniqueName.fresh(), tree)
704-
SourceNamedTree(valDef, source)
705-
}
706-
}
707-
708682
val includes =
709683
Include.references | Include.imports | Include.renamingImports
710684

language-server/src/dotty/tools/languageserver/DottyLanguageServer.scala

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -358,24 +358,11 @@ class DottyLanguageServer extends LanguageServer
358358
path match {
359359
// Selected a renaming in an import node
360360
case Thicket(_ :: (rename: Ident) :: Nil) :: (_: Import) :: rest if rename.pos.contains(pos.pos) =>
361-
val allTrees = uriTrees.map(_.tree)
362-
val source = uriTrees.head.source
363-
Interactive.findTreesMatchingRenaming(rename.name, rest.headOption, syms, allTrees, source)
361+
Interactive.findTreesMatchingRenaming(rename.name, syms, uriTrees)
364362

365363
// Selected a reference that has been renamed
366364
case (nameTree: NameTree) :: rest if Interactive.isRenamed(nameTree) =>
367-
val enclosing = rest.find {
368-
// If we selected one of the parents or the selftype of this Template for doing the
369-
// renaming, then this Template cannot immediately enclose the rename we're interesting
370-
// in (the renaming happening inside its body cannot be used on the parents or selftype).
371-
case template: Template if template.parents.exists(_.pos.contains(pos.pos)) || template.self.pos.contains(pos.pos) =>
372-
false
373-
case tree =>
374-
Interactive.immediatelyEnclosesRenaming(nameTree.name, tree)
375-
}
376-
val allTrees = uriTrees.map(_.tree)
377-
val source = uriTrees.head.source
378-
Interactive.findTreesMatchingRenaming(nameTree.name, enclosing, syms, allTrees, source)
365+
Interactive.findTreesMatchingRenaming(nameTree.name, syms, uriTrees)
379366

380367
case _ =>
381368
val includes =

language-server/test/dotty/tools/languageserver/RenameTest.scala

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,22 @@ class RenameTest {
132132
testRename(m5, Set(m1 to m2, m3 to m4, m5 to m6, m13 to m14))
133133
testRename(m6, Set(m1 to m2, m3 to m4, m5 to m6, m13 to m14))
134134

135-
testRename(m7, Set(m7 to m8, m9 to m10, m11 to m12))
136-
testRename(m8, Set(m7 to m8, m9 to m10, m11 to m12))
137-
testRename(m9, Set(m7 to m8, m9 to m10, m11 to m12))
138-
testRename(m10, Set(m7 to m8, m9 to m10, m11 to m12))
139-
testRename(m11, Set(m7 to m8, m9 to m10, m11 to m12))
140-
testRename(m12, Set(m7 to m8, m9 to m10, m11 to m12))
135+
testRename(m7, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
136+
testRename(m8, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
137+
testRename(m9, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
138+
testRename(m10, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
139+
testRename(m11, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
140+
testRename(m12, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
141141

142142
testRename(m13, Set(m1 to m2, m3 to m4, m5 to m6, m13 to m14))
143143
testRename(m14, Set(m1 to m2, m3 to m4, m5 to m6, m13 to m14))
144144

145-
testRename(m15, Set(m15 to m16, m17 to m18, m19 to m20))
146-
testRename(m16, Set(m15 to m16, m17 to m18, m19 to m20))
147-
testRename(m17, Set(m15 to m16, m17 to m18, m19 to m20))
148-
testRename(m18, Set(m15 to m16, m17 to m18, m19 to m20))
149-
testRename(m19, Set(m15 to m16, m17 to m18, m19 to m20))
150-
testRename(m20, Set(m15 to m16, m17 to m18, m19 to m20))
145+
testRename(m15, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
146+
testRename(m16, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
147+
testRename(m17, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
148+
testRename(m18, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
149+
testRename(m19, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
150+
testRename(m20, Set(m7 to m8, m9 to m10, m11 to m12, m15 to m16, m17 to m18, m19 to m20))
151151

152152
}
153153

@@ -176,20 +176,20 @@ class RenameTest {
176176

177177
testRename(m1, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
178178
testRename(m2, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
179-
testRename(m3, Set(m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
180-
testRename(m4, Set(m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
181-
testRename(m5, Set(m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
182-
testRename(m6, Set(m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
183-
testRename(m7, Set(m7 to m8))
184-
testRename(m8, Set(m7 to m8))
185-
testRename(m9, Set(m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
186-
testRename(m10, Set(m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
187-
testRename(m11, Set(m11 to m12, m13 to m14))
188-
testRename(m12, Set(m11 to m12, m13 to m14))
189-
testRename(m13, Set(m11 to m12, m13 to m14))
190-
testRename(m14, Set(m11 to m12, m13 to m14))
191-
testRename(m15, Set(m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
192-
testRename(m16, Set(m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
179+
testRename(m3, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
180+
testRename(m4, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
181+
testRename(m5, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
182+
testRename(m6, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
183+
testRename(m7, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
184+
testRename(m8, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
185+
testRename(m9, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
186+
testRename(m10, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
187+
testRename(m11, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
188+
testRename(m12, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
189+
testRename(m13, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
190+
testRename(m14, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
191+
testRename(m15, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
192+
testRename(m16, Set(m1 to m2, m3 to m4, m5 to m6, m7 to m8, m9 to m10, m11 to m12, m13 to m14, m15 to m16))
193193
}
194194

195195
@Test def renameImportWithRenaming: Unit = {

0 commit comments

Comments
 (0)