Skip to content

Commit

Permalink
LoggerOps: use Token.structure for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Mar 27, 2024
1 parent 49e8271 commit ec965a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ import org.scalafmt.util.TokenOps._
*/
case class FormatToken(left: Token, right: Token, meta: FormatToken.Meta) {

override def toString =
s"${meta.left.text}${meta.right.text}[${left.end}:${right.end}]"
override def toString = {
val ws = newlinesBetween match {
case 0 => between.mkString
case 1 => "LF"
case _ => "LFLF"
}
s"${meta.left.text}${meta.right.text}: ${left.structure} [$ws] ${right.structure}"
}

def inside(range: Set[Range]): Boolean = {
if (range.isEmpty) true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ object LoggerOps {

def log(tokens: Tokens): String = tokens.map(log).mkString("\n")

def log(token: Token): String =
f"[${token.end}]${cleanup(token).slice(0, 30)}%-30s ${getTokenClass(token)}"

private def getTokenClass(token: Token) =
token.getClass.getName.stripPrefix("scala.meta.tokens.Token$")
def log(token: Token): String = f"[${token.structure}%-40s"

def log(t: Tree): String = log(t, false)
def log(t: Tree, tokensOnly: Boolean): String = {
Expand Down

0 comments on commit ec965a5

Please sign in to comment.