In VS Code's debug adapter and the new SDK DAP implementation, there is a setting that allows showing values of getters in debug tooltips/watch window/etc.. This works by walking up the class hierarchy getting all of the names of any getters at each level and then sending evaluate requests for each.
This code seems fragile and involves looking at an internal field to identify the getters (f.json?['_kind'] == 'GetterFunction'). It would be better to have a more official way to do this (and perhaps in a single request).
|
/// Collect a list of all getter names for [classRef] and its super classes. |
|
/// |
|
/// This is used to show/evaluate getters in debug views like hovers and |
|
/// variables/watch panes. |
|
Future<Set<String>> _getterNamesForClassHierarchy( |
|
ThreadInfo thread, |
|
vm.ClassRef? classRef, |
|
) async { |
|
final getterNames = <String>{}; |
|
final service = _adapter.vmService; |
|
while (service != null && classRef != null) { |
|
final classResponse = |
|
await service.getObject(thread.isolate.id!, classRef.id!); |
|
if (classResponse is! vm.Class) { |
|
break; |
|
} |
|
final functions = classResponse.functions; |
|
if (functions != null) { |
|
final instanceFields = functions.where((f) => |
|
// TODO(dantup): Update this to use something better that bkonyi is |
|
// adding to the protocol. |
|
f.json?['_kind'] == 'GetterFunction' && |
|
!(f.isStatic ?? false) && |
|
!(f.isConst ?? false)); |
|
getterNames.addAll(instanceFields.map((f) => f.name!)); |
|
} |
|
|
|
classRef = classResponse.superClass; |
|
} |
|
|
|
return getterNames; |
|
} |
@bkonyi (I think @jacob314 may also have been interested in this?)
In VS Code's debug adapter and the new SDK DAP implementation, there is a setting that allows showing values of getters in debug tooltips/watch window/etc.. This works by walking up the class hierarchy getting all of the names of any getters at each level and then sending evaluate requests for each.
This code seems fragile and involves looking at an internal field to identify the getters (
f.json?['_kind'] == 'GetterFunction'). It would be better to have a more official way to do this (and perhaps in a single request).sdk/pkg/dds/lib/src/dap/protocol_converter.dart
Lines 444 to 475 in 248e943
@bkonyi (I think @jacob314 may also have been interested in this?)