-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mode to strip type prefix for SourceCodePrinter #10172
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Have an awesome day! ☀️
@@ -1157,12 +1162,14 @@ class SourceCodePrinter[R <: Reflection & Singleton](val reflect: R)(syntaxHighl | |||
printFullClassName(tp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printFullClassName(tp) | |
if printTypePrefix then | |
printFullClassName(tp) | |
else ??? // print class name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe change the logic of printFullClassName
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a guard inside printFullClassName
f79097f
to
894fe06
Compare
@@ -94,9 +94,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler | |||
def showExtractors: String = | |||
Extractors.showTree(using QuotesImpl.this)(self) | |||
def show: String = | |||
SourceCode.showTree(using QuotesImpl.this)(self)(SyntaxHighlight.plain) | |||
SourceCode.showTree(using QuotesImpl.this)(self)(SyntaxHighlight.plain, fullNames = true) | |||
def showShortTypes: String = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about the additional showShortTypes
@nicolasstucki ? Otherwise we will always need to bring in the compiler in with SyntaxHighlight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call it showShort
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed and added it to interfaces.
894fe06
to
99226f1
Compare
I finally managed to rebase and address the comments. Having an additional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good.
@@ -94,9 +94,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler | |||
def showExtractors: String = | |||
Extractors.showTree(using QuotesImpl.this)(self) | |||
def show: String = | |||
SourceCode.showTree(using QuotesImpl.this)(self)(SyntaxHighlight.plain) | |||
SourceCode.showTree(using QuotesImpl.this)(self)(SyntaxHighlight.plain, fullNames = true) | |||
def showShortTypes: String = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call it showShort
.
…nd add an additional `showShortTypes` method
99226f1
to
f51b6cd
Compare
Managed to simplify the logic in mdoc to: trait TPrint[T]{
def render: String
}
object TPrint {
inline given default[T] as TPrint[T] = ${ TypePrinter.typeString[T] }
}
object TypePrinter{
def typeString[T](using ctx: Quotes, tpe: Type[T]): Expr[TPrint[T]] = {
import quotes.reflect._
val valueType = Type.showShort[T]
'{ new TPrint[T]{ def render: String = ${ Expr(valueType) } } }
}
} That should also work in pprint Also we could use it here: https://github.com/scalameta/munit/blob/master/munit/shared/src/main/scala-3.0.0-M2/munit/internal/MacroCompat.scala#L28 |
Thank you @tgodzik |
This is a proposal to help with #9716
I see this is already an issue both in mdoc and in munit. It most likely also help with pprint's TypePrinter.
What do you think? I can add some tests if the solution is sensible.