Skip to content

Commit

Permalink
presentation compiler: remove synthetic decorations for script wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk committed Nov 28, 2023
1 parent b474209 commit 9e0eb8e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class PcSyntheticDecorationsProvider(

def provide(): List[SyntheticDecoration] =
val deepFolder = DeepFolder[Synthetics](collectDecorations)
deepFolder(Synthetics.empty, tpdTree).decorations
deepFolder(Synthetics.empty, tpdTree).result()

def collectDecorations(
decorations: Synthetics,
Expand Down Expand Up @@ -256,11 +256,23 @@ case class Synthetics(
def containsDef(offset: Int) = definitions(offset)
def add(decoration: Decoration, offset: Int) =
copy(
decorations = decoration :: decorations,
decorations = addDecoration(decoration),
definitions = definitions + offset,
)
def add(decoration: Decoration) =
copy(decorations = decoration :: decorations)
copy (
decorations = addDecoration(decoration)
)

// If method has both type parameter and implicit parameter, we want the type parameter decoration to be displayed first,
// but it's added second. This method adds the decoration to the right position in the list.
private def addDecoration(decoration: Decoration): List[Decoration] =
val atSamePos =
decorations.takeWhile(_.range.getStart() == decoration.range.getStart())
(atSamePos :+ decoration) ++ decorations.drop(atSamePos.size)

def result(): List[Decoration] = decorations.reverse
end Synthetics

object Synthetics:
def empty: Synthetics = Synthetics(Nil, Set.empty)
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,18 @@ class SyntheticDecorationsSuite extends BaseSyntheticDecorationsSuite:
|}
|""".stripMargin
)

@Test def `ord` =
check(
"""
|object Main {
| val ordered = "acb".sorted
|}
|""".stripMargin,
"""
|object Main {
| val ordered: String = augmentString("acb").sorted[Char](Char)
|}
|""".stripMargin
)

0 comments on commit 9e0eb8e

Please sign in to comment.