From a7e0ec0e52c95adab14f8e3e70d698562bbf9626 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Fri, 14 Mar 2025 11:32:29 +0100 Subject: [PATCH 1/2] Show the Autofill completion case as what would be auto-filled --- .../tools/pc/completions/CompletionValue.scala | 8 ++++++-- .../tools/pc/completions/NamedArgCompletions.scala | 9 ++++++++- .../pc/tests/completion/CompletionArgSuite.scala | 13 +++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) 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..80cf689208b6 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala @@ -261,13 +261,17 @@ object CompletionValue: end NamedArg case class Autofill( - value: String + value: String, + _label: String, ) extends CompletionValue: + private inline val descriptionText = "Autofill with default values" override def completionItemKind(using Context): CompletionItemKind = CompletionItemKind.Enum override def completionItemDataKind: Integer = CompletionSource.OverrideKind.ordinal override def insertText: Option[String] = Some(value) - override def label: String = "Autofill with default values" + override def label: String = _label + override def description(printer: ShortenedTypePrinter)(using Context): String = descriptionText + override def filterText: Option[String] = Some(label + " " + descriptionText) case class Keyword(label: String, override val insertText: Option[String]) extends CompletionValue: diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/NamedArgCompletions.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/NamedArgCompletions.scala index dd3a910beb4f..a21706b9e36e 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/NamedArgCompletions.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/NamedArgCompletions.scala @@ -339,9 +339,16 @@ object NamedArgCompletions: s"${param.nameBackticked.replace("$", "$$")} = $${${index + 1}${findDefaultValue(param)}}" } .mkString(", ") + val labelText = allParams + .collect { + case param if !param.symbol.is(Flags.HasDefault) => + s"${param.nameBackticked.replace("$", "$$")} = ???" + } + .mkString(", ") List( CompletionValue.Autofill( - editText + editText, + labelText, ) ) else List.empty diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala index dc81d2596c6f..9ddf7b63e91e 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala @@ -1128,3 +1128,16 @@ class CompletionArgSuite extends BaseCompletionSuite: """x: Int |x = : Any""".stripMargin, ) + + @Test def `autofill-arguments-case-class` = + check( + """ + |case class A(x: Int, y: Int) + | + |def main() = + | A(x@@) + |""".stripMargin, + """x = : Int + |x = ???, y = ???Autofill with default values""".stripMargin, + // this looks strange due to the Autofill message belonging to the description + ) From b9c38d77e7640b750d46305f9f4064863a4738d1 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Mon, 17 Mar 2025 16:01:26 +0100 Subject: [PATCH 2/2] Drop `Autofill from default values` from label --- .../main/dotty/tools/pc/completions/CompletionValue.scala | 6 +----- .../tools/pc/tests/completion/CompletionArgSuite.scala | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) 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 80cf689208b6..05d97972d76e 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala @@ -262,16 +262,12 @@ object CompletionValue: case class Autofill( value: String, - _label: String, + override val label: String, ) extends CompletionValue: - private inline val descriptionText = "Autofill with default values" override def completionItemKind(using Context): CompletionItemKind = CompletionItemKind.Enum override def completionItemDataKind: Integer = CompletionSource.OverrideKind.ordinal override def insertText: Option[String] = Some(value) - override def label: String = _label - override def description(printer: ShortenedTypePrinter)(using Context): String = descriptionText - override def filterText: Option[String] = Some(label + " " + descriptionText) case class Keyword(label: String, override val insertText: Option[String]) extends CompletionValue: diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala index 9ddf7b63e91e..e5f2d31ad808 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala @@ -1138,6 +1138,6 @@ class CompletionArgSuite extends BaseCompletionSuite: | A(x@@) |""".stripMargin, """x = : Int - |x = ???, y = ???Autofill with default values""".stripMargin, + |x = ???, y = ???""".stripMargin, // this looks strange due to the Autofill message belonging to the description )