diff --git a/mtags-shared/src/main/scala/scala/meta/internal/mtags/CoursierComplete.scala b/mtags-shared/src/main/scala/scala/meta/internal/mtags/CoursierComplete.scala index 699443b2489..68fad5ad2e2 100644 --- a/mtags-shared/src/main/scala/scala/meta/internal/mtags/CoursierComplete.scala +++ b/mtags-shared/src/main/scala/scala/meta/internal/mtags/CoursierComplete.scala @@ -63,27 +63,28 @@ class CoursierComplete(scalaVersion: String) { dependency: String, supportNonJvm: Boolean ): List[String] = { - val (adjusted, hasDoubleColon) = adjustDoubleColon(dependency) + val adjusted = adjustDoubleColon(dependency) val sortedCompletions = completions(adjusted).sortWith( Version.fromString(_) >= Version.fromString(_) ) + def addDoubleColon: Boolean = + supportNonJvm && !hasSpecifiedPlatform(dependency) && + dependency.count(_ == ':') == 3 + // If dependency name doesn't end with `sjs` or `native` and we can default to `::` before version - if (!hasDoubleColon && supportNonJvm && !hasSpecifiedPlatform(dependency)) + if (addDoubleColon) sortedCompletions.map(":" + _) else sortedCompletions } - private def adjustDoubleColon(dependency: String): (String, Boolean) = { + private def adjustDoubleColon(dependency: String): String = { val doubleColon = dependency.lastIndexOf("::") - val firstColon = dependency.indexOf(":") - + val firstColon = dependency.indexOf("::") if (doubleColon > firstColon) { - val depString = (dependency.substring(0, doubleColon) + - dependency.substring(doubleColon + 1, dependency.length())) - (depString, true) - } else (dependency, false) + dependency.take(doubleColon) + dependency.drop(doubleColon + 1) + } else dependency } private def hasSpecifiedPlatform(dependency: String): Boolean = { diff --git a/tests/cross/src/test/scala/tests/pc/CompletionMillIvySuite.scala b/tests/cross/src/test/scala/tests/pc/CompletionMillIvySuite.scala index e7c8083c77c..f4b0f11c7ab 100644 --- a/tests/cross/src/test/scala/tests/pc/CompletionMillIvySuite.scala +++ b/tests/cross/src/test/scala/tests/pc/CompletionMillIvySuite.scala @@ -61,8 +61,8 @@ class CompletionMillIvySuite extends BaseCompletionSuite { ) check( - "version-double-colon", - """|val dependency = ivy"org.typelevel:cats-core_2.11::@@" + "version2", + """|val dependency = ivy"org.typelevel:cats-core_2.11:@@" |""".stripMargin, """|1.0.1 |1.0.0 @@ -86,23 +86,27 @@ class CompletionMillIvySuite extends BaseCompletionSuite { check( "version-double-colon2", - """|val dependency = ivy"org.typelevel:cats-core_2.11::1.0.@@" + """|val dependency = ivy"org.typelevel::cats-core::2.10@@" |""".stripMargin, - """|1.0.1 - |1.0.0 - |1.0.0-RC2 - |1.0.0-RC1 - |1.0.0-MF + """|2.10.0 |""".stripMargin, filename = "build.sc", ) checkEdit( "version-double-colon-edit", - """|val dependency = ivy"org.typelevel:cats-core_2.11::1.0.1@@" + """|val dependency = ivy"org.typelevel::cats-core::2.10@@" |""".stripMargin, - """|val dependency = ivy"org.typelevel:cats-core_2.11::1.0.1" + """|val dependency = ivy"org.typelevel::cats-core::2.10.0" + |""".stripMargin, + filename = "build.sc", + ) + + check( + "version-double-colon3", + """|val dependency = ivy"org.typelevel:cats-core_2.11::1.0.@@" |""".stripMargin, + "", filename = "build.sc", ) diff --git a/tests/cross/src/test/scala/tests/pc/CompletionScalaCliSuite.scala b/tests/cross/src/test/scala/tests/pc/CompletionScalaCliSuite.scala index 0894a11ea64..422036df741 100644 --- a/tests/cross/src/test/scala/tests/pc/CompletionScalaCliSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/CompletionScalaCliSuite.scala @@ -200,6 +200,25 @@ class CompletionScalaCliSuite extends BaseCompletionSuite { filter = _.startsWith("3.7.1"), ) + check( + "version-double-colon3", + """|//> using lib "com.outr:scribe-cats_3::@@" + |package A + |""".stripMargin, + "", + ) + + checkEdit( + "version-double-colon-edit2", + """|//> using lib "com.outr:scribe-cats_3:3.7@@" + |package A + |""".stripMargin, + """|//> using lib "com.outr:scribe-cats_3:3.7.1" + |package A + |""".stripMargin, + filter = _.startsWith("3.7.1"), + ) + private def scriptWrapper(code: String, filename: String): String = // Vaguely looks like a scala file that ScalaCLI generates // from a sc file.