Skip to content

Commit a9b762b

Browse files
committed
Fix renaming of synthetic positions in IDE
While working on the IDE tests, I noticed that the Dotty IDE didn't behave as I expected in the following scenario: // Rename `Foo` to `Bar` class Foo { new Foo } The Dotty IDE would consider that 3 places need changing, instead of only 2: - The `Ident(Foo)` in the `TypeDef` - The `Ident(Foo)` in the constructor - The `Ident(Foo)` in `Select(new Foo, <init>)` The third tree, however is synthetic: it doesn't need to be changed in the editor. Trees whose positions are not derived from the source are now excluded when doing a rename.
1 parent bfe5387 commit a9b762b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ class DottyLanguageServer extends LanguageServer
303303
val newName = params.getNewName
304304

305305
val refs = Interactive.namedTrees(trees, includeReferences = true, tree =>
306-
(Interactive.matchSymbol(tree, sym, Include.overriding)
307-
|| (linkedSym != NoSymbol && Interactive.matchSymbol(tree, linkedSym, Include.overriding))))
306+
tree.pos.isSourceDerived
307+
&& (Interactive.matchSymbol(tree, sym, Include.overriding)
308+
|| (linkedSym != NoSymbol && Interactive.matchSymbol(tree, linkedSym, Include.overriding))))
308309

309310
val changes = refs.groupBy(ref => toUri(ref.source).toString).mapValues(_.map(ref => new TextEdit(range(ref.namePos), newName)).asJava)
310311

0 commit comments

Comments
 (0)