[dds/dap] Improve display of Sets in debug views

- Show "Set (x items)" to match lists and maps
- Compute an evaluation name as "x.elementAt(y)" since "x[y]" isn't valid for sets

Fixes https://github.com/dart-lang/sdk/issues/60488

Change-Id: Ifb9df6e1d7cf91e2e25a421565d4c5fbb75ca0fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420704
Reviewed-by: Derek Xu <derekx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Danny Tuppeny
2025-04-08 08:10:59 -07:00
committed by Commit Queue
parent 43631b20bb
commit aad32ab70b
2 changed files with 75 additions and 15 deletions
@@ -405,6 +405,55 @@ void main(List<String> args) {
);
});
test('renders a simple set', () async {
final client = dap.client;
final testFile = dap.createTestFile('''
void main(List<String> args) {
final myVariable = {"first", "second", "third", null};
print('Hello!'); $breakpointMarker
}
''');
final breakpointLine = lineWith(testFile, breakpointMarker);
final stop = await client.hitBreakpoint(testFile, breakpointLine);
await client.expectLocalVariable(
stop.threadId!,
expectedName: 'myVariable',
expectedDisplayString: 'Set (4 items)',
expectedIndexedItems: 4,
expectedVariables: '''
[0]: "first", eval: myVariable.elementAt(0)
[1]: "second", eval: myVariable.elementAt(1)
[2]: "third", eval: myVariable.elementAt(2)
[3]: null
''',
);
});
test('renders a simple set subset', () async {
final client = dap.client;
final testFile = dap.createTestFile('''
void main(List<String> args) {
final myVariable = {"first", "second", "third"};
print('Hello!'); $breakpointMarker
}
''');
final breakpointLine = lineWith(testFile, breakpointMarker);
final stop = await client.hitBreakpoint(testFile, breakpointLine);
await client.expectLocalVariable(
stop.threadId!,
expectedName: 'myVariable',
expectedDisplayString: 'Set (3 items)',
expectedIndexedItems: 3,
expectedVariables: '''
[1]: "second", eval: myVariable.elementAt(1)
''',
start: 1,
count: 1,
);
});
test('only calls toString() for 100 items in a list', () async {
final client = dap.client;
// Generate a file that assigns a list of 150 items