scalameta / metals

Scala language server with rich IDE features 🚀
https://scalameta.org/metals/
Apache License 2.0
2.08k stars 326 forks source link

2.x: "Show decompiled with javap" doesn't show lambdas #5948

Open kubukoz opened 9 months ago

kubukoz commented 9 months ago

Describe the bug

Synthetic classes generated by certain Scala versions (I checked 2.13, 2.12 probably also does this, 3.x doesn't) don't show up in the selector of classes to decode with javap.

To reproduce:

1.

//> using scala 2.13.11

class Super(x: () => Int)

trait Demo {
  object A extends Super(() => 42)
}
  1. Run the "show decompiled with javap" command
  2. Only Super, Demo and A$ are shown

Expected behavior

Demo$A$$anonfun$$lessinit$greater$1 is also shown.

Here's one of its methods (the one that returns the 42) - I got this by running javap -v manually in the .scala-build directory of my project.

  public final int apply$mcI$sp();
    descriptor: ()I
    flags: (0x0011) ACC_PUBLIC, ACC_FINAL
    Code:
      stack=1, locals=1, args_size=1
         0: bipush        42
         2: ireturn
      LineNumberTable:
        line 6: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       3     0  this   LDemo$A$$anonfun$$lessinit$greater$1;

I realize this is possibly a niche usecase, and it's probably going to add some noise in real-world scenarios, so perhaps these can be shown last on the list. It'd be good to try enabling this on a codebase with a lot of closures in use and see if it is indeed noisy.

Operating system

macOS

Editor/Extension

VS Code

Version of Metals

1.2.0

Extra context or search terms

No response

tgodzik commented 9 months ago

Thanks for reporting! The list is generated manually, we need to add also add the additional class or figure out a way to generate the list automatically. Maybe we could read the classfiles and figure out which ones come from the current source file?

For the current case we would most likely need to add a library to be able to read classfiles though :/

kubukoz commented 9 months ago

For the current case we would most likely need to add a library to be able to read classfiles though :/

it could start with a heuristic: s"strings $classFile".!!.contains(fileName) 😅

tgodzik commented 9 months ago

Another option would be to read zinc analysis files, which apparently contain that infor. I am however unsure how to do it without adding a dependency on zinc itself.