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

improvement: Make including detail in completion label configurable #6986

Merged
merged 2 commits into from
Dec 6, 2024
Merged
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 @@ -200,6 +200,9 @@ object InitializationOptions {
isSignatureHelpDocumentationEnabled = compilerObj.flatMap(
_.getBooleanOption("isSignatureHelpDocumentationEnabled")
),
isDetailIncludedInLabel = compilerObj.flatMap(
_.getBooleanOption("isDetailIncludedInLabel")
),
overrideDefFormat = compilerObj.flatMap(
_.getStringOption("overrideDefFormat")
),
Expand All @@ -210,7 +213,6 @@ object InitializationOptions {
compilerObj.flatMap(_.getBooleanOption("snippetAutoIndent")),
)
}

}

sealed trait CommandHTMLFormat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ object MetalsServerConfig {
base.copy(
executeClientCommand = ExecuteClientCommandConfig.on,
compilers = base.compilers.copy(
snippetAutoIndent = false
snippetAutoIndent = false,
isDetailIncludedInLabel = false,
),
)
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -44,6 +47,7 @@ object CompilerInitializationOptions {
None,
None,
None,
None,
None
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
}
Loading