Skip to content

Commit

Permalink
fix: Fix scala-cli dep completions for scala-cli 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk committed Jun 20, 2023
1 parent 99dc09f commit b3e6e42
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@ import scala.meta.internal.pc.MetalsGlobal
trait ScalaCliCompletions {
this: MetalsGlobal =>
class ScalaCliExtractor(pos: Position) {
def unapply(path: List[Tree]): Option[String] =
def unapply(path: List[Tree]): Option[String] = {
def scalaCliDep = CoursierComplete.isScalaCliDep(
pos.lineContent
.take(pos.column - 1)
.stripPrefix("/*<script>*/")
)

path match {
case Nil =>
CoursierComplete.isScalaCliDep(
pos.lineContent.replace(CURSOR, "").take(pos.column - 1)
)
// generated script file will end with .sc.scala
case (_: Template) :: (_: ModuleDef) :: _
case (_: Template) :: (_: ModuleDef) :: (_: PackageDef) :: Nil
if pos.source.file.path.endsWith(".sc.scala") =>
CoursierComplete.isScalaCliDep(
pos.lineContent
.stripPrefix("/*<script>*/")
.replace(CURSOR, "")
.take(pos.column - 1)
)
scalaCliDep
case (_: Template) :: (_: ClassDef) :: (_: PackageDef) :: Nil
if pos.source.file.path.endsWith(".sc.scala") =>
scalaCliDep
case _ => None
}
}
}

case class ScalaCliCompletion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class ScalaCliCompletions(
// generated script file will end with .sc.scala
case (_: TypeDef) :: Nil if pos.source.file.path.endsWith(".sc.scala") =>
scalaCliDep
case (_: Template) :: (_: TypeDef) :: Nil
if pos.source.file.path.endsWith(".sc.scala") =>
scalaCliDep
case head :: next => None

def contribute(dependency: String) =
Expand Down
7 changes: 7 additions & 0 deletions tests/slow/src/test/scala/tests/scalacli/ScalaCliSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ class ScalaCliSuite extends BaseScalaCliSuite(V.scala3) {
s"Expected no scalameta errors, got: $parserDiagnostics",
)

completion <- server.completion(
"MyTests.sc",
"//> using lib \"com.lihao@@yi::utest::0.7.9\"",
)

_ = assertNoDiff(completion, "com.lihaoyi")

} yield ()

private val simpleFileLayout =
Expand Down

0 comments on commit b3e6e42

Please sign in to comment.