microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.05k stars 29.21k forks source link

Watch expressions should allow LSP or debugger to remove inner whitespaces #226412

Open FMorschel opened 2 months ago

FMorschel commented 2 months ago

Watch expressions should allow LSP or debugger to remove inner whitespace.

In languages like Dart, most of the time (and even more so in the future with the new tall formatter) you can select multiple lines that represent a single expression and add them to the watch list.

Currently, we end up with lots of whitespaces between every line because of indentation and such. There could be an option for the LSP or debugger to remove inner spaces when that will not interfere with the expression (like spaces inside strings and such should not be removed).

Edit

This could be expanded to remove trailing ; and similar as well.

roblourens commented 1 month ago

I suppose this would be a job for the formatter? JS example

Select foo.charAt(0), "Add to Watch", it's displayed poorly

Image

Image

roblourens commented 1 month ago

Could at least just .trim() it and escape \n for display.

DanTup commented 1 month ago

I suppose this would be a job for the formatter?

Do you mean send a formatRange request and apply it only to the expression being added to the watch? Would it get messed up if the formatter returned an edit that is slightly larger than the expression?

I wonder if it'd be better to have some specific API for simplifying the expression given a range. For example, you might also want to remove comments inside the expression for watch/evaluation:

myList
  // Filter by foo because reasons...
  .where((i) => i.foo);