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

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

Issue 1783503004: Listen for context add/remove and unit invalidation to update the 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
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 6e6d704ac6fa7b62ce516ab8b29318ad97f49a4f..0ad8ca331be6fcd045440b80d94a4f9d867750b9 100644
--- a/pkg/analysis_server/lib/src/services/index2/index2.dart
+++ b/pkg/analysis_server/lib/src/services/index2/index2.dart
@@ -95,6 +95,14 @@ class Index2 {
}
/**
+ * Remove index information about the unit in the given [context].
+ */
+ void removeUnit(
+ AnalysisContext context, Source librarySource, Source unitSource) {
+ _contextIndexMap[context]?.removeUnit(librarySource, unitSource);
+ }
+
+ /**
* Return the [_ContextIndex] instance for the given [context].
*/
_ContextIndex _getContextIndex(AnalysisContext context) {
@@ -207,8 +215,7 @@ class _ContextIndex {
*/
Future<List<Location>> getDefinedNames(
RegExp regExp, IndexNameKind kind) async {
- return _mergeLocations((PackageIndex index) {
- _PackageIndexRequester requester = new _PackageIndexRequester(index);
+ return _mergeLocations((_PackageIndexRequester requester) {
return requester.getDefinedNames(context, regExp, kind);
});
}
@@ -218,8 +225,7 @@ class _ContextIndex {
* of the given [kind].
*/
Future<List<Location>> getRelations(Element element, IndexRelationKind kind) {
- return _mergeLocations((PackageIndex index) {
- _PackageIndexRequester requester = new _PackageIndexRequester(index);
+ return _mergeLocations((_PackageIndexRequester requester) {
return requester.getRelations(context, element, kind);
});
}
@@ -229,8 +235,7 @@ class _ContextIndex {
* [name] is referenced with a qualifier, but is not resolved.
*/
Future<List<Location>> getUnresolvedMemberReferences(String name) async {
- return _mergeLocations((PackageIndex index) {
- _PackageIndexRequester requester = new _PackageIndexRequester(index);
+ return _mergeLocations((_PackageIndexRequester requester) {
return requester.getUnresolvedMemberReferences(context, name);
});
}
@@ -250,6 +255,14 @@ class _ContextIndex {
indexMap[key] = index;
}
+ /**
+ * Remove index information about the unit.
+ */
+ void removeUnit(Source librarySource, Source unitSource) {
+ String key = _getUnitKeyForSource(librarySource, unitSource);
+ indexMap.remove(key);
+ }
+
String _getUnitKeyForElement(CompilationUnitElement unitElement) {
Source librarySource = unitElement.library.source;
Source unitSource = unitElement.source;
@@ -263,10 +276,11 @@ class _ContextIndex {
}
Future<List<Location>> _mergeLocations(
- List<Location> callback(PackageIndex index)) async {
+ List<Location> callback(_PackageIndexRequester requester)) async {
List<Location> locations = <Location>[];
for (PackageIndex index in indexMap.values) {
- List<Location> indexLocations = callback(index);
+ _PackageIndexRequester requester = new _PackageIndexRequester(index);
+ List<Location> indexLocations = callback(requester);
locations.addAll(indexLocations);
}
return locations;

Powered by Google App Engine
This is Rietveld 408576698