Skip to content
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

Coursier dependency imports should have lexicographic ordering #21592

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum CompletionSource:
case NamedArgKind
case AutoFillKind
case FileSystemMemberKind
case IvyImportKind
case CoursierKind
case InterpolatorKind
case MatchCompletionKind
case CaseKeywordKind
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading