Skip to content

Commit

Permalink
bugfix: Incorrect docstring on parameters
Browse files Browse the repository at this point in the history
Previously, we were not changing tree when entering class/method parameters and type parameters while indexing,
which resulted in showing incorrect docstring.
  • Loading branch information
jkciesluk committed Sep 18, 2023
1 parent d7be734 commit 7a9fa82
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mtags/src/main/scala/scala/meta/internal/mtags/ScalaMtags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand All @@ -101,6 +108,7 @@ class ScalaMtags(val input: Input.VirtualFile, dialect: Dialect)
case _ =>
}
}
myCurrentTree = old
}
def disambiguatedMethod(
member: Member,
Expand Down
86 changes: 86 additions & 0 deletions tests/cross/src/test/scala/tests/hover/HoverDocSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,92 @@ class HoverDocSuite extends BaseHoverSuite {
|""".stripMargin,
)

check(
"class-param",
"""|
|/**
| * Doc about class
| *
| */
|class Alpha(abc: Int) {
| val y = <<a@@bc>>
|}
|
|""".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) = <<a@@bc>> + 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),
"""|
Expand Down

0 comments on commit 7a9fa82

Please sign in to comment.