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 analysis.server; | 5 library analysis.server; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:core'; | 9 import 'dart:core'; |
10 import 'dart:io' as io; | 10 import 'dart:io' as io; |
11 import 'dart:math' show max; | 11 import 'dart:math' show max; |
12 | 12 |
13 import 'package:analysis_server/plugin/protocol/protocol.dart' | 13 import 'package:analysis_server/plugin/protocol/protocol.dart' |
14 hide AnalysisOptions, Element; | 14 hide AnalysisOptions, Element; |
15 import 'package:analysis_server/src/analysis_logger.dart'; | 15 import 'package:analysis_server/src/analysis_logger.dart'; |
16 import 'package:analysis_server/src/channel/channel.dart'; | 16 import 'package:analysis_server/src/channel/channel.dart'; |
17 import 'package:analysis_server/src/computer/new_notifications.dart'; | 17 import 'package:analysis_server/src/computer/new_notifications.dart'; |
18 import 'package:analysis_server/src/context_manager.dart'; | 18 import 'package:analysis_server/src/context_manager.dart'; |
19 import 'package:analysis_server/src/operation/operation.dart'; | 19 import 'package:analysis_server/src/operation/operation.dart'; |
20 import 'package:analysis_server/src/operation/operation_analysis.dart'; | 20 import 'package:analysis_server/src/operation/operation_analysis.dart'; |
21 import 'package:analysis_server/src/operation/operation_queue.dart'; | 21 import 'package:analysis_server/src/operation/operation_queue.dart'; |
22 import 'package:analysis_server/src/plugin/server_plugin.dart'; | 22 import 'package:analysis_server/src/plugin/server_plugin.dart'; |
23 import 'package:analysis_server/src/services/correction/namespace.dart'; | 23 import 'package:analysis_server/src/services/correction/namespace.dart'; |
24 import 'package:analysis_server/src/services/index/index.dart'; | 24 import 'package:analysis_server/src/services/index/index.dart'; |
25 import 'package:analysis_server/src/services/search/search_engine.dart'; | 25 import 'package:analysis_server/src/services/search/search_engine.dart'; |
26 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 26 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 27 import 'package:analysis_server/src/services/search/search_engine_internal2.dart
'; |
27 import 'package:analysis_server/src/single_context_manager.dart'; | 28 import 'package:analysis_server/src/single_context_manager.dart'; |
28 import 'package:analyzer/dart/ast/ast.dart'; | 29 import 'package:analyzer/dart/ast/ast.dart'; |
29 import 'package:analyzer/dart/element/element.dart'; | 30 import 'package:analyzer/dart/element/element.dart'; |
30 import 'package:analyzer/exception/exception.dart'; | 31 import 'package:analyzer/exception/exception.dart'; |
31 import 'package:analyzer/file_system/file_system.dart'; | 32 import 'package:analyzer/file_system/file_system.dart'; |
32 import 'package:analyzer/file_system/physical_file_system.dart'; | 33 import 'package:analyzer/file_system/physical_file_system.dart'; |
33 import 'package:analyzer/instrumentation/instrumentation.dart'; | 34 import 'package:analyzer/instrumentation/instrumentation.dart'; |
34 import 'package:analyzer/plugin/resolver_provider.dart'; | 35 import 'package:analyzer/plugin/resolver_provider.dart'; |
35 import 'package:analyzer/source/pub_package_map_provider.dart'; | 36 import 'package:analyzer/source/pub_package_map_provider.dart'; |
36 import 'package:analyzer/src/context/builder.dart'; | 37 import 'package:analyzer/src/context/builder.dart'; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 final ResourceProvider resourceProvider; | 113 final ResourceProvider resourceProvider; |
113 | 114 |
114 /** | 115 /** |
115 * The [Index] for this server, may be `null` if indexing is disabled. | 116 * The [Index] for this server, may be `null` if indexing is disabled. |
116 */ | 117 */ |
117 final Index index; | 118 final Index index; |
118 | 119 |
119 /** | 120 /** |
120 * The [SearchEngine] for this server, may be `null` if indexing is disabled. | 121 * The [SearchEngine] for this server, may be `null` if indexing is disabled. |
121 */ | 122 */ |
122 final SearchEngine searchEngine; | 123 SearchEngine searchEngine; |
123 | 124 |
124 /** | 125 /** |
125 * The plugin associated with this analysis server. | 126 * The plugin associated with this analysis server. |
126 */ | 127 */ |
127 final ServerPlugin serverPlugin; | 128 final ServerPlugin serverPlugin; |
128 | 129 |
129 /** | 130 /** |
130 * A list of the globs used to determine which files should be analyzed. The | 131 * A list of the globs used to determine which files should be analyzed. The |
131 * list is lazily created and should be accessed using [analyzedFilesGlobs]. | 132 * list is lazily created and should be accessed using [analyzedFilesGlobs]. |
132 */ | 133 */ |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 * | 340 * |
340 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are | 341 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are |
341 * propagated up the call stack. The default is true to allow analysis | 342 * propagated up the call stack. The default is true to allow analysis |
342 * exceptions to show up in unit tests, but it should be set to false when | 343 * exceptions to show up in unit tests, but it should be set to false when |
343 * running a full analysis server. | 344 * running a full analysis server. |
344 */ | 345 */ |
345 AnalysisServer( | 346 AnalysisServer( |
346 this.channel, | 347 this.channel, |
347 this.resourceProvider, | 348 this.resourceProvider, |
348 PubPackageMapProvider packageMapProvider, | 349 PubPackageMapProvider packageMapProvider, |
349 Index _index, | 350 this.index, |
350 this.serverPlugin, | 351 this.serverPlugin, |
351 this.options, | 352 this.options, |
352 this.sdkManager, | 353 this.sdkManager, |
353 this.instrumentationService, | 354 this.instrumentationService, |
354 {ResolverProvider fileResolverProvider: null, | 355 {ResolverProvider fileResolverProvider: null, |
355 ResolverProvider packageResolverProvider: null, | 356 ResolverProvider packageResolverProvider: null, |
356 bool useSingleContextManager: false, | 357 bool useSingleContextManager: false, |
357 this.rethrowExceptions: true}) | 358 this.rethrowExceptions: true}) { |
358 : index = _index, | |
359 searchEngine = _index != null ? new SearchEngineImpl(_index) : null { | |
360 _performance = performanceDuringStartup; | 359 _performance = performanceDuringStartup; |
361 defaultContextOptions.incremental = true; | 360 defaultContextOptions.incremental = true; |
362 defaultContextOptions.incrementalApi = | 361 defaultContextOptions.incrementalApi = |
363 options.enableIncrementalResolutionApi; | 362 options.enableIncrementalResolutionApi; |
364 defaultContextOptions.incrementalValidation = | 363 defaultContextOptions.incrementalValidation = |
365 options.enableIncrementalResolutionValidation; | 364 options.enableIncrementalResolutionValidation; |
366 defaultContextOptions.finerGrainedInvalidation = | 365 defaultContextOptions.finerGrainedInvalidation = |
367 options.finerGrainedInvalidation; | 366 options.finerGrainedInvalidation; |
368 defaultContextOptions.generateImplicitErrors = false; | 367 defaultContextOptions.generateImplicitErrors = false; |
369 operationQueue = new ServerOperationQueue(); | 368 operationQueue = new ServerOperationQueue(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 _onPriorityChangeController = | 406 _onPriorityChangeController = |
408 new StreamController<PriorityChangeEvent>.broadcast(); | 407 new StreamController<PriorityChangeEvent>.broadcast(); |
409 running = true; | 408 running = true; |
410 onAnalysisStarted.first.then((_) { | 409 onAnalysisStarted.first.then((_) { |
411 onAnalysisComplete.then((_) { | 410 onAnalysisComplete.then((_) { |
412 performanceAfterStartup = new ServerPerformance(); | 411 performanceAfterStartup = new ServerPerformance(); |
413 _performance = performanceAfterStartup; | 412 _performance = performanceAfterStartup; |
414 }); | 413 }); |
415 }); | 414 }); |
416 _setupIndexInvalidation(); | 415 _setupIndexInvalidation(); |
| 416 if (options.enableNewAnalysisDriver) { |
| 417 searchEngine = new SearchEngineImpl2(driverMap.values); |
| 418 } else if (index != null) { |
| 419 searchEngine = new SearchEngineImpl(index); |
| 420 } |
417 pubSummaryManager = | 421 pubSummaryManager = |
418 new PubSummaryManager(resourceProvider, '${io.pid}.temp'); | 422 new PubSummaryManager(resourceProvider, '${io.pid}.temp'); |
419 Notification notification = new ServerConnectedParams(VERSION, io.pid, | 423 Notification notification = new ServerConnectedParams(VERSION, io.pid, |
420 sessionId: instrumentationService.sessionId) | 424 sessionId: instrumentationService.sessionId) |
421 .toNotification(); | 425 .toNotification(); |
422 channel.sendNotification(notification); | 426 channel.sendNotification(notification); |
423 channel.listen(handleRequest, onDone: done, onError: error); | 427 channel.listen(handleRequest, onDone: done, onError: error); |
424 handlers = serverPlugin.createDomains(this); | 428 handlers = serverPlugin.createDomains(this); |
425 } | 429 } |
426 | 430 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 } | 599 } |
596 return null; | 600 return null; |
597 } | 601 } |
598 | 602 |
599 /** | 603 /** |
600 * Return the analysis result for the file with the given [path]. The file is | 604 * Return the analysis result for the file with the given [path]. The file is |
601 * analyzed in one of the analysis drivers to which the file was added, | 605 * analyzed in one of the analysis drivers to which the file was added, |
602 * otherwise in the first driver, otherwise `null` is returned. | 606 * otherwise in the first driver, otherwise `null` is returned. |
603 */ | 607 */ |
604 Future<nd.AnalysisResult> getAnalysisResult(String path) async { | 608 Future<nd.AnalysisResult> getAnalysisResult(String path) async { |
| 609 print('[getAnalysisResult] path: $path'); |
605 nd.AnalysisResult result = priorityFileResults[path]; | 610 nd.AnalysisResult result = priorityFileResults[path]; |
606 if (result != null) { | 611 if (result != null) { |
607 return result; | 612 return result; |
608 } | 613 } |
609 nd.AnalysisDriver driver = getAnalysisDriver(path); | 614 nd.AnalysisDriver driver = getAnalysisDriver(path); |
| 615 print('[getAnalysisResult] driver: ${driver.name}'); |
610 return driver?.getResult(path); | 616 return driver?.getResult(path); |
611 } | 617 } |
612 | 618 |
613 CompilationUnitElement getCompilationUnitElement(String file) { | 619 CompilationUnitElement getCompilationUnitElement(String file) { |
614 ContextSourcePair pair = getContextSourcePair(file); | 620 ContextSourcePair pair = getContextSourcePair(file); |
615 if (pair == null) { | 621 if (pair == null) { |
616 return null; | 622 return null; |
617 } | 623 } |
618 // prepare AnalysisContext and Source | 624 // prepare AnalysisContext and Source |
619 AnalysisContext context = pair.context; | 625 AnalysisContext context = pair.context; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 } | 770 } |
765 return context.getErrors(source); | 771 return context.getErrors(source); |
766 } | 772 } |
767 | 773 |
768 /** | 774 /** |
769 * Return a [Future] that completes with the resolved [AstNode] at the | 775 * Return a [Future] that completes with the resolved [AstNode] at the |
770 * given [offset] of the given [file], or with `null` if there is no node as | 776 * given [offset] of the given [file], or with `null` if there is no node as |
771 * the [offset]. | 777 * the [offset]. |
772 */ | 778 */ |
773 Future<AstNode> getNodeAtOffset(String file, int offset) async { | 779 Future<AstNode> getNodeAtOffset(String file, int offset) async { |
774 CompilationUnit unit = await getResolvedCompilationUnit(file); | 780 CompilationUnit unit; |
| 781 if (options.enableNewAnalysisDriver) { |
| 782 nd.AnalysisResult result = await getAnalysisResult(file); |
| 783 unit = result?.unit; |
| 784 } else { |
| 785 unit = await getResolvedCompilationUnit(file); |
| 786 } |
775 if (unit != null) { | 787 if (unit != null) { |
776 return new NodeLocator(offset).searchWithin(unit); | 788 return new NodeLocator(offset).searchWithin(unit); |
777 } | 789 } |
778 return null; | 790 return null; |
779 } | 791 } |
780 | 792 |
781 /** | 793 /** |
782 * Return a [Future] that completes with the resolved [CompilationUnit] for | 794 * Return a [Future] that completes with the resolved [CompilationUnit] for |
783 * the Dart file with the given [path], or with `null` if the file is not a | 795 * the Dart file with the given [path], or with `null` if the file is not a |
784 * Dart file or cannot be resolved. | 796 * Dart file or cannot be resolved. |
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2040 /** | 2052 /** |
2041 * The [PerformanceTag] for time spent in server request handlers. | 2053 * The [PerformanceTag] for time spent in server request handlers. |
2042 */ | 2054 */ |
2043 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 2055 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
2044 | 2056 |
2045 /** | 2057 /** |
2046 * The [PerformanceTag] for time spent in split store microtasks. | 2058 * The [PerformanceTag] for time spent in split store microtasks. |
2047 */ | 2059 */ |
2048 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 2060 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
2049 } | 2061 } |
OLD | NEW |