From 7a9fa821251b65a137dce1bc74a62f0d3ef33384 Mon Sep 17 00:00:00 2001 From: Jakub Ciesluk <323892@uwr.edu.pl> Date: Fri, 15 Sep 2023 16:31:52 +0200 Subject: [PATCH] bugfix: Incorrect docstring on parameters Previously, we were not changing tree when entering class/method parameters and type parameters while indexing, which resulted in showing incorrect docstring. --- .../meta/internal/mtags/ScalaMtags.scala | 10 ++- .../scala/tests/hover/HoverDocSuite.scala | 86 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/mtags/src/main/scala/scala/meta/internal/mtags/ScalaMtags.scala b/mtags/src/main/scala/scala/meta/internal/mtags/ScalaMtags.scala index be791e692e6..6d35f628eda 100644 --- a/mtags/src/main/scala/scala/meta/internal/mtags/ScalaMtags.scala +++ b/mtags/src/main/scala/scala/meta/internal/mtags/ScalaMtags.scala @@ -60,10 +60,12 @@ class ScalaMtags(val input: Input.VirtualFile, dialect: Dialect) paramss: List[List[Term.Param]], isPrimaryCtor: Boolean ): Unit = { + val old = myCurrentTree for { params <- paramss param <- params } { + myCurrentTree = param withOwner() { if (isPrimaryCtor) { param.name match { @@ -76,19 +78,24 @@ class ScalaMtags(val input: Input.VirtualFile, dialect: Dialect) } } } - + myCurrentTree = old } def enterTypeParameters(tparams: List[Type.Param]): Unit = { + val old = myCurrentTree for { tparam <- tparams } { + myCurrentTree = tparam withOwner() { super.tparam(tparam.name, Kind.TYPE_PARAMETER, 0) } } + myCurrentTree = old } def enterPatterns(ps: List[Pat], kind: Kind, properties: Int): Unit = { + val old = myCurrentTree ps.foreach { pat => + myCurrentTree = pat pat.traverse { case Pat.Var(name) => withOwner() { @@ -101,6 +108,7 @@ class ScalaMtags(val input: Input.VirtualFile, dialect: Dialect) case _ => } } + myCurrentTree = old } def disambiguatedMethod( member: Member, diff --git a/tests/cross/src/test/scala/tests/hover/HoverDocSuite.scala b/tests/cross/src/test/scala/tests/hover/HoverDocSuite.scala index 048640f531a..deb5923b4e2 100644 --- a/tests/cross/src/test/scala/tests/hover/HoverDocSuite.scala +++ b/tests/cross/src/test/scala/tests/hover/HoverDocSuite.scala @@ -293,6 +293,92 @@ class HoverDocSuite extends BaseHoverSuite { |""".stripMargin, ) + check( + "class-param", + """| + |/** + | * Doc about class + | * + | */ + |class Alpha(abc: Int) { + | val y = <> + |} + | + |""".stripMargin, + """|```scala + |private[this] val abc: Int + |``` + |""".stripMargin, + compat = Map( + "3" -> + """|```scala + |val abc: Int + |``` + |""".stripMargin + ), + ) + + check( + "class-type-param", + """| + |/** + | * Doc about class + | * + | */ + |class Alpha[T](abc: T) { + | val y: <<@@T>> = abc + |} + | + |""".stripMargin, + """|```scala + |T: T + |``` + |""".stripMargin, + compat = Map( + "3" -> + """|```scala + |type T: T + |``` + |""".stripMargin + ), + ) + + check( + "method-param", + """| + |object O { + | /** + | * Doc about method + | */ + | def foo(abc: Int) = <> + 1 + | + |} + | + |""".stripMargin, + """|```scala + |abc: Int + |``` + |""".stripMargin, + ) + + check( + "method-type-param", + """| + |object O { + | /** + | * Doc about method + | */ + | def foo[T](abc: T): <<@@T>> = abc + | + |} + | + |""".stripMargin, + """|```scala + |T: T + |``` + |""".stripMargin, + ) + check( "universal-apply".tag(IgnoreScala2), """|