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:math' show max; | 9 import 'dart:math' show max; |
10 | 10 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 * running a full analysis server. | 242 * running a full analysis server. |
243 */ | 243 */ |
244 AnalysisServer(this.channel, this.resourceProvider, | 244 AnalysisServer(this.channel, this.resourceProvider, |
245 PackageMapProvider packageMapProvider, Index _index, | 245 PackageMapProvider packageMapProvider, Index _index, |
246 AnalysisServerOptions analysisServerOptions, this.defaultSdk, | 246 AnalysisServerOptions analysisServerOptions, this.defaultSdk, |
247 this.instrumentationService, {this.rethrowExceptions: true}) | 247 this.instrumentationService, {this.rethrowExceptions: true}) |
248 : index = _index, | 248 : index = _index, |
249 searchEngine = _index != null ? createSearchEngine(_index) : null { | 249 searchEngine = _index != null ? createSearchEngine(_index) : null { |
250 _performance = performanceDuringStartup; | 250 _performance = performanceDuringStartup; |
251 operationQueue = new ServerOperationQueue(); | 251 operationQueue = new ServerOperationQueue(); |
252 contextDirectoryManager = | 252 contextDirectoryManager = new ServerContextManager( |
253 new ServerContextManager(this, resourceProvider, packageMapProvider); | 253 this, |
| 254 resourceProvider, |
| 255 packageMapProvider, |
| 256 instrumentationService); |
254 contextDirectoryManager.defaultOptions.incremental = true; | 257 contextDirectoryManager.defaultOptions.incremental = true; |
255 contextDirectoryManager.defaultOptions.incrementalApi = | 258 contextDirectoryManager.defaultOptions.incrementalApi = |
256 analysisServerOptions.enableIncrementalResolutionApi; | 259 analysisServerOptions.enableIncrementalResolutionApi; |
257 contextDirectoryManager.defaultOptions.incrementalValidation = | 260 contextDirectoryManager.defaultOptions.incrementalValidation = |
258 analysisServerOptions.enableIncrementalResolutionValidation; | 261 analysisServerOptions.enableIncrementalResolutionValidation; |
259 _noErrorNotification = analysisServerOptions.noErrorNotification; | 262 _noErrorNotification = analysisServerOptions.noErrorNotification; |
260 AnalysisEngine.instance.logger = new AnalysisLogger(); | 263 AnalysisEngine.instance.logger = new AnalysisLogger(); |
261 _onAnalysisStartedController = new StreamController.broadcast(); | 264 _onAnalysisStartedController = new StreamController.broadcast(); |
262 _onFileAnalyzedController = new StreamController.broadcast(); | 265 _onFileAnalyzedController = new StreamController.broadcast(); |
263 _onPriorityChangeController = | 266 _onPriorityChangeController = |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // folderMap.values.forEach((ContextDirectory directory) { | 493 // folderMap.values.forEach((ContextDirectory directory) { |
491 // InternalAnalysisContext context = directory.context; | 494 // InternalAnalysisContext context = directory.context; |
492 // context.prioritySources.forEach((Source source) { | 495 // context.prioritySources.forEach((Source source) { |
493 // priorityFiles.add(source.fullName); | 496 // priorityFiles.add(source.fullName); |
494 // }); | 497 // }); |
495 // }); | 498 // }); |
496 // return priorityFiles; | 499 // return priorityFiles; |
497 // } | 500 // } |
498 | 501 |
499 /** | 502 /** |
| 503 * Returns resolved [CompilationUnit]s of the Dart file with the given [path]. |
| 504 * |
| 505 * May be empty, but not `null`. |
| 506 */ |
| 507 List<CompilationUnit> getResolvedCompilationUnits(String path) { |
| 508 List<CompilationUnit> units = <CompilationUnit>[]; |
| 509 // prepare AnalysisContext |
| 510 AnalysisContext context = getAnalysisContext(path); |
| 511 if (context == null) { |
| 512 return units; |
| 513 } |
| 514 // add a unit for each unit/library combination |
| 515 Source unitSource = getSource(path); |
| 516 List<Source> librarySources = context.getLibrariesContaining(unitSource); |
| 517 for (Source librarySource in librarySources) { |
| 518 CompilationUnit unit = |
| 519 context.resolveCompilationUnit2(unitSource, librarySource); |
| 520 if (unit != null) { |
| 521 units.add(unit); |
| 522 } |
| 523 } |
| 524 // done |
| 525 return units; |
| 526 } |
| 527 |
| 528 /** |
500 * Returns the [CompilationUnit] of the Dart file with the given [path] that | 529 * Returns the [CompilationUnit] of the Dart file with the given [path] that |
501 * should be used to resend notifications for already resolved unit. | 530 * should be used to resend notifications for already resolved unit. |
502 * Returns `null` if the file is not a part of any context, library has not | 531 * Returns `null` if the file is not a part of any context, library has not |
503 * been yet resolved, or any problem happened. | 532 * been yet resolved, or any problem happened. |
504 */ | 533 */ |
505 CompilationUnit getResolvedCompilationUnitToResendNotification(String path) { | 534 CompilationUnit getResolvedCompilationUnitToResendNotification(String path) { |
506 // prepare AnalysisContext | 535 // prepare AnalysisContext |
507 AnalysisContext context = getAnalysisContext(path); | 536 AnalysisContext context = getAnalysisContext(path); |
508 if (context == null) { | 537 if (context == null) { |
509 return null; | 538 return null; |
510 } | 539 } |
511 // prepare sources | 540 // prepare sources |
512 Source unitSource = getSource(path); | 541 Source unitSource = getSource(path); |
513 List<Source> librarySources = context.getLibrariesContaining(unitSource); | 542 List<Source> librarySources = context.getLibrariesContaining(unitSource); |
514 if (librarySources.isEmpty) { | 543 if (librarySources.isEmpty) { |
515 return null; | 544 return null; |
516 } | 545 } |
517 // if library has not been resolved yet, the unit will be resolved later | 546 // if library has not been resolved yet, the unit will be resolved later |
518 Source librarySource = librarySources[0]; | 547 Source librarySource = librarySources[0]; |
519 if (context.getLibraryElement(librarySource) == null) { | 548 if (context.getLibraryElement(librarySource) == null) { |
520 return null; | 549 return null; |
521 } | 550 } |
522 // if library has been already resolved, resolve unit | 551 // if library has been already resolved, resolve unit |
523 return context.resolveCompilationUnit2(unitSource, librarySource); | 552 return context.resolveCompilationUnit2(unitSource, librarySource); |
524 } | 553 } |
525 | 554 |
526 /** | 555 /** |
527 * Returns resolved [CompilationUnit]s of the Dart file with the given [path]. | |
528 * | |
529 * May be empty, but not `null`. | |
530 */ | |
531 List<CompilationUnit> getResolvedCompilationUnits(String path) { | |
532 List<CompilationUnit> units = <CompilationUnit>[]; | |
533 // prepare AnalysisContext | |
534 AnalysisContext context = getAnalysisContext(path); | |
535 if (context == null) { | |
536 return units; | |
537 } | |
538 // add a unit for each unit/library combination | |
539 Source unitSource = getSource(path); | |
540 List<Source> librarySources = context.getLibrariesContaining(unitSource); | |
541 for (Source librarySource in librarySources) { | |
542 CompilationUnit unit = | |
543 context.resolveCompilationUnit2(unitSource, librarySource); | |
544 if (unit != null) { | |
545 units.add(unit); | |
546 } | |
547 } | |
548 // done | |
549 return units; | |
550 } | |
551 | |
552 /** | |
553 * Return the [Source] of the Dart file with the given [path]. | 556 * Return the [Source] of the Dart file with the given [path]. |
554 */ | 557 */ |
555 Source getSource(String path) { | 558 Source getSource(String path) { |
556 // try SDK | 559 // try SDK |
557 { | 560 { |
558 Uri uri = resourceProvider.pathContext.toUri(path); | 561 Uri uri = resourceProvider.pathContext.toUri(path); |
559 Source sdkSource = defaultSdk.fromFileUri(uri); | 562 Source sdkSource = defaultSdk.fromFileUri(uri); |
560 if (sdkSource != null) { | 563 if (sdkSource != null) { |
561 return sdkSource; | 564 return sdkSource; |
562 } | 565 } |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 * The default options used to create new analysis contexts. | 1176 * The default options used to create new analysis contexts. |
1174 */ | 1177 */ |
1175 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); | 1178 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
1176 | 1179 |
1177 /** | 1180 /** |
1178 * The controller for sending [ContextsChangedEvent]s. | 1181 * The controller for sending [ContextsChangedEvent]s. |
1179 */ | 1182 */ |
1180 StreamController<ContextsChangedEvent> _onContextsChangedController; | 1183 StreamController<ContextsChangedEvent> _onContextsChangedController; |
1181 | 1184 |
1182 ServerContextManager(this.analysisServer, ResourceProvider resourceProvider, | 1185 ServerContextManager(this.analysisServer, ResourceProvider resourceProvider, |
1183 PackageMapProvider packageMapProvider) | 1186 PackageMapProvider packageMapProvider, InstrumentationService service) |
1184 : super(resourceProvider, packageMapProvider) { | 1187 : super(resourceProvider, packageMapProvider, service) { |
1185 _onContextsChangedController = | 1188 _onContextsChangedController = |
1186 new StreamController<ContextsChangedEvent>.broadcast(); | 1189 new StreamController<ContextsChangedEvent>.broadcast(); |
1187 } | 1190 } |
1188 | 1191 |
1189 /** | 1192 /** |
1190 * The stream that is notified when contexts are added or removed. | 1193 * The stream that is notified when contexts are added or removed. |
1191 */ | 1194 */ |
1192 Stream<ContextsChangedEvent> get onContextsChanged => | 1195 Stream<ContextsChangedEvent> get onContextsChanged => |
1193 _onContextsChangedController.stream; | 1196 _onContextsChangedController.stream; |
1194 | 1197 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 /** | 1372 /** |
1370 * The [PerformanceTag] for time spent in server request handlers. | 1373 * The [PerformanceTag] for time spent in server request handlers. |
1371 */ | 1374 */ |
1372 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); | 1375 static PerformanceTag serverRequests = new PerformanceTag('serverRequests'); |
1373 | 1376 |
1374 /** | 1377 /** |
1375 * The [PerformanceTag] for time spent in split store microtasks. | 1378 * The [PerformanceTag] for time spent in split store microtasks. |
1376 */ | 1379 */ |
1377 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 1380 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
1378 } | 1381 } |
OLD | NEW |