@@ -45,6 +45,9 @@ class AppInspector extends Domain {
4545 /// Map of [ScriptRef] id to containing [LibraryRef] id.
4646 final _scriptIdToLibraryId = < String , String > {};
4747
48+ /// Map of [Library] id to included [ScriptRef] s.
49+ final _libraryIdToScriptRefs = < String , List <ScriptRef >> {};
50+
4851 final RemoteDebugger remoteDebugger;
4952 final Debugger debugger;
5053 final Isolate isolate;
@@ -232,7 +235,7 @@ class AppInspector extends Domain {
232235 String isolateId, String targetId, String expression,
233236 {Map <String , String > scope}) async {
234237 scope ?? = {};
235- var library = await _getLibrary (isolateId, targetId);
238+ var library = await getLibrary (isolateId, targetId);
236239 if (library == null ) {
237240 throw UnsupportedError (
238241 'Evaluate is only supported when `targetId` is a library.' );
@@ -341,10 +344,6 @@ function($argsString) {
341344 }
342345
343346 Future <Library > getLibrary (String isolateId, String objectId) async {
344- return await _getLibrary (isolateId, objectId);
345- }
346-
347- Future <Library > _getLibrary (String isolateId, String objectId) async {
348347 if (isolateId != isolate.id) return null ;
349348 var libraryRef = await libraryHelper.libraryRefFor (objectId);
350349 if (libraryRef == null ) return null ;
@@ -354,7 +353,7 @@ function($argsString) {
354353 Future <Obj > getObject (String isolateId, String objectId,
355354 {int offset, int count}) async {
356355 try {
357- var library = await _getLibrary (isolateId, objectId);
356+ var library = await getLibrary (isolateId, objectId);
358357 if (library != null ) {
359358 return library;
360359 }
@@ -410,13 +409,16 @@ function($argsString) {
410409
411410 /// Returns the [ScriptRef] for the provided Dart server path [uri] .
412411 Future <ScriptRef > scriptRefFor (String uri) async {
413- if (_serverPathToScriptRef.isEmpty) {
414- // TODO(grouma) - populate the server path cache a better way.
415- await getScripts (isolate.id);
416- }
412+ await _populateScriptCaches ();
417413 return _serverPathToScriptRef[uri];
418414 }
419415
416+ /// Returns the [ScriptRef] s in the library with [libraryId] .
417+ Future <List <ScriptRef >> scriptRefsForLibrary (String libraryId) async {
418+ await _populateScriptCaches ();
419+ return _libraryIdToScriptRefs[libraryId];
420+ }
421+
420422 /// Return the VM SourceReport for the given parameters.
421423 ///
422424 /// Currently this implements the 'PossibleBreakpoints' report kind.
@@ -486,8 +488,10 @@ function($argsString) {
486488
487489 /// Request and cache <ScriptRef>s for all the scripts in the application.
488490 ///
489- /// This populates [_scriptRefsById] , [_scriptIdToLibraryId] and
490- /// [_serverPathToScriptRef] . It is a one-time operation, because if we do a
491+ /// This populates [_scriptRefsById] , [_scriptIdToLibraryId] ,
492+ /// [_libraryIdToScriptRefs] and [_serverPathToScriptRef] .
493+ ///
494+ /// It is a one-time operation, because if we do a
491495 /// reload the inspector will get re-created.
492496 ///
493497 /// Returns the list of scripts refs cached.
@@ -507,11 +511,13 @@ function($argsString) {
507511 for (var part in parts) ScriptRef (uri: part, id: createId ())
508512 ];
509513 var libraryRef = await libraryHelper.libraryRefFor (uri);
514+ _libraryIdToScriptRefs.putIfAbsent (libraryRef.id, () => < ScriptRef > []);
510515 for (var scriptRef in scriptRefs) {
511516 _scriptRefsById[scriptRef.id] = scriptRef;
512517 _scriptIdToLibraryId[scriptRef.id] = libraryRef.id;
513518 _serverPathToScriptRef[DartUri (scriptRef.uri, _root).serverPath] =
514519 scriptRef;
520+ _libraryIdToScriptRefs[libraryRef.id].add (scriptRef);
515521 }
516522 }
517523 return _scriptRefsById.values.toList ();
0 commit comments