Skip to content

Commit

Permalink
delete use of untyped trees
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Sep 18, 2023
1 parent cc43c56 commit f286970
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
31 changes: 11 additions & 20 deletions mtags/src/main/scala-3/scala/meta/internal/pc/PcCollector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,12 @@ abstract class PcCollector[T](
* object MyIntOut:
* extension (i: MyIntOut) def <<uneven>> = i.value % 2 == 1
*
* val a = MyIntOut(1).un@@even
* val a = MyIntOut(1).<<un@@even>>
*/
case Apply(sel: Select, _) :: _
case (a @ Apply(sel: Select, _)) :: _
if sel.span.isZeroExtent && sel.symbol.is(Flags.ExtensionMethod) =>
untypedPath match
case (untypedSel: untpd.Select) :: _ =>
Some(
symbolAlternatives(sel.symbol),
pos.withSpan(untypedSel.nameSpan),
)
case _ => None
val span = a.span.withStart(a.span.point)
Some(symbolAlternatives(sel.symbol), pos.withSpan(span))
case _ => None

sought match
Expand All @@ -282,11 +277,9 @@ abstract class PcCollector[T](

end soughtSymbols

lazy val untypedPath =
lazy val extensionMethods =
NavigateAST
.untypedPath(pos.span)(using compilatonUnitContext)
lazy val extensionMethods =
untypedPath
.collectFirst { case em @ ExtMethods(_, _) => em }

private def findAllExtensionParamSymbols(
Expand Down Expand Up @@ -471,20 +464,18 @@ abstract class PcCollector[T](
* object MyIntOut:
* extension (i: MyIntOut) def <<uneven>> = i.value % 2 == 1
*
* val a = MyIntOut(1).un@@even
* val a = MyIntOut(1).<<un@@even>>
*/
case sel: Select
if sel.span.isZeroExtent && sel.symbol.is(Flags.ExtensionMethod) =>
scala.util
.Try(NavigateAST.untypedPath(sel.span)(using compilatonUnitContext))
.toOption match
case Some((_: Ident) :: (untypedSel: untpd.Select) :: _)
if untypedSel.span.isCorrect =>
val amendedSelect = sel.withSpan(untypedSel.span)
parent match
case Some(a: Apply) =>
val span = a.span.withStart(a.span.point)
val amendedSelect = sel.withSpan(span)
if filter(amendedSelect) then
occurences + collect(
amendedSelect,
pos.withSpan(untypedSel.nameSpan),
pos.withSpan(span),
)
else occurences
case _ => occurences
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,24 @@ class Scala3DocumentHighlightSuite extends BaseDocumentHighlightSuite {
|""".stripMargin,
)

check(
"i5630-2".tag(IgnoreForScala3CompilerPC),
"""|class MyIntOut(val value: Int)
|object MyIntOut:
| extension (i: MyIntOut) def <<uneven>>(u: Int) = i.value % 2 == 1
|
|val a = MyIntOut(1).<<un@@even>>(3)
|""".stripMargin,
)

check(
"i5630-infix".tag(IgnoreForScala3CompilerPC),
"""|class MyIntOut(val value: Int)
|object MyIntOut:
| extension (i: MyIntOut) def <<++>>(u: Int) = i.value + u
|
|val a = MyIntOut(1) <<+@@+>> 3
|""".stripMargin,
)

}
12 changes: 12 additions & 0 deletions tests/cross/src/test/scala/tests/hover/HoverScala3TypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,16 @@ class HoverScala3TypeSuite extends BaseHoverSuite {
"""|val ddd: Int
|""".stripMargin.hover,
)

check(
"i5630".tag(IgnoreForScala3CompilerPC),
"""|class MyIntOut(val value: Int)
|object MyIntOut:
| extension (i: MyIntOut) def uneven = i.value % 2 == 1
|
|val a = MyIntOut(1).un@@even
|""".stripMargin,
"""|extension (i: MyIntOut) def uneven: Boolean
|""".stripMargin.hover,
)
}

0 comments on commit f286970

Please sign in to comment.