Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle getObject issues during autocomplete #3046

Merged
merged 1 commit into from
May 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions packages/devtools_app/lib/src/debugger/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ Future<List<String>> autoCompleteResultsFor(
);
// TODO(grouma) - This shouldn't be necessary but package:dwds does
// not properly provide superclass information.
final clazz = await controller.getObject(instance.classRef);
final clazz = await classFor(instance.classRef, controller);
result.addAll(instance.fields
.map((field) => field.decl.name)
.where((member) => _isAccessible(member, clazz, controller)));
Expand All @@ -312,22 +312,29 @@ Future<Set<String>> _autoCompleteMembersFor(
DebuggerController controller,
) async {
final result = <String>{};
if (classRef != null) {
try {
final Class clazz = await controller.getObject(classRef);
result.addAll(clazz.fields.map((field) => field.name));
result.addAll(clazz.functions
.where((funcRef) => _validFunction(funcRef, clazz))
// The VM shows setters as `<member>=`.
.map((funcRef) => funcRef.name.replaceAll('=', '')));
result
.addAll(await _autoCompleteMembersFor(clazz.superClass, controller));
result.removeWhere((member) => !_isAccessible(member, clazz, controller));
} catch (_) {}
final clazz = await classFor(classRef, controller);
if (clazz != null) {
result.addAll(clazz.fields.map((field) => field.name));
result.addAll(clazz.functions
.where((funcRef) => _validFunction(funcRef, clazz))
// The VM shows setters as `<member>=`.
.map((funcRef) => funcRef.name.replaceAll('=', '')));
result.addAll(await _autoCompleteMembersFor(clazz.superClass, controller));
result.removeWhere((member) => !_isAccessible(member, clazz, controller));
}
return result;
}

/// Returns the class for the provided [ClassRef].
///
/// May return null.
Future<Class> classFor(ClassRef classRef, DebuggerController controller) async {
try {
return await controller.getObject(classRef);
} catch (_) {}
return null;
}

bool _validFunction(FuncRef funcRef, Class clazz) {
return !funcRef.isStatic &&
!_isContructor(funcRef, clazz) &&
Expand Down Expand Up @@ -364,5 +371,5 @@ bool _isAccessible(String member, Class clazz, DebuggerController controller) {
controller.stackFramesWithLocation.value.first.frame;
final currentScript = frame.location.script;
return !member.startsWith('_') ||
currentScript.id == clazz.location?.script?.id;
currentScript.id == clazz?.location?.script?.id;
}