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

Side by Side Diff: pkg/analysis_server/lib/src/services/search/search_engine_internal2.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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library services.src.search.search_engine2; 5 library services.src.search.search_engine2;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/services/correction/source_range.dart'; 9 import 'package:analysis_server/src/services/correction/source_range.dart';
10 import 'package:analysis_server/src/services/index2/index2.dart'; 10 import 'package:analysis_server/src/services/index2/index2.dart';
11 import 'package:analysis_server/src/services/search/search_engine.dart'; 11 import 'package:analysis_server/src/services/search/search_engine.dart';
12 import 'package:analyzer/dart/ast/ast.dart'; 12 import 'package:analyzer/dart/ast/ast.dart';
13 import 'package:analyzer/dart/ast/visitor.dart'; 13 import 'package:analyzer/dart/ast/visitor.dart';
14 import 'package:analyzer/dart/element/element.dart'; 14 import 'package:analyzer/dart/element/element.dart';
15 import 'package:analyzer/src/dart/element/member.dart'; 15 import 'package:analyzer/src/dart/element/member.dart';
16 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext; 16 import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
17 import 'package:analyzer/src/generated/resolver.dart' show NamespaceBuilder; 17 import 'package:analyzer/src/generated/resolver.dart' show NamespaceBuilder;
18 import 'package:analyzer/src/generated/source.dart' show Source, SourceRange; 18 import 'package:analyzer/src/generated/source.dart' show Source, SourceRange;
19 import 'package:analyzer/src/summary/idl.dart'; 19 import 'package:analyzer/src/summary/idl.dart';
20 20
21 /** 21 /**
22 * A [SearchEngine] implementation. 22 * A [SearchEngine] implementation.
23 */ 23 */
24 class SearchEngineImpl2 implements SearchEngine { 24 class SearchEngineImpl2 implements SearchEngine {
25 final AnalysisContext context;
26 final Index2 _index; 25 final Index2 _index;
27 26
28 SearchEngineImpl2(this.context, this._index); 27 SearchEngineImpl2(this._index);
29 28
30 @override 29 @override
31 Future<List<SearchMatch>> searchAllSubtypes(ClassElement type) async { 30 Future<List<SearchMatch>> searchAllSubtypes(ClassElement type) async {
32 List<SearchMatch> matches = <SearchMatch>[]; 31 List<SearchMatch> matches = <SearchMatch>[];
33 await _addMatches( 32 await _addMatches(
34 matches, type, IndexRelationKind.IS_ANCESTOR_OF, MatchKind.DECLARATION); 33 matches, type, IndexRelationKind.IS_ANCESTOR_OF, MatchKind.DECLARATION);
35 return matches; 34 return matches;
36 } 35 }
37 36
38 @override 37 @override
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 IndexRelationKind relationKind, MatchKind kind) async { 103 IndexRelationKind relationKind, MatchKind kind) async {
105 List<Location> locations = await _index.getRelations(element, relationKind); 104 List<Location> locations = await _index.getRelations(element, relationKind);
106 for (Location location in locations) { 105 for (Location location in locations) {
107 SearchMatch match = _newMatchForLocation(location, kind); 106 SearchMatch match = _newMatchForLocation(location, kind);
108 matches.add(match); 107 matches.add(match);
109 } 108 }
110 } 109 }
111 110
112 SearchMatch _newMatchForLocation(Location location, MatchKind kind) => 111 SearchMatch _newMatchForLocation(Location location, MatchKind kind) =>
113 new SearchMatch( 112 new SearchMatch(
114 context, 113 location.context,
115 location.libraryUri, 114 location.libraryUri,
116 location.unitUri, 115 location.unitUri,
117 kind, 116 kind,
118 new SourceRange(location.offset, location.length), 117 new SourceRange(location.offset, location.length),
119 true, 118 true,
120 location.isQualified); 119 location.isQualified);
121 120
122 Future<List<SearchMatch>> _searchDefinedNames( 121 Future<List<SearchMatch>> _searchDefinedNames(
123 String pattern, IndexNameKind nameKind) async { 122 String pattern, IndexNameKind nameKind) async {
124 RegExp regExp = new RegExp(pattern); 123 RegExp regExp = new RegExp(pattern);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 await _addMatches(matches, element, IndexRelationKind.IS_INVOKED_BY, 168 await _addMatches(matches, element, IndexRelationKind.IS_INVOKED_BY,
170 MatchKind.INVOCATION); 169 MatchKind.INVOCATION);
171 return matches; 170 return matches;
172 } 171 }
173 172
174 Future<List<SearchMatch>> _searchReferences_Import( 173 Future<List<SearchMatch>> _searchReferences_Import(
175 ImportElement element) async { 174 ImportElement element) async {
176 List<SearchMatch> matches = <SearchMatch>[]; 175 List<SearchMatch> matches = <SearchMatch>[];
177 LibraryElement libraryElement = element.library; 176 LibraryElement libraryElement = element.library;
178 Source librarySource = libraryElement.source; 177 Source librarySource = libraryElement.source;
178 AnalysisContext context = libraryElement.context;
179 for (CompilationUnitElement unitElement in libraryElement.units) { 179 for (CompilationUnitElement unitElement in libraryElement.units) {
180 Source unitSource = unitElement.source; 180 Source unitSource = unitElement.source;
181 CompilationUnit unit = 181 CompilationUnit unit =
182 context.resolveCompilationUnit2(unitSource, librarySource); 182 context.resolveCompilationUnit2(unitSource, librarySource);
183 _ImportElementReferencesVisitor visitor = 183 _ImportElementReferencesVisitor visitor =
184 new _ImportElementReferencesVisitor( 184 new _ImportElementReferencesVisitor(
185 element, unitSource.uri.toString()); 185 element, unitSource.uri.toString());
186 unit.accept(visitor); 186 unit.accept(visitor);
187 matches.addAll(visitor.matches); 187 matches.addAll(visitor.matches);
188 } 188 }
189 return matches; 189 return matches;
190 } 190 }
191 191
192 Future<List<SearchMatch>> _searchReferences_Library(Element element) async { 192 Future<List<SearchMatch>> _searchReferences_Library(Element element) async {
193 List<SearchMatch> matches = <SearchMatch>[]; 193 List<SearchMatch> matches = <SearchMatch>[];
194 LibraryElement libraryElement = element.library; 194 LibraryElement libraryElement = element.library;
195 Source librarySource = libraryElement.source; 195 Source librarySource = libraryElement.source;
196 AnalysisContext context = libraryElement.context;
196 for (CompilationUnitElement unitElement in libraryElement.parts) { 197 for (CompilationUnitElement unitElement in libraryElement.parts) {
197 Source unitSource = unitElement.source; 198 Source unitSource = unitElement.source;
198 CompilationUnit unit = 199 CompilationUnit unit =
199 context.resolveCompilationUnit2(unitSource, librarySource); 200 context.resolveCompilationUnit2(unitSource, librarySource);
200 for (Directive directive in unit.directives) { 201 for (Directive directive in unit.directives) {
201 if (directive is PartOfDirective && 202 if (directive is PartOfDirective &&
202 directive.element == libraryElement) { 203 directive.element == libraryElement) {
203 matches.add(new SearchMatch( 204 matches.add(new SearchMatch(
204 context, 205 context,
205 librarySource.uri.toString(), 206 librarySource.uri.toString(),
(...skipping 24 matching lines...) Expand all
230 matches.addAll(await _searchReferences_Local( 231 matches.addAll(await _searchReferences_Local(
231 parameter, (n) => n is MethodDeclaration || n is FunctionExpression)); 232 parameter, (n) => n is MethodDeclaration || n is FunctionExpression));
232 return matches; 233 return matches;
233 } 234 }
234 235
235 Future<List<SearchMatch>> _searchReferences_Prefix( 236 Future<List<SearchMatch>> _searchReferences_Prefix(
236 PrefixElement element) async { 237 PrefixElement element) async {
237 List<SearchMatch> matches = <SearchMatch>[]; 238 List<SearchMatch> matches = <SearchMatch>[];
238 LibraryElement libraryElement = element.library; 239 LibraryElement libraryElement = element.library;
239 Source librarySource = libraryElement.source; 240 Source librarySource = libraryElement.source;
241 AnalysisContext context = libraryElement.context;
240 for (CompilationUnitElement unitElement in libraryElement.units) { 242 for (CompilationUnitElement unitElement in libraryElement.units) {
241 Source unitSource = unitElement.source; 243 Source unitSource = unitElement.source;
242 CompilationUnit unit = 244 CompilationUnit unit =
243 context.resolveCompilationUnit2(unitSource, librarySource); 245 context.resolveCompilationUnit2(unitSource, librarySource);
244 _LocalReferencesVisitor visitor = 246 _LocalReferencesVisitor visitor =
245 new _LocalReferencesVisitor(element, unitSource.uri.toString()); 247 new _LocalReferencesVisitor(element, unitSource.uri.toString());
246 unit.accept(visitor); 248 unit.accept(visitor);
247 matches.addAll(visitor.matches); 249 matches.addAll(visitor.matches);
248 } 250 }
249 return matches; 251 return matches;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 _addMatch(node, kind); 363 _addMatch(node, kind);
362 } 364 }
363 } 365 }
364 366
365 void _addMatch(AstNode node, MatchKind kind) { 367 void _addMatch(AstNode node, MatchKind kind) {
366 bool isQualified = node is SimpleIdentifier && node.isQualified; 368 bool isQualified = node is SimpleIdentifier && node.isQualified;
367 matches.add(new SearchMatch(context, libraryUri, unitUri, kind, 369 matches.add(new SearchMatch(context, libraryUri, unitUri, kind,
368 rangeNode(node), true, isQualified)); 370 rangeNode(node), true, isQualified));
369 } 371 }
370 } 372 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/index2/index2.dart ('k') | pkg/analysis_server/lib/src/status/get_handler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698