Unverified Commit 76f056ac authored by Daniel Chevalier's avatar Daniel Chevalier Committed by GitHub

Improve pub root directory interface (#106567)

The pubRoot directory interface is being changed to promote adding and removing directories
parent 0b6e0e2a
...@@ -748,6 +748,12 @@ mixin WidgetInspectorService { ...@@ -748,6 +748,12 @@ mixin WidgetInspectorService {
final Map<Object, String> _objectToId = Map<Object, String>.identity(); final Map<Object, String> _objectToId = Map<Object, String>.identity();
int _nextId = 0; 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; List<String>? _pubRootDirectories;
/// Memoization for [_isLocalCreationLocation]. /// Memoization for [_isLocalCreationLocation].
final HashMap<String, bool> _isLocalCreationCache = HashMap<String, bool>(); final HashMap<String, bool> _isLocalCreationCache = HashMap<String, bool>();
...@@ -1106,6 +1112,20 @@ mixin WidgetInspectorService { ...@@ -1106,6 +1112,20 @@ mixin WidgetInspectorService {
return null; 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( _registerServiceExtensionWithArg(
name: 'setSelectionById', name: 'setSelectionById',
callback: setSelectionById, callback: setSelectionById,
...@@ -1233,7 +1253,7 @@ mixin WidgetInspectorService { ...@@ -1233,7 +1253,7 @@ mixin WidgetInspectorService {
void resetAllState() { void resetAllState() {
disposeAllGroups(); disposeAllGroups();
selection.clear(); selection.clear();
setPubRootDirectories(<String>[]); resetPubRootDirectories();
} }
/// Free all references to objects in a group. /// Free all references to objects in a group.
...@@ -1355,12 +1375,66 @@ mixin WidgetInspectorService { ...@@ -1355,12 +1375,66 @@ mixin WidgetInspectorService {
/// project. /// project.
/// ///
/// The local project directories are used to distinguish widgets created by /// 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 @protected
@Deprecated(
'Use addPubRootDirectories instead. '
'This feature was deprecated after v3.1.0-9.0.pre.',
)
void setPubRootDirectories(List<String> pubRootDirectories) { void setPubRootDirectories(List<String> pubRootDirectories) {
_pubRootDirectories = pubRootDirectories addPubRootDirectories(pubRootDirectories);
.map<String>((String directory) => Uri.parse(directory).path) }
.toList();
/// 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(); _isLocalCreationCache.clear();
} }
......
...@@ -176,7 +176,7 @@ void main() { ...@@ -176,7 +176,7 @@ void main() {
// framework, excluding any that are for the widget inspector // framework, excluding any that are for the widget inspector
// (see widget_inspector_test.dart for tests of the ext.flutter.inspector // (see widget_inspector_test.dart for tests of the ext.flutter.inspector
// service extensions). // service extensions).
const int serviceExtensionCount = 36; const int serviceExtensionCount = 38;
expect(binding.extensions.length, serviceExtensionCount + widgetInspectorExtensionCount - disabledExtensions); expect(binding.extensions.length, serviceExtensionCount + widgetInspectorExtensionCount - disabledExtensions);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment