mdoc icon indicating copy to clipboard operation
mdoc copied to clipboard

Conflict with pprint in mdoc in worksheet

Open ckipp01 opened this issue 3 years ago • 11 comments

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:

  1. Clone https://github.com/DavidGregory084/mill-tpolecat
  2. Create a worksheet next to the Scala code (I created davidgregory084.worksheet.sc via quick worksheet command, hence the weird name)
  3. Paste the following code in there:
import mill.scalalib.api.Util._

val x = 3
  1. 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

ckipp01 avatar Oct 24 '22 10:10 ckipp01

Thanks for reporting! I think the solution might be to inline pprint completely in mdoc or always use toString.

tgodzik avatar Oct 24 '22 14:10 tgodzik

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.

tgodzik avatar Nov 30 '22 16:11 tgodzik

After trying some alternatives I think the best approach is to either:

  • shade all the libraries aside from Scala
  • inline them in the codebase

tgodzik avatar Dec 27 '22 16:12 tgodzik

🤔 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?

ckipp01 avatar Dec 27 '22 17:12 ckipp01

In that case would it make the most sense to just shade everything com.lihaoyi in the artifacts? I think so yeah.

tgodzik avatar Dec 28 '22 10:12 tgodzik

@tgodzik I'm also hit by this in Scala 2.13 with metals 1.2 : image

I see there's a closed PR, so what should we do? shade everything from com.lihaoyi ?

doofin avatar Jan 15 '24 16:01 doofin

Looks like it, but I will not have time to look into it.

tgodzik avatar Jan 15 '24 19:01 tgodzik

Is this Scala 2 specific? I checked it seems to work fine in Scala 3 @tgodzik

doofin avatar Jan 16 '24 18:01 doofin

I think it's inlined already for Scala 3

tgodzik avatar Jan 16 '24 18:01 tgodzik

@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 .

doofin avatar Jan 16 '24 19:01 doofin

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

tgodzik avatar Jan 16 '24 20:01 tgodzik