diff --git a/presentation-compiler/src/main/dotty/tools/pc/PcRenameProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/PcRenameProvider.scala index 666ccf9c614f..467f331ea7dc 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/PcRenameProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/PcRenameProvider.scala @@ -18,11 +18,19 @@ final class PcRenameProvider( name: Option[String] ) extends WithSymbolSearchCollector[l.TextEdit](driver, params): private val forbiddenMethods = - Set("equals", "hashCode", "unapply", "unary_!", "!") + Set("equals", "hashCode", "unapply", "apply", "", "unary_!", "!") + + private val soughtSymbolNames = soughtSymbols match + case Some((symbols, _)) => + symbols.filterNot(_.isError).map(symbol => symbol.decodedName.toString) + case None => Set.empty[String] + def canRenameSymbol(sym: Symbol)(using Context): Boolean = - (!sym.is(Method) || !forbiddenMethods(sym.decodedName)) - && (sym.ownersIterator.drop(1).exists(ow => ow.is(Method)) - || sym.source.path.isWorksheet) + val decodedName = sym.decodedName + def isForbiddenMethod = sym.is(Method) && forbiddenMethods(decodedName) + def local = sym.ownersIterator.drop(1).exists(ow => ow.is(Method)) + def isInWorksheet = sym.source.path.isWorksheet + !isForbiddenMethod && (local || isInWorksheet) && soughtSymbolNames(decodedName) def prepareRename(): Option[l.Range] = soughtSymbols.flatMap((symbols, pos) => diff --git a/presentation-compiler/test/dotty/tools/pc/tests/SelectionRangeSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/SelectionRangeSuite.scala index e277a67c466b..143d998a0ec1 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/SelectionRangeSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/SelectionRangeSuite.scala @@ -123,27 +123,13 @@ class SelectionRangeSuite extends BaseSelectionRangeSuite: |}""".stripMargin ) ) + + @Test def `def - type params` = check( - """|object Main extends App { - | val func = (a@@: Int, b: Int) => - | a + b - |}""".stripMargin, - List[String]( - """|object Main extends App { - | val func = (>>region>>a: Int< - | a + b - |}""".stripMargin, - """|object Main extends App { - | val func = (>>region>>a: Int, b: Int< - | a + b - |}""".stripMargin, - """|object Main extends App { - | val func = >>region>>(a: Int, b: Int) => - | a + b<>region>>val func = (a: Int, b: Int) => - | a + b<>region>>Type <: T1<>region>>Type <: T1, B<>region>>def foo[Type <: T1, B](hi: Int, b: Int, c:Int) = ???<