Skip to content

Commit 492f777

Browse files
authored
Fix presentation compiler autoimports, update presentation compiler dependencies (#18264)
2 parents 7613234 + b5cb4b9 commit 492f777

File tree

6 files changed

+68
-16
lines changed

6 files changed

+68
-16
lines changed

presentation-compiler/src/main/dotty/tools/pc/printer/ShortenedTypePrinter.scala

+6-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ShortenedTypePrinter(
4545
isTextEdit: Boolean = false,
4646
renameConfigMap: Map[Symbol, String] = Map.empty
4747
)(using indexedCtx: IndexedContext, reportCtx: ReportContext) extends RefinedPrinter(indexedCtx.ctx):
48-
private val missingImports: mutable.ListBuffer[ImportSel] = mutable.ListBuffer.empty
48+
private val missingImports: mutable.Set[ImportSel] = mutable.Set.empty
4949
private val defaultWidth = 1000
5050

5151
private val methodFlags =
@@ -81,7 +81,8 @@ class ShortenedTypePrinter(
8181
* Returns a list of TextEdits (auto-imports) of the symbols
8282
*/
8383
def imports(autoImportsGen: AutoImportsGenerator): List[TextEdit] =
84-
missingImports.toList
84+
missingImports
85+
.toList
8586
.filterNot(selector => selector.sym.isRoot)
8687
.sortBy(_.sym.effectiveName)
8788
.flatMap(selector => autoImportsGen.renderImports(List(selector)))
@@ -112,7 +113,9 @@ class ShortenedTypePrinter(
112113
def ownersAfterRename(owner: Symbol): List[Symbol] =
113114
prefix.ownersIterator.takeWhile(_ != owner).toList
114115

115-
prefix.ownersIterator.flatMap { owner =>
116+
val prefixIterator = if isTextEdit then prefix.ownersIterator else Iterator(prefix)
117+
118+
prefixIterator.flatMap { owner =>
116119
val prefixAfterRename = ownersAfterRename(owner)
117120
val currentRenamesSearchResult =
118121
indexedCtx.rename(owner).map(Found(owner, _, prefixAfterRename))

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionOverrideSuite.scala

+38
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,44 @@ class CompletionOverrideSuite extends BaseCompletionSuite:
342342
|""".stripMargin
343343
)
344344

345+
@Test def `jutil-package` =
346+
checkEdit(
347+
"""|abstract class JUtil {
348+
| def foo: java.util.concurrent.CompletableFuture[Int]
349+
|}
350+
|class Main extends JUtil {
351+
| def foo@@
352+
|}
353+
|""".stripMargin,
354+
"""|import java.util.concurrent.CompletableFuture
355+
|abstract class JUtil {
356+
| def foo: java.util.concurrent.CompletableFuture[Int]
357+
|}
358+
|class Main extends JUtil {
359+
| def foo: CompletableFuture[Int] = ${0:???}
360+
|}
361+
|""".stripMargin
362+
)
363+
364+
@Test def `jutil-multiple-symbols` =
365+
checkEdit(
366+
"""|abstract class JUtil {
367+
| def foo(x: java.util.List[Int]): java.util.List[Int]
368+
|}
369+
|class Main extends JUtil {
370+
| override def fo@@
371+
|}
372+
|""".stripMargin,
373+
"""|import java.{util => ju}
374+
|abstract class JUtil {
375+
| def foo(x: java.util.List[Int]): java.util.List[Int]
376+
|}
377+
|class Main extends JUtil {
378+
| override def foo(x: ju.List[Int]): ju.List[Int] = ${0:???}
379+
|}
380+
|""".stripMargin
381+
)
382+
345383
@Test def `jutil-conflict` =
346384
checkEdit(
347385
"""|package jutil

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionScalaCliSuite.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class CompletionScalaCliSuite extends BaseCompletionSuite:
106106
"""|//> using lib "co.fs2::fs2-core:@@"
107107
|package A
108108
|""".stripMargin,
109-
"""|//> using lib "co.fs2::fs2-core:3.4.0"
109+
"""|//> using lib "co.fs2::fs2-core::3.4.0"
110110
|package A
111111
|""".stripMargin,
112112
filter = _.startsWith("3.4")

presentation-compiler/test/dotty/tools/pc/tests/edit/AutoImplementAbstractMembersSuite.scala

+20
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,26 @@ class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite:
373373
|""".stripMargin
374374
)
375375

376+
@Test def `jutil-multiple-symbols` =
377+
checkEdit(
378+
"""|abstract class JUtil {
379+
| def foo(x: java.util.List[Int]): java.util.List[Int]
380+
|}
381+
|class <<Main>> extends JUtil {
382+
|}
383+
|""".stripMargin,
384+
"""|import java.{util => ju}
385+
|abstract class JUtil {
386+
| def foo(x: java.util.List[Int]): java.util.List[Int]
387+
|}
388+
|class Main extends JUtil {
389+
|
390+
| override def foo(x: ju.List[Int]): ju.List[Int] = ???
391+
|
392+
|}
393+
|""".stripMargin
394+
)
395+
376396
@Test def `jutil-conflict` =
377397
checkEdit(
378398
"""|package jutil

presentation-compiler/test/dotty/tools/pc/tests/edit/InsertInferredTypeSuite.scala

-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ import org.junit.Test
1313

1414
class InsertInferredTypeSuite extends BaseCodeActionSuite:
1515

16-
// override def extraDependencies(scalaVersion: String): Seq[Dependency] = {
17-
// val binaryVersion = createBinaryVersion(scalaVersion)
18-
// Seq(
19-
// Dependency.of("org.typelevel", s"cats-effect_$binaryVersion", "3.1.1")
20-
// )
21-
// }
22-
2316
@Test def `val` =
2417
checkEdit(
2518
"""|object A{

project/Build.scala

+3-5
Original file line numberDiff line numberDiff line change
@@ -1185,19 +1185,17 @@ object Build {
11851185
BuildInfoPlugin.buildInfoDefaultSettings
11861186

11871187
lazy val presentationCompilerSettings = {
1188-
val mtagsVersion = "0.11.12+165-7d0397b3-SNAPSHOT" // Will be set to stable release after 0.11.13 is published
1188+
val mtagsVersion = "1.0.0"
11891189

11901190
Seq(
11911191
libraryDependencies ++= Seq(
11921192
"org.lz4" % "lz4-java" % "1.8.0",
1193-
"io.get-coursier" % "interface" % "1.0.13",
1193+
"io.get-coursier" % "interface" % "1.0.18",
11941194
"org.scalameta" % "mtags-interfaces" % mtagsVersion,
11951195
),
1196+
libraryDependencies += ("org.scalameta" % "mtags-shared_2.13.11" % mtagsVersion % SourceDeps),
11961197
ivyConfigurations += SourceDeps.hide,
11971198
transitiveClassifiers := Seq("sources"),
1198-
resolvers += Resolver.defaultLocal,
1199-
resolvers ++= Resolver.sonatypeOssRepos("snapshots"), // To be removed after 0.11.13 is published
1200-
libraryDependencies += ("org.scalameta" % "mtags-shared_2.13.11" % mtagsVersion % "sourcedeps"),
12011199
(Compile / sourceGenerators) += Def.task {
12021200
val s = streams.value
12031201
val cacheDir = s.cacheDirectory

0 commit comments

Comments
 (0)