@@ -381,7 +381,7 @@ class Search {
381381 return _searchReferences (element, searchedFiles);
382382 } else if (element is ConstructorElement ) {
383383 return await _searchReferences_Constructor (element, searchedFiles);
384- } else if (element is CompilationUnitElement ) {
384+ } else if (element is CompilationUnitElementImpl ) {
385385 return _searchReferences_CompilationUnit (element);
386386 } else if (element is PropertyAccessorElement && element.isGetter) {
387387 return _searchReferences_Getter (element, searchedFiles);
@@ -692,7 +692,7 @@ class Search {
692692 }
693693
694694 Future <List <SearchResult >> _searchReferences_CompilationUnit (
695- CompilationUnitElement element) async {
695+ CompilationUnitElementImpl element) async {
696696 String path = element.source.fullName;
697697
698698 var file = _driver.resourceProvider.getFile (path);
@@ -704,8 +704,28 @@ class Search {
704704 }
705705
706706 // Check files that reference the given file.
707- List < SearchResult > results = < SearchResult > [];
707+ var results = < SearchResult > [];
708708 for (var reference in fileState.referencingFiles) {
709+ var index = await _driver.getIndex (reference.path);
710+ if (index != null ) {
711+ var targetId = index.getLibraryFragmentId (element);
712+ for (var i = 0 ; i < index.libFragmentRefTargets.length; i++ ) {
713+ if (index.libFragmentRefTargets[i] == targetId) {
714+ var refUnit = await _getUnitElement (reference.path);
715+ results.add (
716+ SearchResult ._(
717+ refUnit! ,
718+ SearchResultKind .REFERENCE ,
719+ index.libFragmentRefUriOffsets[i],
720+ index.libFragmentRefUriLengths[i],
721+ true ,
722+ true ,
723+ ),
724+ );
725+ }
726+ }
727+ }
728+
709729 await _addResultsInFile (
710730 results,
711731 element,
@@ -1391,7 +1411,7 @@ class _IndexRequest {
13911411
13921412 void addSubtypes (
13931413 String superIdString, List <SubtypeResult > results, FileState file) {
1394- var superId = getStringId (superIdString);
1414+ var superId = index. getStringId (superIdString);
13951415 if (superId == - 1 ) {
13961416 return ;
13971417 }
@@ -1425,24 +1445,24 @@ class _IndexRequest {
14251445 /// Return the [element] 's identifier in the [index] or `-1` if the
14261446 /// [element] is not referenced in the [index] .
14271447 int findElementId (Element element) {
1428- IndexElementInfo info = IndexElementInfo (element);
1429- element = info.element;
1448+ IndexElementInfo info = IndexElementInfo (element.asElement2 ! );
1449+ element = info.element.asElement ! ;
14301450 // Find the id of the element's unit.
14311451 int unitId = getUnitId (element);
14321452 if (unitId == - 1 ) {
14331453 return - 1 ;
14341454 }
14351455 // Prepare information about the element.
1436- var components = ElementNameComponents (element);
1437- int unitMemberId = getStringId (components.unitMemberName);
1456+ var components = ElementNameComponents (element.asElement2 ! );
1457+ int unitMemberId = index. getStringId (components.unitMemberName);
14381458 if (unitMemberId == - 1 ) {
14391459 return - 1 ;
14401460 }
1441- int classMemberId = getStringId (components.classMemberName);
1461+ int classMemberId = index. getStringId (components.classMemberName);
14421462 if (classMemberId == - 1 ) {
14431463 return - 1 ;
14441464 }
1445- int parameterId = getStringId (components.parameterName);
1465+ int parameterId = index. getStringId (components.parameterName);
14461466 if (parameterId == - 1 ) {
14471467 return - 1 ;
14481468 }
@@ -1511,35 +1531,11 @@ class _IndexRequest {
15111531 return results;
15121532 }
15131533
1514- /// Return the identifier of [str] in the [index] or `-1` if [str] is not
1515- /// used in the [index] .
1516- int getStringId (String ? str) {
1517- if (str == null ) {
1518- return index.nullStringId;
1519- }
1520-
1521- return binarySearch (index.strings, str);
1522- }
1523-
15241534 /// Return the identifier of the [CompilationUnitElement] containing the
15251535 /// [element] in the [index] or `-1` if not found.
15261536 int getUnitId (Element element) {
1527- CompilationUnitElement unitElement = getUnitElement (element);
1528- int libraryUriId = getUriId (unitElement.library.source.uri);
1529- if (libraryUriId == - 1 ) {
1530- return - 1 ;
1531- }
1532- int unitUriId = getUriId (unitElement.source.uri);
1533- if (unitUriId == - 1 ) {
1534- return - 1 ;
1535- }
1536- for (int i = 0 ; i < index.unitLibraryUris.length; i++ ) {
1537- if (index.unitLibraryUris[i] == libraryUriId &&
1538- index.unitUnitUris[i] == unitUriId) {
1539- return i;
1540- }
1541- }
1542- return - 1 ;
1537+ var unitElement = getUnitElement (element.asElement2! );
1538+ return index.getLibraryFragmentId (unitElement);
15431539 }
15441540
15451541 /// Return a list of results where a class members with the given [name] is
@@ -1550,7 +1546,7 @@ class _IndexRequest {
15501546 Future <CompilationUnitElement ?> Function ()
15511547 getEnclosingUnitElement) async {
15521548 // Find the name identifier.
1553- int nameId = getStringId (name);
1549+ int nameId = index. getStringId (name);
15541550 if (nameId == - 1 ) {
15551551 return const < SearchResult > [];
15561552 }
@@ -1582,13 +1578,6 @@ class _IndexRequest {
15821578 return results;
15831579 }
15841580
1585- /// Return the identifier of the [uri] in the [index] or `-1` if the [uri] is
1586- /// not used in the [index] .
1587- int getUriId (Uri uri) {
1588- String str = uri.toString ();
1589- return getStringId (str);
1590- }
1591-
15921581 /// Return the index of the first occurrence of the [value] in the
15931582 /// [sortedList] , or `-1` if the [value] is not in the list.
15941583 int _findFirstOccurrence (List <int > sortedList, int value) {
0 commit comments