Skip to content

Commit

Permalink
bugfix: Backticked named arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk committed Oct 22, 2023
1 parent 4bb3aeb commit adb34ce
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
13 changes: 10 additions & 3 deletions mtags/src/main/scala-3/scala/meta/internal/pc/PcCollector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ abstract class PcCollector[T](
val realName = arg.name.stripModuleClassSuffix.lastPart
if pos.span.start > arg.span.start && pos.span.end < arg.span.point + realName.length
then
val length = realName.toString.backticked.length()
val pos = arg.sourcePos.withSpan(
arg.span
.withEnd(arg.span.start + length)
.withPoint(arg.span.start)
)
appl.symbol.paramSymss.flatten.find(_.name == arg.name).map { s =>
// if it's a case class we need to look for parameters also
if caseClassSynthetics(s.owner.name) && s.owner.is(Flags.Synthetic)
Expand All @@ -214,9 +220,9 @@ abstract class PcCollector[T](
s.owner.owner.info.member(s.name).symbol,
)
.filter(_ != NoSymbol),
arg.sourcePos,
pos,
)
else (Set(s), arg.sourcePos)
else (Set(s), pos)
}
else None
end if
Expand Down Expand Up @@ -521,14 +527,15 @@ abstract class PcCollector[T](
}
val named = args.map { arg =>
val realName = arg.name.stripModuleClassSuffix.lastPart
val length = realName.toString.backticked.length()
val sym = apply.symbol.paramSymss.flatten
.find(_.name == realName)
collect(
arg,
pos
.withSpan(
arg.span
.withEnd(arg.span.start + realName.length)
.withEnd(arg.span.start + length)
.withPoint(arg.span.start)
),
sym,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,4 +866,15 @@ class DocumentHighlightSuite extends BaseDocumentHighlightSuite {
|}
|""".stripMargin,
)

check(
"named-arg-backtick",
"""|object Main {
| def foo(<<`type`>>: String): String = <<`type`>>
| val x = foo(
| <<`ty@@pe`>> = "abc"
| )
|}
|""".stripMargin,
)
}
13 changes: 13 additions & 0 deletions tests/cross/src/test/scala/tests/pc/PcPrepareRenameSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,17 @@ class PcPrepareRenameSuite extends BasePcRenameSuite {
|""".stripMargin,
)

prepare(
"named-arg-backtick",
"""|object Main {
| def m() = {
| def foo(`type`: String): String = `type`
| val x = foo(
| <<`ty@@pe`>> = "abc"
| )
| }
|}
|""".stripMargin,
)

}
11 changes: 11 additions & 0 deletions tests/cross/src/test/scala/tests/tokens/SemanticTokensSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,15 @@ class SemanticTokensSuite extends BaseSemanticTokensSuite {
),
)

check(
"named-arg-backtick",
"""|object <<Main>>/*class*/ {
| def <<foo>>/*method,definition*/(<<`type`>>/*parameter,declaration,readonly*/: <<String>>/*type*/): <<String>>/*type*/ = <<`type`>>/*parameter,readonly*/
| val <<x>>/*variable,definition,readonly*/ = <<foo>>/*method*/(
| <<`type`>>/*parameter,readonly*/ = "abc"
| )
|}
|""".stripMargin,
)

}

0 comments on commit adb34ce

Please sign in to comment.