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'; |
11 import 'package:analysis_server/src/computer/computer_overrides.dart'; | 11 import 'package:analysis_server/src/computer/computer_overrides.dart'; |
12 import 'package:analysis_server/src/context_manager.dart'; | |
13 import 'package:analysis_server/src/domains/analysis/implemented_dart.dart'; | 12 import 'package:analysis_server/src/domains/analysis/implemented_dart.dart'; |
14 import 'package:analysis_server/src/domains/analysis/navigation.dart'; | 13 import 'package:analysis_server/src/domains/analysis/navigation.dart'; |
15 import 'package:analysis_server/src/domains/analysis/occurrences.dart'; | 14 import 'package:analysis_server/src/domains/analysis/occurrences.dart'; |
16 import 'package:analysis_server/src/operation/operation.dart'; | 15 import 'package:analysis_server/src/operation/operation.dart'; |
17 import 'package:analysis_server/src/protocol_server.dart' as protocol; | 16 import 'package:analysis_server/src/protocol_server.dart' as protocol; |
18 import 'package:analysis_server/src/services/dependencies/library_dependencies.d
art'; | 17 import 'package:analysis_server/src/services/dependencies/library_dependencies.d
art'; |
19 import 'package:analysis_server/src/services/search/search_engine.dart'; | 18 import 'package:analysis_server/src/services/search/search_engine.dart'; |
20 import 'package:analyzer/dart/ast/ast.dart'; | 19 import 'package:analyzer/dart/ast/ast.dart'; |
21 import 'package:analyzer/dart/element/element.dart'; | 20 import 'package:analyzer/dart/element/element.dart'; |
22 import 'package:analyzer/src/generated/engine.dart'; | 21 import 'package:analyzer/src/generated/engine.dart'; |
23 import 'package:analyzer/src/generated/error.dart'; | 22 import 'package:analyzer/src/generated/error.dart'; |
24 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
25 import 'package:analyzer/task/dart.dart'; | |
26 import 'package:analyzer/task/model.dart'; | |
27 | 24 |
28 /** | 25 /** |
29 * Runs the given function [f] with the working cache size in [context]. | 26 * Runs the given function [f] with the working cache size in [context]. |
30 * Returns the result of [f] invocation. | 27 * Returns the result of [f] invocation. |
31 */ | 28 */ |
32 runWithWorkingCacheSize(AnalysisContext context, f()) { | 29 runWithWorkingCacheSize(AnalysisContext context, f()) { |
33 int currentCacheSize = context.analysisOptions.cacheSize; | 30 int currentCacheSize = context.analysisOptions.cacheSize; |
34 if (currentCacheSize < PerformAnalysisOperation.WORKING_CACHE_SIZE) { | 31 if (currentCacheSize < PerformAnalysisOperation.WORKING_CACHE_SIZE) { |
35 setCacheSize(context, PerformAnalysisOperation.WORKING_CACHE_SIZE); | 32 setCacheSize(context, PerformAnalysisOperation.WORKING_CACHE_SIZE); |
36 try { | 33 try { |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 } | 369 } |
373 // prepare results | 370 // prepare results |
374 AnalysisResult result = context.performAnalysisTask(); | 371 AnalysisResult result = context.performAnalysisTask(); |
375 List<ChangeNotice> notices = result.changeNotices; | 372 List<ChangeNotice> notices = result.changeNotices; |
376 // nothing to analyze | 373 // nothing to analyze |
377 if (notices == null) { | 374 if (notices == null) { |
378 server.scheduleCacheConsistencyValidation(context); | 375 server.scheduleCacheConsistencyValidation(context); |
379 setCacheSize(context, IDLE_CACHE_SIZE); | 376 setCacheSize(context, IDLE_CACHE_SIZE); |
380 server.sendContextAnalysisDoneNotifications( | 377 server.sendContextAnalysisDoneNotifications( |
381 context, AnalysisDoneReason.COMPLETE); | 378 context, AnalysisDoneReason.COMPLETE); |
382 _flushCache(server); | |
383 return; | 379 return; |
384 } | 380 } |
385 // process results | 381 // process results |
386 ServerPerformanceStatistics.notices.makeCurrentWhile(() { | 382 ServerPerformanceStatistics.notices.makeCurrentWhile(() { |
387 _sendNotices(server, notices); | 383 _sendNotices(server, notices); |
388 _updateIndex(server, notices); | 384 _updateIndex(server, notices); |
389 }); | 385 }); |
390 // continue analysis | 386 // continue analysis |
391 server.addOperation(new PerformAnalysisOperation(context, true)); | 387 server.addOperation(new PerformAnalysisOperation(context, true)); |
392 } | 388 } |
393 | 389 |
394 /** | 390 /** |
395 * Flush some of the [context] cache results, which we probably not | |
396 * going to use anymore. | |
397 */ | |
398 void _flushCache(AnalysisServer server) { | |
399 if (context is InternalAnalysisContext) { | |
400 InternalAnalysisContext context = this.context; | |
401 // Flush AST results for source outside of the analysis roots. | |
402 ContextManager contextManager = server.contextManager; | |
403 context.analysisCache.flush((target) { | |
404 if (target is Source || target is LibrarySpecificUnit) { | |
405 Source targetSource = target.source; | |
406 return !context.prioritySources.contains(targetSource) && | |
407 !contextManager.isInAnalysisRoot(targetSource.fullName); | |
408 } | |
409 return false; | |
410 }, (target, result) { | |
411 return result is ResultDescriptor<CompilationUnit>; | |
412 }); | |
413 } | |
414 } | |
415 | |
416 /** | |
417 * Send the information in the given list of notices back to the client. | 391 * Send the information in the given list of notices back to the client. |
418 */ | 392 */ |
419 void _sendNotices(AnalysisServer server, List<ChangeNotice> notices) { | 393 void _sendNotices(AnalysisServer server, List<ChangeNotice> notices) { |
420 for (int i = 0; i < notices.length; i++) { | 394 for (int i = 0; i < notices.length; i++) { |
421 ChangeNotice notice = notices[i]; | 395 ChangeNotice notice = notices[i]; |
422 Source source = notice.source; | 396 Source source = notice.source; |
423 String file = source.fullName; | 397 String file = source.fullName; |
424 // Dart | 398 // Dart |
425 CompilationUnit parsedDartUnit = notice.parsedDartUnit; | 399 CompilationUnit parsedDartUnit = notice.parsedDartUnit; |
426 CompilationUnit resolvedDartUnit = notice.resolvedDartUnit; | 400 CompilationUnit resolvedDartUnit = notice.resolvedDartUnit; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 abstract class _SingleFileOperation extends SourceSensitiveOperation { | 535 abstract class _SingleFileOperation extends SourceSensitiveOperation { |
562 final String file; | 536 final String file; |
563 | 537 |
564 _SingleFileOperation(AnalysisContext context, this.file) : super(context); | 538 _SingleFileOperation(AnalysisContext context, this.file) : super(context); |
565 | 539 |
566 @override | 540 @override |
567 bool shouldBeDiscardedOnSourceChange(Source source) { | 541 bool shouldBeDiscardedOnSourceChange(Source source) { |
568 return source.fullName == file; | 542 return source.fullName == file; |
569 } | 543 } |
570 } | 544 } |
OLD | NEW |