diff --git a/presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala b/presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala index 8237e286ceff..10978f9d33b8 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala @@ -45,7 +45,7 @@ class ShortenedTypePrinter( isTextEdit: Boolean = false, renameConfigMap: Map[Symbol, String] = Map.empty )(using indexedCtx: IndexedContext, reportCtx: ReportContext) extends RefinedPrinter(indexedCtx.ctx): - private val missingImports: mutable.ListBuffer[ImportSel] = mutable.ListBuffer.empty + private val missingImports: mutable.Set[ImportSel] = mutable.Set.empty private val defaultWidth = 1000 private val methodFlags = @@ -81,7 +81,8 @@ class ShortenedTypePrinter( * Returns a list of TextEdits (auto-imports) of the symbols */ def imports(autoImportsGen: AutoImportsGenerator): List[TextEdit] = - missingImports.toList + missingImports + .toList .filterNot(selector => selector.sym.isRoot) .sortBy(_.sym.effectiveName) .flatMap(selector => autoImportsGen.renderImports(List(selector))) @@ -112,7 +113,9 @@ class ShortenedTypePrinter( def ownersAfterRename(owner: Symbol): List[Symbol] = prefix.ownersIterator.takeWhile(_ != owner).toList - prefix.ownersIterator.flatMap { owner => + val prefixIterator = if isTextEdit then prefix.ownersIterator else Iterator(prefix) + + prefixIterator.flatMap { owner => val prefixAfterRename = ownersAfterRename(owner) val currentRenamesSearchResult = indexedCtx.rename(owner).map(Found(owner, _, prefixAfterRename)) diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionOverrideSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionOverrideSuite.scala index 690427688705..8bc45d344244 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionOverrideSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionOverrideSuite.scala @@ -342,6 +342,44 @@ class CompletionOverrideSuite extends BaseCompletionSuite: |""".stripMargin ) + @Test def `jutil-package` = + checkEdit( + """|abstract class JUtil { + | def foo: java.util.concurrent.CompletableFuture[Int] + |} + |class Main extends JUtil { + | def foo@@ + |} + |""".stripMargin, + """|import java.util.concurrent.CompletableFuture + |abstract class JUtil { + | def foo: java.util.concurrent.CompletableFuture[Int] + |} + |class Main extends JUtil { + | def foo: CompletableFuture[Int] = ${0:???} + |} + |""".stripMargin + ) + + @Test def `jutil-multiple-symbols` = + checkEdit( + """|abstract class JUtil { + | def foo(x: java.util.List[Int]): java.util.List[Int] + |} + |class Main extends JUtil { + | override def fo@@ + |} + |""".stripMargin, + """|import java.{util => ju} + |abstract class JUtil { + | def foo(x: java.util.List[Int]): java.util.List[Int] + |} + |class Main extends JUtil { + | override def foo(x: ju.List[Int]): ju.List[Int] = ${0:???} + |} + |""".stripMargin + ) + @Test def `jutil-conflict` = checkEdit( """|package jutil diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionScalaCliSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionScalaCliSuite.scala index 95dc3305375c..c55b5277122b 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionScalaCliSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionScalaCliSuite.scala @@ -106,7 +106,7 @@ class CompletionScalaCliSuite extends BaseCompletionSuite: """|//> using lib "co.fs2::fs2-core:@@" |package A |""".stripMargin, - """|//> using lib "co.fs2::fs2-core:3.4.0" + """|//> using lib "co.fs2::fs2-core::3.4.0" |package A |""".stripMargin, filter = _.startsWith("3.4") diff --git a/presentation-compiler/test/dotty/tools/pc/tests/edit/AutoImplementAbstractMembersSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/edit/AutoImplementAbstractMembersSuite.scala index a0cf2bbc63cb..f781e226944b 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/edit/AutoImplementAbstractMembersSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/edit/AutoImplementAbstractMembersSuite.scala @@ -373,6 +373,26 @@ class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite: |""".stripMargin ) + @Test def `jutil-multiple-symbols` = + checkEdit( + """|abstract class JUtil { + | def foo(x: java.util.List[Int]): java.util.List[Int] + |} + |class <
> extends JUtil { + |} + |""".stripMargin, + """|import java.{util => ju} + |abstract class JUtil { + | def foo(x: java.util.List[Int]): java.util.List[Int] + |} + |class Main extends JUtil { + | + | override def foo(x: ju.List[Int]): ju.List[Int] = ??? + | + |} + |""".stripMargin + ) + @Test def `jutil-conflict` = checkEdit( """|package jutil diff --git a/presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredTypeSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredTypeSuite.scala index 6c8772ba40b8..982264fa4b2a 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredTypeSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredTypeSuite.scala @@ -13,13 +13,6 @@ import org.junit.Test class InsertInferredTypeSuite extends BaseCodeActionSuite: - // override def extraDependencies(scalaVersion: String): Seq[Dependency] = { - // val binaryVersion = createBinaryVersion(scalaVersion) - // Seq( - // Dependency.of("org.typelevel", s"cats-effect_$binaryVersion", "3.1.1") - // ) - // } - @Test def `val` = checkEdit( """|object A{ diff --git a/project/Build.scala b/project/Build.scala index 677532fd7cef..cb656dff36a8 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1186,19 +1186,17 @@ object Build { BuildInfoPlugin.buildInfoDefaultSettings lazy val presentationCompilerSettings = { - val mtagsVersion = "0.11.12+165-7d0397b3-SNAPSHOT" // Will be set to stable release after 0.11.13 is published + val mtagsVersion = "1.0.0" Seq( libraryDependencies ++= Seq( "org.lz4" % "lz4-java" % "1.8.0", - "io.get-coursier" % "interface" % "1.0.13", + "io.get-coursier" % "interface" % "1.0.18", "org.scalameta" % "mtags-interfaces" % mtagsVersion, ), + libraryDependencies += ("org.scalameta" % "mtags-shared_2.13.11" % mtagsVersion % SourceDeps), ivyConfigurations += SourceDeps.hide, transitiveClassifiers := Seq("sources"), - resolvers += Resolver.defaultLocal, - resolvers ++= Resolver.sonatypeOssRepos("snapshots"), // To be removed after 0.11.13 is published - libraryDependencies += ("org.scalameta" % "mtags-shared_2.13.11" % mtagsVersion % "sourcedeps"), (Compile / sourceGenerators) += Def.task { val s = streams.value val cacheDir = s.cacheDirectory