Skip to content

Commit

Permalink
Improve pub root directory interface (#106567)
Browse files Browse the repository at this point in the history
The pubRoot directory interface is being changed to promote adding and removing directories
  • Loading branch information
CoderDake committed Jul 7, 2022
1 parent 0b6e0e2 commit 76f056a
Show file tree
Hide file tree
Showing 3 changed files with 965 additions and 56 deletions.
84 changes: 79 additions & 5 deletions packages/flutter/lib/src/widgets/widget_inspector.dart
Expand Up @@ -748,6 +748,12 @@ mixin WidgetInspectorService {
final Map<Object, String> _objectToId = Map<Object, String>.identity();
int _nextId = 0;

/// the pubRootDirectories that are currently configured for the widget inspector.
///
/// This is for testing use only.
@visibleForTesting
@protected
List<String>? get pubRootDirectories => _pubRootDirectories == null ? const <String>[] : List<String>.from(_pubRootDirectories!);
List<String>? _pubRootDirectories;
/// Memoization for [_isLocalCreationLocation].
final HashMap<String, bool> _isLocalCreationCache = HashMap<String, bool>();
Expand Down Expand Up @@ -1106,6 +1112,20 @@ mixin WidgetInspectorService {
return null;
},
);
_registerServiceExtensionVarArgs(
name: 'addPubRootDirectories',
callback: (List<String> args) async {
addPubRootDirectories(args);
return null;
},
);
_registerServiceExtensionVarArgs(
name: 'removePubRootDirectories',
callback: (List<String> args) async {
removePubRootDirectories(args);
return null;
},
);
_registerServiceExtensionWithArg(
name: 'setSelectionById',
callback: setSelectionById,
Expand Down Expand Up @@ -1233,7 +1253,7 @@ mixin WidgetInspectorService {
void resetAllState() {
disposeAllGroups();
selection.clear();
setPubRootDirectories(<String>[]);
resetPubRootDirectories();
}

/// Free all references to objects in a group.
Expand Down Expand Up @@ -1355,12 +1375,66 @@ mixin WidgetInspectorService {
/// project.
///
/// The local project directories are used to distinguish widgets created by
/// the local project over widgets created from inside the framework.
/// the local project from widgets created from inside the framework
/// or other packages.
@protected
@Deprecated(
'Use addPubRootDirectories instead. '
'This feature was deprecated after v3.1.0-9.0.pre.',
)
void setPubRootDirectories(List<String> pubRootDirectories) {
_pubRootDirectories = pubRootDirectories
.map<String>((String directory) => Uri.parse(directory).path)
.toList();
addPubRootDirectories(pubRootDirectories);
}

/// Resets the list of directories, that should be considered part of the
/// local project, to the value passed in [pubRootDirectories].
///
/// The local project directories are used to distinguish widgets created by
/// the local project from widgets created from inside the framework
/// or other packages.
@visibleForTesting
@protected
void resetPubRootDirectories() {
_pubRootDirectories = <String>[];
_isLocalCreationCache.clear();
}

/// Add a list of directories that should be considered part of the local
/// project.
///
/// The local project directories are used to distinguish widgets created by
/// the local project from widgets created from inside the framework
/// or other packages.
@protected
void addPubRootDirectories(List<String> pubRootDirectories) {
pubRootDirectories = pubRootDirectories.map<String>((String directory) => Uri.parse(directory).path).toList();

final Set<String> directorySet = Set<String>.from(pubRootDirectories);
if(_pubRootDirectories != null) {
directorySet.addAll(_pubRootDirectories!);
}

_pubRootDirectories = directorySet.toList();
_isLocalCreationCache.clear();
}

/// Remove a list of directories that should no longer be considered part
/// of the local project.
///
/// The local project directories are used to distinguish widgets created by
/// the local project from widgets created from inside the framework
/// or other packages.
@protected
void removePubRootDirectories(List<String> pubRootDirectories) {
if (_pubRootDirectories == null) {
return;
}
pubRootDirectories = pubRootDirectories.map<String>((String directory) => Uri.parse(directory).path).toList();

final Set<String> directorySet = Set<String>.from(_pubRootDirectories!);
directorySet.removeAll(pubRootDirectories);

_pubRootDirectories = directorySet.toList();
_isLocalCreationCache.clear();
}

Expand Down
Expand Up @@ -176,7 +176,7 @@ void main() {
// framework, excluding any that are for the widget inspector
// (see widget_inspector_test.dart for tests of the ext.flutter.inspector
// service extensions).
const int serviceExtensionCount = 36;
const int serviceExtensionCount = 38;

expect(binding.extensions.length, serviceExtensionCount + widgetInspectorExtensionCount - disabledExtensions);

Expand Down

0 comments on commit 76f056a

Please sign in to comment.