Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: pkg/analysis_server/lib/src/services/index2/index2.dart

Issue 1771903002: Implement search for names defined in index. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/index2/index2_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/lib/src/services/index2/index2.dart
diff --git a/pkg/analysis_server/lib/src/services/index2/index2.dart b/pkg/analysis_server/lib/src/services/index2/index2.dart
index 53205a6b09003ecbb591fa1a43e2cdadc3cc90cd..00f536cee26d6580bf2df4cdfd054a44a32430c4 100644
--- a/pkg/analysis_server/lib/src/services/index2/index2.dart
+++ b/pkg/analysis_server/lib/src/services/index2/index2.dart
@@ -46,6 +46,23 @@ class Index2 {
Index2(this._store);
/**
+ * Complete with a list of locations where elements of the given [kind] with
+ * names satisfying the given [regExp] are defined.
+ */
+ Future<List<Location>> getDefinedNames(
+ RegExp regExp, IndexNameKind kind) async {
+ List<Location> locations = <Location>[];
+ Iterable<PackageIndexId> ids = await _store.getIds();
+ for (PackageIndexId id in ids) {
+ PackageIndex index = await _store.getIndex(id);
+ _PackageIndexRequester requester = new _PackageIndexRequester(index);
+ List<Location> packageLocations = requester.getDefinedNames(regExp, kind);
+ locations.addAll(packageLocations);
+ }
+ return locations;
+ }
+
+ /**
* Complete with a list of locations where the given [element] has relation
* of the given [kind].
*/
@@ -223,6 +240,20 @@ class _PackageIndexRequester {
}
/**
+ * Complete with a list of locations where elements of the given [kind] with
+ * names satisfying the given [regExp] are defined.
+ */
+ List<Location> getDefinedNames(RegExp regExp, IndexNameKind kind) {
+ List<Location> locations = <Location>[];
+ for (UnitIndex unitIndex in index.units) {
+ _UnitIndexRequester requester = new _UnitIndexRequester(this, unitIndex);
+ List<Location> unitLocations = requester.getDefinedNames(regExp, kind);
+ locations.addAll(unitLocations);
+ }
+ return locations;
+ }
+
+ /**
* Complete with a list of locations where the given [element] has relation
* of the given [kind].
*/
@@ -302,6 +333,29 @@ class _UnitIndexRequester {
_UnitIndexRequester(this.packageRequester, this.unitIndex);
/**
+ * Complete with a list of locations where elements of the given [kind] with
+ * names satisfying the given [regExp] are defined.
+ */
+ List<Location> getDefinedNames(RegExp regExp, IndexNameKind kind) {
+ List<Location> locations = <Location>[];
+ String unitLibraryUri = null;
+ String unitUnitUri = null;
+ for (int i = 0; i < unitIndex.definedNames.length; i++) {
+ if (unitIndex.definedNameKinds[i] == kind) {
+ int nameIndex = unitIndex.definedNames[i];
+ String name = packageRequester.index.strings[nameIndex];
+ if (regExp.matchAsPrefix(name) != null) {
+ unitLibraryUri ??= packageRequester.getUnitLibraryUri(unitIndex.unit);
+ unitUnitUri ??= packageRequester.getUnitUnitUri(unitIndex.unit);
+ locations.add(new Location(unitLibraryUri, unitUnitUri,
+ unitIndex.definedNameOffsets[i], 0, false));
+ }
+ }
+ }
+ return locations;
+ }
+
+ /**
* Return a list of locations where an element with the given [elementId] has
* relation of the given [kind].
*/
« no previous file with comments | « no previous file | pkg/analysis_server/test/services/index2/index2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698