diff --git a/metals/src/main/scala/scala/meta/internal/metals/InitializationOptions.scala b/metals/src/main/scala/scala/meta/internal/metals/InitializationOptions.scala index 3b6cea590d5..a5acb3d0b82 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/InitializationOptions.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/InitializationOptions.scala @@ -200,6 +200,9 @@ object InitializationOptions { isSignatureHelpDocumentationEnabled = compilerObj.flatMap( _.getBooleanOption("isSignatureHelpDocumentationEnabled") ), + isDetailIncludedInLabel = compilerObj.flatMap( + _.getBooleanOption("isDetailIncludedInLabel") + ), overrideDefFormat = compilerObj.flatMap( _.getStringOption("overrideDefFormat") ), @@ -210,7 +213,6 @@ object InitializationOptions { compilerObj.flatMap(_.getBooleanOption("snippetAutoIndent")), ) } - } sealed trait CommandHTMLFormat { diff --git a/metals/src/main/scala/scala/meta/internal/metals/MetalsServerConfig.scala b/metals/src/main/scala/scala/meta/internal/metals/MetalsServerConfig.scala index ad8b2e2396a..eb5d14565f8 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/MetalsServerConfig.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/MetalsServerConfig.scala @@ -225,7 +225,8 @@ object MetalsServerConfig { base.copy( executeClientCommand = ExecuteClientCommandConfig.on, compilers = base.compilers.copy( - snippetAutoIndent = false + snippetAutoIndent = false, + isDetailIncludedInLabel = false, ), ) case _ => diff --git a/mtags-interfaces/src/main/java/scala/meta/pc/PresentationCompilerConfig.java b/mtags-interfaces/src/main/java/scala/meta/pc/PresentationCompilerConfig.java index afcd8bb3616..13fc0900052 100644 --- a/mtags-interfaces/src/main/java/scala/meta/pc/PresentationCompilerConfig.java +++ b/mtags-interfaces/src/main/java/scala/meta/pc/PresentationCompilerConfig.java @@ -96,6 +96,13 @@ enum OverrideDefFormat { */ boolean isCompletionSnippetsEnabled(); + /** + * Returns true if the completion's description should be included in the label. + */ + default boolean isDetailIncludedInLabel() { + return true; + } + /** * The maximum delay for requests to respond. * diff --git a/mtags-shared/src/main/scala/scala/meta/internal/pc/CompilerInitializationOptions.scala b/mtags-shared/src/main/scala/scala/meta/internal/pc/CompilerInitializationOptions.scala index 57b5e583277..274b49f6012 100644 --- a/mtags-shared/src/main/scala/scala/meta/internal/pc/CompilerInitializationOptions.scala +++ b/mtags-shared/src/main/scala/scala/meta/internal/pc/CompilerInitializationOptions.scala @@ -16,6 +16,8 @@ package scala.meta.internal.pc * @param isHoverDocumentationEnabled whether to include docstrings in a `textDocument/hover`. * @param isSignatureHelpDocumentationEnabled whether the `SignatureHelp.documentation` field * should be populated. + * @param isDetailIncludedInLabel whether the completion's description should be included in the + * label. * @param overrideDefFormat whether the override should include a unicode icon or only ascii. * @param parameterHintsCommand command identifier to trigger parameter hints. * @param snippetAutoIndent whether the client defaults to adding the indentation of the reference @@ -28,6 +30,7 @@ case class CompilerInitializationOptions( isCompletionItemResolve: Option[Boolean], isHoverDocumentationEnabled: Option[Boolean], isSignatureHelpDocumentationEnabled: Option[Boolean], + isDetailIncludedInLabel: Option[Boolean], overrideDefFormat: Option[String], parameterHintsCommand: Option[String], snippetAutoIndent: Option[Boolean] @@ -44,6 +47,7 @@ object CompilerInitializationOptions { None, None, None, + None, None ) } diff --git a/mtags-shared/src/main/scala/scala/meta/internal/pc/PresentationCompilerConfigImpl.scala b/mtags-shared/src/main/scala/scala/meta/internal/pc/PresentationCompilerConfigImpl.scala index 12db83917cf..18b72bb5248 100644 --- a/mtags-shared/src/main/scala/scala/meta/internal/pc/PresentationCompilerConfigImpl.scala +++ b/mtags-shared/src/main/scala/scala/meta/internal/pc/PresentationCompilerConfigImpl.scala @@ -22,6 +22,7 @@ case class PresentationCompilerConfigImpl( snippetAutoIndent: Boolean = true, isSignatureHelpDocumentationEnabled: Boolean = true, isCompletionSnippetsEnabled: Boolean = true, + override val isDetailIncludedInLabel: Boolean = true, isCompletionItemResolve: Boolean = true, _isStripMarginOnTypeFormattingEnabled: () => Boolean = () => true, timeoutDelay: Long = 20, @@ -72,6 +73,9 @@ case class PresentationCompilerConfigImpl( isCompletionItemResolve = options.isCompletionItemResolve.getOrElse( this.isCompletionItemResolve ), + isDetailIncludedInLabel = options.isDetailIncludedInLabel.getOrElse( + this.isDetailIncludedInLabel + ), _parameterHintsCommand = options.parameterHintsCommand.orElse( this._parameterHintsCommand ), diff --git a/mtags/src/main/scala-2/scala/meta/internal/pc/CompletionProvider.scala b/mtags/src/main/scala-2/scala/meta/internal/pc/CompletionProvider.scala index b6e6c930994..9a57c565461 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/pc/CompletionProvider.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/pc/CompletionProvider.scala @@ -110,8 +110,11 @@ class CompletionProvider( case _ => detailString(member, history) } + val includeDetailInLabel = compiler.metalsConfig.isDetailIncludedInLabel def labelWithSig = - if (member.sym.isMethod || member.sym.isValue) { + if ( + includeDetailInLabel && (member.sym.isMethod || member.sym.isValue) + ) { ident + detail } else { ident @@ -128,7 +131,7 @@ class CompletionProvider( o.label.getOrElse(labelWithSig) case _: WorkspaceImplicitMember => s"$labelWithSig (implicit)" - case o: WorkspaceMember => + case o: WorkspaceMember if includeDetailInLabel => s"$ident - ${o.sym.owner.fullName}" case _ => labelWithSig } diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/CompletionProvider.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/CompletionProvider.scala index 19a93ae188f..d591d509b1e 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/CompletionProvider.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/CompletionProvider.scala @@ -162,7 +162,11 @@ class CompletionProvider( // related issue https://github.com/lampepfl/dotty/issues/11941 lazy val kind: CompletionItemKind = completion.completionItemKind val description = completion.description(printer) - val label = completion.labelWithDescription(printer) + val label = + if config.isDetailIncludedInLabel then + completion.labelWithDescription(printer) + else + completion.label val ident = completion.insertText.getOrElse(completion.label) def mkItem( diff --git a/tests/cross/src/test/scala/tests/pc/CompletionWithoutDetailsSuite.scala b/tests/cross/src/test/scala/tests/pc/CompletionWithoutDetailsSuite.scala new file mode 100644 index 00000000000..74aa27b6b03 --- /dev/null +++ b/tests/cross/src/test/scala/tests/pc/CompletionWithoutDetailsSuite.scala @@ -0,0 +1,151 @@ +package tests.pc + +import scala.meta.internal.pc.PresentationCompilerConfigImpl +import scala.meta.pc.PresentationCompilerConfig + +import tests.BaseCompletionSuite + +class CompletionWithoutDetailsSuite extends BaseCompletionSuite { + + override def config: PresentationCompilerConfig = + PresentationCompilerConfigImpl().copy( + isDetailIncludedInLabel = false + ) + + check( + "scope", + """ + |object A { + | Lis@@ + |}""".stripMargin, + """|List + |List + |List + |JList + |ListUI + |""".stripMargin, + compat = Map( + "2.13" -> + """|List + |LazyList + |List + |List + |JList + |""".stripMargin, + "3" -> + """|List + |List + |List + |List + |List + |""".stripMargin + ), + includeDetail = false, + topLines = Some(5) + ) + + check( + "scope-detail", + """ + |object A { + | Lis@@ + |}""".stripMargin, + """|List scala.collection.immutable + |List java.awt + |List java.util + |JList javax.swing + |ListUI javax.swing.plaf + |""".stripMargin, + compat = Map( + "2.13" -> + """|List scala.collection.immutable + |LazyList scala.collection.immutable + |List java.awt + |List java.util + |JList javax.swing + |""".stripMargin, + "3" -> + """|List scala.collection.immutable + |List java.awt + |List java.util + |List scala.collection.immutable + |List[A](elems: A*): CC[A] + |""".stripMargin + ), + includeDetail = true, + topLines = Some(5) + ) + + check( + "member", + """ + |object A { + | List.emp@@ + |}""".stripMargin, + """ + |empty + |""".stripMargin, + includeDetail = false + ) + + check( + "extension", + """ + |object A { + | "".stripSu@@ + |}""".stripMargin, + """|stripSuffix + |""".stripMargin, + includeDetail = false + ) + + check( + "tparam", + """ + |class Foo[A] { + | def identity[B >: A](a: B): B = a + |} + |object Foo { + | new Foo[Int].ident@@ + |}""".stripMargin, + """|identity + |""".stripMargin, + includeDetail = false + ) + + check( + "tparam1", + """ + |class Foo[A] { + | def identity(a: A): A = a + |} + |object Foo { + | new Foo[Int].ident@@ + |}""".stripMargin, + """|identity + |""".stripMargin, + includeDetail = false + ) + + check( + "tparam2", + """ + |object A { + | Map.empty[Int, String].getOrEl@@ + |} + |""".stripMargin, + """|getOrElse + |""".stripMargin, + includeDetail = false + ) + + check( + "pkg", + """ + |import scala.collection.conc@@ + |""".stripMargin, + """|concurrent + |""".stripMargin, + includeDetail = false + ) +}