Skip to content

Fix presentation compiler autoimports, update presentation compiler dependencies #18264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<Main>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 3 additions & 5 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down