scala-debug-adapter icon indicating copy to clipboard operation
scala-debug-adapter copied to clipboard

Add a collection formatter

Open adpi2 opened this issue 2 years ago • 4 comments

When inspecting a Scala (or Java) collection in the debugger, it would be very useful to see its elements as if it was an array (or rather a lazy array).

The end result should look like this:

myList: List[Int]
  size: 13
  elems
    0: "foo"
    1: "bar"
    ...
    10: "fizz"
    load more:
      11: "buzz"
      12: "bazz"

We can find some inspiration of how to do it in IntelliJ Scala debugger.

Corresponding feature request in Metals is: https://github.com/scalameta/metals-feature-requests/issues/307

adpi2 avatar Apr 04 '23 14:04 adpi2

Any pointers on roughly where in the code this sort of thing might go?

I was recently bitten by the fact that the default toString formatting of values means that very large collections will force rendering into a string when you go to poke them in the debugger (alternately, is there a way to avoid trigger toString?)

harpocrates avatar Mar 12 '25 01:03 harpocrates

Any pointers on roughly where in the code this sort of thing might go?

That's a bit tricky because we depend on microsoft/java-debug. So first we should check if such thing is implemented in there, and then, if we can extend its implementation for our own collection classes.

The first step would be to debug a Java program in VSCode using the official Java extensions and see if it uses custom formatting for collections. Then to find where it is implemented in microsoft/java-debug.

adpi2 avatar Mar 12 '25 08:03 adpi2

Oh does the toString functionality originate in java-debug?

harpocrates avatar Mar 12 '25 13:03 harpocrates

Oh does the toString functionality originate in java-debug?

Yes I am pretty sure it does.

adpi2 avatar Mar 12 '25 15:03 adpi2