diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/AmmoniteIvyCompletions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/AmmoniteIvyCompletions.scala index 718b57cd4828..667c6c5fb2b1 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/AmmoniteIvyCompletions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/AmmoniteIvyCompletions.scala @@ -34,7 +34,7 @@ object AmmoniteIvyCompletions: val completions = coursierComplete.complete(dependency.nn) completions .map(insertText => - CompletionValue.IvyImport( + CompletionValue.Coursier( insertText.stripPrefix(":"), Some(insertText), Some(ivyEditRange) diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala index 90b285bffb3a..55c2737c36e6 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala @@ -30,7 +30,7 @@ enum CompletionSource: case NamedArgKind case AutoFillKind case FileSystemMemberKind - case IvyImportKind + case CoursierKind case InterpolatorKind case MatchCompletionKind case CaseKeywordKind @@ -286,13 +286,13 @@ object CompletionValue: override def completionItemKind(using Context): CompletionItemKind = CompletionItemKind.File - case class IvyImport( + case class Coursier( label: String, override val insertText: Option[String], override val range: Option[Range] ) extends CompletionValue: override val filterText: Option[String] = insertText - override def completionItemDataKind: Integer = CompletionSource.IvyImportKind.ordinal + override def completionItemDataKind: Integer = CompletionSource.CoursierKind.ordinal override def completionItemKind(using Context): CompletionItemKind = CompletionItemKind.Folder diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala index 05dbe1ef5a43..2eeb44f5d7e7 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala @@ -701,7 +701,7 @@ class Completions( (autofill.label, true) case fileSysMember: CompletionValue.FileSystemMember => (fileSysMember.label, true) - case ii: CompletionValue.IvyImport => (ii.label, true) + case ii: CompletionValue.Coursier => (ii.label, true) case sv: CompletionValue.SingletonValue => (sv.label, true) if !alreadySeen(id) && include then @@ -985,10 +985,7 @@ class Completions( o1.label, o2.label ) - case ( - sym1: CompletionValue.Symbolic, - sym2: CompletionValue.Symbolic, - ) => + case (sym1: CompletionValue.Symbolic, sym2: CompletionValue.Symbolic) => if compareCompletionValue(sym1, sym2) then 0 else if compareCompletionValue(sym2, sym1) then 1 else @@ -1037,6 +1034,8 @@ class Completions( end if end if end if + case (sym1: CompletionValue.Coursier, sym2: CompletionValue.Coursier) => + sym1.label.compareTo(sym2.label) case _ => val byClass = prioritizeByClass(o1, o2) if byClass != 0 then byClass diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/ScalaCliCompletions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/ScalaCliCompletions.scala index e2a0a033ee6b..85108b143edc 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/ScalaCliCompletions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/ScalaCliCompletions.scala @@ -30,7 +30,7 @@ class ScalaCliCompletions( val editRange = pos.withStart(editStart).withEnd(editEnd).toLsp completions .map(insertText => - CompletionValue.IvyImport( + CompletionValue.Coursier( insertText.stripPrefix(":"), Some(insertText), Some(editRange) diff --git a/presentation-compiler/test/dotty/tools/pc/base/BaseCompletionSuite.scala b/presentation-compiler/test/dotty/tools/pc/base/BaseCompletionSuite.scala index 3e5269b947a0..7c7d75a535c6 100644 --- a/presentation-compiler/test/dotty/tools/pc/base/BaseCompletionSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/base/BaseCompletionSuite.scala @@ -219,7 +219,10 @@ abstract class BaseCompletionSuite extends BasePCSuite: case Some(top) => baseItems.take(top) case None => baseItems val filteredItems = items.filter(item => filter(item.getLabel)) - filteredItems.foreach { item => + val nonEmptyExpected = filteredItems.isEmpty && expected.linesIterator.exists(_.trim.nonEmpty) + val result = if nonEmptyExpected then items else filteredItems + + result.foreach { item => val label = TestCompletions.getFullyQualifiedLabel(item) val commitCharacter = if includeCommitCharacter then @@ -247,6 +250,7 @@ abstract class BaseCompletionSuite extends BasePCSuite: }) .append(commitCharacter) .append(completionKind) + .append(if nonEmptyExpected then " [FILTERED OUT]" else "") .append("\n") } val completionSources = filteredItems 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 b542e4ba84e3..6ce85b37c9a4 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionScalaCliSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionScalaCliSuite.scala @@ -140,6 +140,17 @@ class CompletionScalaCliSuite extends BaseCompletionSuite: |io.circul""".stripMargin ) + @Test def `lexicographic-order` = + checkSubset( + """|//> using dep "org.scala-lang@@" + |package A + |""".stripMargin, + """|org.scala-lang + |org.scala-lang-osgi + |org.scala-lang.modules + |""".stripMargin + ) + @Ignore @Test def `multiple-deps2` = checkSubset(