Conflict with pprint in mdoc in worksheet
Describe the bug
When working on a repo and trying something out in a worksheet I'm seeing the following error:
davidgregory084.worksheet.sc:12 (mdoc generated code) value recolor is not a member of object pprint.TPrint
val x = 3; $doc.binder(x, 2, 4, 2, 5)
^
You can reproduce this by doing the following:
- Clone https://github.com/DavidGregory084/mill-tpolecat
- Create a worksheet next to the Scala code (I created davidgregory084.worksheet.sc via quick worksheet command, hence the weird name)
- Paste the following code in there:
import mill.scalalib.api.Util._
val x = 3
- See the error
Expected behavior
I'm assuming there is a conflict with the pprint versions in Mill vs mdoc however I don't think a user should have be hit with this. I'm not sure if the solution is shading in Mill or mdoc, but there seems to be an issue with pprint.
Operating system
macOS
Editor/Extension
Nvim (nvim-metals)
Version of Metals
0.11.9+56-6943e41c-SNAPSHOT
Extra context or search terms
value recolor is not a member of object pprint.TPrint
Thanks for reporting! I think the solution might be to inline pprint completely in mdoc or always use toString.
Looking at this I think we can filter out some libraries in https://github.com/scalameta/metals/blob/main/metals/src/main/scala/scala/meta/internal/worksheets/WorksheetProvider.scala#L424 and not include the ones used in Mdoc. This is a good candidate for the next week spree.
After trying some alternatives I think the best approach is to either:
- shade all the libraries aside from Scala
- inline them in the codebase
🤔 if it was only one I'd say maybe we can just inline it, but we then might hit on the same issues with sourceode or fansi right? In that case would it make the most sense to just shade everything com.lihaoyi in the artifacts?
In that case would it make the most sense to just shade everything com.lihaoyi in the artifacts? I think so yeah.
@tgodzik I'm also hit by this in Scala 2.13 with metals 1.2 :
I see there's a closed PR, so what should we do? shade everything from com.lihaoyi ?
Looks like it, but I will not have time to look into it.
Is this Scala 2 specific? I checked it seems to work fine in Scala 3 @tgodzik
I think it's inlined already for Scala 3
@tgodzik could you elaborate a bit? Does Scala 3 not dependent on https://github.com/scalameta/metals/blob/main/metals/src/main/scala/scala/meta/internal/worksheets/WorksheetProvider.scala#L424 ? I see worksheetScala3Adjustments but didn't find "inline" stuff .
Runtime doesn't seem to depend on pprint at all https://github.com/scalameta/mdoc/blob/main/build.sbt#L151
It's inline here https://github.com/scalameta/mdoc/tree/main/runtime/src/main/scala-3/mdoc/internal