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:don't show types for match case for showInferredType #5284

Merged
merged 9 commits into from
Jul 21, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ class SemanticdbTreePrinter(
* hello<<[String]>>("")
*/
case tree @ s.TypeApplyTree(_: s.OriginalTree | _: s.SelectTree, _)
if !ignoreTypesTrees && userConfig.showInferredType =>
if !ignoreTypesTrees && userConfig.showInferredType
.contains("true") =>
gatherSynthetics(tree)
/**
* implicit def implicitFun(object: T): R = ???
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ final class SyntheticsDecorationProvider(
}

private def areSyntheticsEnabled: Boolean = {
userConfig().showImplicitArguments || userConfig().showInferredType || userConfig().showImplicitConversionsAndClasses
val showInferredType = !userConfig().showInferredType.contains(
"false"
) && userConfig().showInferredType.nonEmpty
userConfig().showImplicitArguments || showInferredType || userConfig().showImplicitConversionsAndClasses
}

private def createHoverAtPoint(
Expand Down Expand Up @@ -445,7 +448,10 @@ final class SyntheticsDecorationProvider(
} yield decorationOptions(lspRange, decoration)

val typDecorations =
if (userConfig().showInferredType)
if (
userConfig().showInferredType.contains("true") |
userConfig().showInferredType.contains("minimal")
)
typeDecorations(path, textDocument, decorationPrinter)
else Nil
decorations ++ typDecorations
Expand Down Expand Up @@ -488,7 +494,10 @@ final class SyntheticsDecorationProvider(
case param: m.Term.Param =>
if (param.decltpe.isEmpty) List(param.name.pos.toSemanticdb) else Nil
case cs: m.Case =>
explorePatterns(List(cs.pat)) ++ visit(cs.body)
// if the case is too long then it'll be too messy
if (userConfig().showInferredType.contains("minimal"))
tgodzik marked this conversation as resolved.
Show resolved Hide resolved
visit(cs.body) // don't show type hint for cases inside match
else explorePatterns(List(cs.pat)) ++ visit(cs.body)
case vl: m.Defn.Val =>
val values =
if (vl.decltpe.isEmpty) explorePatterns(vl.pats) else Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ case class UserConfiguration(
bloopJvmProperties: Option[List[String]] = None,
ammoniteJvmProperties: Option[List[String]] = None,
superMethodLensesEnabled: Boolean = false,
showInferredType: Boolean = false,
showInferredType: Option[String] = None,
showImplicitArguments: Boolean = false,
showImplicitConversionsAndClasses: Boolean = false,
remoteLanguageServer: Option[String] = None,
Expand Down Expand Up @@ -491,7 +491,7 @@ object UserConfiguration {
val superMethodLensesEnabled =
getBooleanKey("super-method-lenses-enabled").getOrElse(false)
val showInferredType =
getBooleanKey("show-inferred-type").getOrElse(false)
getStringKey("show-inferred-type")
val showImplicitArguments =
getBooleanKey("show-implicit-arguments").getOrElse(false)
val showImplicitConversionsAndClasses =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,44 @@ class SyntheticDecorationsLspSuite extends BaseLspSuite("implicits") {
|}
|""".stripMargin
)
// minimal style for show-inferred-type : don't show types for match case
_ <- server.didChangeConfiguration(
"""{
| "show-implicit-arguments": true,
| "show-implicit-conversions-and-classes": true,
| "show-inferred-type": minimal
|}
|""".stripMargin
)
_ <- server.didOpen("a/src/main/scala/Main.scala")
_ <- server.didSave("a/src/main/scala/Main.scala")(identity)
_ = assertNoDiagnostics()
_ = assertNoDiff( // foo[t]() to foo()
client.workspaceDecorations,
"""|import scala.concurrent.Future
|case class Location(city: String)
|object Main{
| def hello()(implicit name: String, from: Location): Unit = {
| println(s"Hello $name from ${from.city}")
| }
| implicit val andy : String = "Andy"
|
| def greeting(): Unit = {
| implicit val boston: Location = Location("Boston")
| hello()(andy, boston)
| hello()(andy, boston); hello()(andy, boston)
| }
|
| val ordered: String = augmentString("acb").sorted(Char)
| augmentString("foo").map(c: Char => c.toInt)
| implicit val ec: scala.concurrent.ExecutionContext = scala.concurrent.ExecutionContext.global
| Future{
| println("")
| }(ec)
|}
|""".stripMargin,
)
// full style for show-inferred-type
_ <- server.didChangeConfiguration(
"""{
| "show-implicit-arguments": true,
Expand Down