OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 operation.analysis; | 5 library operation.analysis; |
6 | 6 |
7 import 'package:analysis_server/src/analysis_server.dart'; | 7 import 'package:analysis_server/src/analysis_server.dart'; |
8 import 'package:analysis_server/src/computer/computer_highlights.dart'; | 8 import 'package:analysis_server/src/computer/computer_highlights.dart'; |
9 import 'package:analysis_server/src/computer/computer_highlights2.dart'; | 9 import 'package:analysis_server/src/computer/computer_highlights2.dart'; |
10 import 'package:analysis_server/src/computer/computer_outline.dart'; | 10 import 'package:analysis_server/src/computer/computer_outline.dart'; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 server.addOperation(new _DartIndexOperation(context, file, dartUnit)); | 70 server.addOperation(new _DartIndexOperation(context, file, dartUnit)); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 /** | 74 /** |
75 * Schedules sending notifications for the given [file] using the resolved | 75 * Schedules sending notifications for the given [file] using the resolved |
76 * [resolvedDartUnit]. | 76 * [resolvedDartUnit]. |
77 */ | 77 */ |
78 void scheduleNotificationOperations( | 78 void scheduleNotificationOperations( |
79 AnalysisServer server, | 79 AnalysisServer server, |
| 80 Source source, |
80 String file, | 81 String file, |
81 LineInfo lineInfo, | 82 LineInfo lineInfo, |
82 AnalysisContext context, | 83 AnalysisContext context, |
83 CompilationUnit parsedDartUnit, | 84 CompilationUnit parsedDartUnit, |
84 CompilationUnit resolvedDartUnit, | 85 CompilationUnit resolvedDartUnit, |
85 List<AnalysisError> errors) { | 86 List<AnalysisError> errors) { |
86 // If the file belongs to any analysis root, check whether we're in it now. | 87 // If the file belongs to any analysis root, check whether we're in it now. |
87 AnalysisContext containingContext = server.getContainingContext(file); | 88 AnalysisContext containingContext = server.getContainingContext(file); |
88 if (containingContext != null && context != containingContext) { | 89 if (containingContext != null && context != containingContext) { |
89 return; | 90 return; |
90 } | 91 } |
91 // Dart | 92 // Dart |
92 CompilationUnit dartUnit = | 93 CompilationUnit dartUnit = |
93 resolvedDartUnit != null ? resolvedDartUnit : parsedDartUnit; | 94 resolvedDartUnit != null ? resolvedDartUnit : parsedDartUnit; |
94 if (resolvedDartUnit != null) { | 95 if (resolvedDartUnit != null) { |
95 if (server.hasAnalysisSubscription( | 96 if (server.hasAnalysisSubscription( |
96 protocol.AnalysisService.HIGHLIGHTS, file)) { | 97 protocol.AnalysisService.HIGHLIGHTS, file)) { |
97 server.scheduleOperation( | 98 server.scheduleOperation( |
98 new _DartHighlightsOperation(context, file, resolvedDartUnit)); | 99 new _DartHighlightsOperation(context, file, resolvedDartUnit)); |
99 } | 100 } |
100 if (server.hasAnalysisSubscription( | 101 if (server.hasAnalysisSubscription( |
101 protocol.AnalysisService.NAVIGATION, file)) { | 102 protocol.AnalysisService.NAVIGATION, file)) { |
102 Source source = resolvedDartUnit.element.source; | |
103 server.scheduleOperation(new NavigationOperation(context, source)); | 103 server.scheduleOperation(new NavigationOperation(context, source)); |
104 } | 104 } |
105 if (server.hasAnalysisSubscription( | 105 if (server.hasAnalysisSubscription( |
106 protocol.AnalysisService.OCCURRENCES, file)) { | 106 protocol.AnalysisService.OCCURRENCES, file)) { |
107 Source source = resolvedDartUnit.element.source; | |
108 server.scheduleOperation(new OccurrencesOperation(context, source)); | 107 server.scheduleOperation(new OccurrencesOperation(context, source)); |
109 } | 108 } |
110 if (server.hasAnalysisSubscription( | 109 if (server.hasAnalysisSubscription( |
111 protocol.AnalysisService.OVERRIDES, file)) { | 110 protocol.AnalysisService.OVERRIDES, file)) { |
112 server.scheduleOperation( | 111 server.scheduleOperation( |
113 new _DartOverridesOperation(context, file, resolvedDartUnit)); | 112 new _DartOverridesOperation(context, file, resolvedDartUnit)); |
114 } | 113 } |
115 } | 114 } |
116 if (dartUnit != null) { | 115 if (dartUnit != null) { |
117 if (server.hasAnalysisSubscription( | 116 if (server.hasAnalysisSubscription( |
118 protocol.AnalysisService.OUTLINE, file)) { | 117 protocol.AnalysisService.OUTLINE, file)) { |
119 server.scheduleOperation( | 118 SourceKind sourceKind = context.getKindOf(source); |
120 new _DartOutlineOperation(context, file, lineInfo, dartUnit)); | 119 server.scheduleOperation(new _DartOutlineOperation( |
| 120 context, file, lineInfo, sourceKind, dartUnit)); |
121 } | 121 } |
122 } | 122 } |
123 // errors | 123 // errors |
124 if (server.shouldSendErrorsNotificationFor(file)) { | 124 if (server.shouldSendErrorsNotificationFor(file)) { |
125 server.scheduleOperation( | 125 server.scheduleOperation( |
126 new _NotificationErrorsOperation(context, file, lineInfo, errors)); | 126 new _NotificationErrorsOperation(context, file, lineInfo, errors)); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 void sendAnalysisNotificationAnalyzedFiles(AnalysisServer server) { | 130 void sendAnalysisNotificationAnalyzedFiles(AnalysisServer server) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 OccurrencesCollectorImpl collector = | 206 OccurrencesCollectorImpl collector = |
207 computeOccurrences(server, context, source); | 207 computeOccurrences(server, context, source); |
208 String file = source.fullName; | 208 String file = source.fullName; |
209 var params = | 209 var params = |
210 new protocol.AnalysisOccurrencesParams(file, collector.allOccurrences); | 210 new protocol.AnalysisOccurrencesParams(file, collector.allOccurrences); |
211 server.sendNotification(params.toNotification()); | 211 server.sendNotification(params.toNotification()); |
212 }); | 212 }); |
213 } | 213 } |
214 | 214 |
215 void sendAnalysisNotificationOutline(AnalysisServer server, String file, | 215 void sendAnalysisNotificationOutline(AnalysisServer server, String file, |
216 LineInfo lineInfo, CompilationUnit dartUnit) { | 216 LineInfo lineInfo, SourceKind sourceKind, CompilationUnit dartUnit) { |
217 _sendNotification(server, () { | 217 _sendNotification(server, () { |
| 218 // compute FileKind |
| 219 protocol.FileKind fileKind = protocol.FileKind.LIBRARY; |
| 220 if (sourceKind == SourceKind.LIBRARY) { |
| 221 fileKind = protocol.FileKind.LIBRARY; |
| 222 } else if (sourceKind == SourceKind.PART) { |
| 223 fileKind = protocol.FileKind.PART; |
| 224 } |
| 225 // compute library name |
| 226 String libraryName = _computeLibraryName(dartUnit); |
| 227 // compute Outline |
218 var computer = new DartUnitOutlineComputer(file, lineInfo, dartUnit); | 228 var computer = new DartUnitOutlineComputer(file, lineInfo, dartUnit); |
219 var outline = computer.compute(); | 229 protocol.Outline outline = computer.compute(); |
220 var params = new protocol.AnalysisOutlineParams( | 230 // send notification |
221 file, protocol.FileKind.LIBRARY, outline); | 231 var params = new protocol.AnalysisOutlineParams(file, fileKind, outline, |
| 232 libraryName: libraryName); |
222 server.sendNotification(params.toNotification()); | 233 server.sendNotification(params.toNotification()); |
223 }); | 234 }); |
224 } | 235 } |
225 | 236 |
226 void sendAnalysisNotificationOverrides( | 237 void sendAnalysisNotificationOverrides( |
227 AnalysisServer server, String file, CompilationUnit dartUnit) { | 238 AnalysisServer server, String file, CompilationUnit dartUnit) { |
228 _sendNotification(server, () { | 239 _sendNotification(server, () { |
229 var overrides = new DartUnitOverridesComputer(dartUnit).compute(); | 240 var overrides = new DartUnitOverridesComputer(dartUnit).compute(); |
230 var params = new protocol.AnalysisOverridesParams(file, overrides); | 241 var params = new protocol.AnalysisOverridesParams(file, overrides); |
231 server.sendNotification(params.toNotification()); | 242 server.sendNotification(params.toNotification()); |
232 }); | 243 }); |
233 } | 244 } |
234 | 245 |
235 /** | 246 /** |
236 * Sets the cache size in the given [context] to the given value. | 247 * Sets the cache size in the given [context] to the given value. |
237 */ | 248 */ |
238 void setCacheSize(AnalysisContext context, int cacheSize) { | 249 void setCacheSize(AnalysisContext context, int cacheSize) { |
239 AnalysisOptionsImpl options = | 250 AnalysisOptionsImpl options = |
240 new AnalysisOptionsImpl.from(context.analysisOptions); | 251 new AnalysisOptionsImpl.from(context.analysisOptions); |
241 options.cacheSize = cacheSize; | 252 options.cacheSize = cacheSize; |
242 context.analysisOptions = options; | 253 context.analysisOptions = options; |
243 } | 254 } |
244 | 255 |
| 256 String _computeLibraryName(CompilationUnit unit) { |
| 257 for (Directive directive in unit.directives) { |
| 258 if (directive is LibraryDirective && directive.name != null) { |
| 259 return directive.name.name; |
| 260 } |
| 261 } |
| 262 for (Directive directive in unit.directives) { |
| 263 if (directive is PartOfDirective && directive.libraryName != null) { |
| 264 return directive.libraryName.name; |
| 265 } |
| 266 } |
| 267 return null; |
| 268 } |
| 269 |
245 /** | 270 /** |
246 * Runs the given notification producing function [f], catching exceptions. | 271 * Runs the given notification producing function [f], catching exceptions. |
247 */ | 272 */ |
248 void _sendNotification(AnalysisServer server, f()) { | 273 void _sendNotification(AnalysisServer server, f()) { |
249 ServerPerformanceStatistics.notices.makeCurrentWhile(() { | 274 ServerPerformanceStatistics.notices.makeCurrentWhile(() { |
250 try { | 275 try { |
251 f(); | 276 f(); |
252 } catch (exception, stackTrace) { | 277 } catch (exception, stackTrace) { |
253 server.sendServerErrorNotification(exception, stackTrace); | 278 server.sendServerErrorNotification(exception, stackTrace); |
254 } | 279 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 * Send the information in the given list of notices back to the client. | 390 * Send the information in the given list of notices back to the client. |
366 */ | 391 */ |
367 void _sendNotices(AnalysisServer server, List<ChangeNotice> notices) { | 392 void _sendNotices(AnalysisServer server, List<ChangeNotice> notices) { |
368 for (int i = 0; i < notices.length; i++) { | 393 for (int i = 0; i < notices.length; i++) { |
369 ChangeNotice notice = notices[i]; | 394 ChangeNotice notice = notices[i]; |
370 Source source = notice.source; | 395 Source source = notice.source; |
371 String file = source.fullName; | 396 String file = source.fullName; |
372 // Dart | 397 // Dart |
373 CompilationUnit parsedDartUnit = notice.parsedDartUnit; | 398 CompilationUnit parsedDartUnit = notice.parsedDartUnit; |
374 CompilationUnit resolvedDartUnit = notice.resolvedDartUnit; | 399 CompilationUnit resolvedDartUnit = notice.resolvedDartUnit; |
375 scheduleNotificationOperations(server, file, notice.lineInfo, context, | 400 scheduleNotificationOperations(server, source, file, notice.lineInfo, |
376 parsedDartUnit, resolvedDartUnit, notice.errors); | 401 context, parsedDartUnit, resolvedDartUnit, notice.errors); |
377 // done | 402 // done |
378 server.fileAnalyzed(notice); | 403 server.fileAnalyzed(notice); |
379 } | 404 } |
380 } | 405 } |
381 | 406 |
382 void _updateIndex(AnalysisServer server, List<ChangeNotice> notices) { | 407 void _updateIndex(AnalysisServer server, List<ChangeNotice> notices) { |
383 if (server.index == null) { | 408 if (server.index == null) { |
384 return; | 409 return; |
385 } | 410 } |
386 for (ChangeNotice notice in notices) { | 411 for (ChangeNotice notice in notices) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 : super(context, file); | 474 : super(context, file); |
450 | 475 |
451 @override | 476 @override |
452 ServerOperationPriority get priority { | 477 ServerOperationPriority get priority { |
453 return ServerOperationPriority.ANALYSIS_NOTIFICATION; | 478 return ServerOperationPriority.ANALYSIS_NOTIFICATION; |
454 } | 479 } |
455 } | 480 } |
456 | 481 |
457 class _DartOutlineOperation extends _DartNotificationOperation { | 482 class _DartOutlineOperation extends _DartNotificationOperation { |
458 final LineInfo lineInfo; | 483 final LineInfo lineInfo; |
| 484 final SourceKind sourceKind; |
459 | 485 |
460 _DartOutlineOperation( | 486 _DartOutlineOperation(AnalysisContext context, String file, this.lineInfo, |
461 AnalysisContext context, String file, this.lineInfo, CompilationUnit unit) | 487 this.sourceKind, CompilationUnit unit) |
462 : super(context, file, unit); | 488 : super(context, file, unit); |
463 | 489 |
464 @override | 490 @override |
465 void perform(AnalysisServer server) { | 491 void perform(AnalysisServer server) { |
466 sendAnalysisNotificationOutline(server, file, lineInfo, unit); | 492 sendAnalysisNotificationOutline(server, file, lineInfo, sourceKind, unit); |
467 } | 493 } |
468 } | 494 } |
469 | 495 |
470 class _DartOverridesOperation extends _DartNotificationOperation { | 496 class _DartOverridesOperation extends _DartNotificationOperation { |
471 _DartOverridesOperation( | 497 _DartOverridesOperation( |
472 AnalysisContext context, String file, CompilationUnit unit) | 498 AnalysisContext context, String file, CompilationUnit unit) |
473 : super(context, file, unit); | 499 : super(context, file, unit); |
474 | 500 |
475 @override | 501 @override |
476 void perform(AnalysisServer server) { | 502 void perform(AnalysisServer server) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 abstract class _SingleFileOperation extends SourceSensitiveOperation { | 560 abstract class _SingleFileOperation extends SourceSensitiveOperation { |
535 final String file; | 561 final String file; |
536 | 562 |
537 _SingleFileOperation(AnalysisContext context, this.file) : super(context); | 563 _SingleFileOperation(AnalysisContext context, this.file) : super(context); |
538 | 564 |
539 @override | 565 @override |
540 bool shouldBeDiscardedOnSourceChange(Source source) { | 566 bool shouldBeDiscardedOnSourceChange(Source source) { |
541 return source.fullName == file; | 567 return source.fullName == file; |
542 } | 568 } |
543 } | 569 } |
OLD | NEW |