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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 328 |
329 /** | 329 /** |
330 * There was an error related to the socket from which requests are being | 330 * There was an error related to the socket from which requests are being |
331 * read. | 331 * read. |
332 */ | 332 */ |
333 void error(argument) { | 333 void error(argument) { |
334 running = false; | 334 running = false; |
335 } | 335 } |
336 | 336 |
337 /** | 337 /** |
338 * Performs all scheduled analysis operations. | |
339 */ | |
340 void test_performAllAnalysisOperations() { | |
341 while (true) { | |
342 ServerOperation operation = operationQueue.takeIf((operation) { | |
343 return operation is PerformAnalysisOperation; | |
344 }); | |
345 if (operation == null) { | |
346 break; | |
347 } | |
348 operation.perform(this); | |
349 } | |
350 } | |
351 | |
352 /** | |
353 * If the given notice applies to a file contained within an analysis root, | 338 * If the given notice applies to a file contained within an analysis root, |
354 * notify interested parties that the file has been (at least partially) | 339 * notify interested parties that the file has been (at least partially) |
355 * analyzed. | 340 * analyzed. |
356 */ | 341 */ |
357 void fileAnalyzed(ChangeNotice notice) { | 342 void fileAnalyzed(ChangeNotice notice) { |
358 if (contextDirectoryManager.isInAnalysisRoot(notice.source.fullName)) { | 343 if (contextDirectoryManager.isInAnalysisRoot(notice.source.fullName)) { |
359 _onFileAnalyzedController.add(notice); | 344 _onFileAnalyzedController.add(notice); |
360 } | 345 } |
361 } | 346 } |
362 | 347 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 } | 453 } |
469 // prepare Source | 454 // prepare Source |
470 Source source = getSource(file); | 455 Source source = getSource(file); |
471 if (context.getKindOf(source) == SourceKind.UNKNOWN) { | 456 if (context.getKindOf(source) == SourceKind.UNKNOWN) { |
472 return null; | 457 return null; |
473 } | 458 } |
474 // get errors for the file | 459 // get errors for the file |
475 return context.getErrors(source); | 460 return context.getErrors(source); |
476 } | 461 } |
477 | 462 |
478 // TODO(brianwilkerson) Add the following method after 'prioritySources' has | |
479 // been added to InternalAnalysisContext. | |
480 // /** | |
481 // * Return a list containing the full names of all of the sources that are | |
482 // * priority sources. | |
483 // */ | |
484 // List<String> getPriorityFiles() { | |
485 // List<String> priorityFiles = new List<String>(); | |
486 // folderMap.values.forEach((ContextDirectory directory) { | |
487 // InternalAnalysisContext context = directory.context; | |
488 // context.prioritySources.forEach((Source source) { | |
489 // priorityFiles.add(source.fullName); | |
490 // }); | |
491 // }); | |
492 // return priorityFiles; | |
493 // } | |
494 | |
495 /** | 463 /** |
496 * Returns resolved [AstNode]s at the given [offset] of the given [file]. | 464 * Returns resolved [AstNode]s at the given [offset] of the given [file]. |
497 * | 465 * |
498 * May be empty, but not `null`. | 466 * May be empty, but not `null`. |
499 */ | 467 */ |
500 List<AstNode> getNodesAtOffset(String file, int offset) { | 468 List<AstNode> getNodesAtOffset(String file, int offset) { |
501 List<CompilationUnit> units = getResolvedCompilationUnits(file); | 469 List<CompilationUnit> units = getResolvedCompilationUnits(file); |
502 List<AstNode> nodes = <AstNode>[]; | 470 List<AstNode> nodes = <AstNode>[]; |
503 for (CompilationUnit unit in units) { | 471 for (CompilationUnit unit in units) { |
504 AstNode node = new NodeLocator.con1(offset).searchWithin(unit); | 472 AstNode node = new NodeLocator.con1(offset).searchWithin(unit); |
505 if (node != null) { | 473 if (node != null) { |
506 nodes.add(node); | 474 nodes.add(node); |
507 } | 475 } |
508 } | 476 } |
509 return nodes; | 477 return nodes; |
510 } | 478 } |
511 | 479 |
| 480 // TODO(brianwilkerson) Add the following method after 'prioritySources' has |
| 481 // been added to InternalAnalysisContext. |
| 482 // /** |
| 483 // * Return a list containing the full names of all of the sources that are |
| 484 // * priority sources. |
| 485 // */ |
| 486 // List<String> getPriorityFiles() { |
| 487 // List<String> priorityFiles = new List<String>(); |
| 488 // folderMap.values.forEach((ContextDirectory directory) { |
| 489 // InternalAnalysisContext context = directory.context; |
| 490 // context.prioritySources.forEach((Source source) { |
| 491 // priorityFiles.add(source.fullName); |
| 492 // }); |
| 493 // }); |
| 494 // return priorityFiles; |
| 495 // } |
| 496 |
512 /** | 497 /** |
513 * Returns resolved [CompilationUnit]s of the Dart file with the given [path]. | 498 * Returns resolved [CompilationUnit]s of the Dart file with the given [path]. |
514 * | 499 * |
515 * May be empty, but not `null`. | 500 * May be empty, but not `null`. |
516 */ | 501 */ |
517 List<CompilationUnit> getResolvedCompilationUnits(String path) { | 502 List<CompilationUnit> getResolvedCompilationUnits(String path) { |
518 List<CompilationUnit> units = <CompilationUnit>[]; | 503 List<CompilationUnit> units = <CompilationUnit>[]; |
519 // prepare AnalysisContext | 504 // prepare AnalysisContext |
520 AnalysisContext context = getAnalysisContext(path); | 505 AnalysisContext context = getAnalysisContext(path); |
521 if (context == null) { | 506 if (context == null) { |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 void test_flushResolvedUnit(String file) { | 948 void test_flushResolvedUnit(String file) { |
964 if (AnalysisEngine.isDartFileName(file)) { | 949 if (AnalysisEngine.isDartFileName(file)) { |
965 AnalysisContextImpl context = getAnalysisContext(file); | 950 AnalysisContextImpl context = getAnalysisContext(file); |
966 Source source = getSource(file); | 951 Source source = getSource(file); |
967 DartEntry dartEntry = context.getReadableSourceEntryOrNull(source); | 952 DartEntry dartEntry = context.getReadableSourceEntryOrNull(source); |
968 dartEntry.flushAstStructures(); | 953 dartEntry.flushAstStructures(); |
969 } | 954 } |
970 } | 955 } |
971 | 956 |
972 /** | 957 /** |
| 958 * Performs all scheduled analysis operations. |
| 959 */ |
| 960 void test_performAllAnalysisOperations() { |
| 961 while (true) { |
| 962 ServerOperation operation = operationQueue.takeIf((operation) { |
| 963 return operation is PerformAnalysisOperation; |
| 964 }); |
| 965 if (operation == null) { |
| 966 break; |
| 967 } |
| 968 operation.perform(this); |
| 969 } |
| 970 } |
| 971 |
| 972 /** |
973 * Implementation for `analysis.updateContent`. | 973 * Implementation for `analysis.updateContent`. |
974 */ | 974 */ |
975 void updateContent(String id, Map<String, dynamic> changes) { | 975 void updateContent(String id, Map<String, dynamic> changes) { |
976 changes.forEach((file, change) { | 976 changes.forEach((file, change) { |
977 Source source = getSource(file); | 977 Source source = getSource(file); |
978 operationQueue.sourceAboutToChange(source); | 978 operationQueue.sourceAboutToChange(source); |
979 // Prepare the new contents. | 979 // Prepare the new contents. |
980 String oldContents = _overlayState.getContents(source); | 980 String oldContents = _overlayState.getContents(source); |
981 String newContents; | 981 String newContents; |
982 if (change is AddContentOverlay) { | 982 if (change is AddContentOverlay) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1163 new StreamController<ContextsChangedEvent>.broadcast(); | 1163 new StreamController<ContextsChangedEvent>.broadcast(); |
1164 } | 1164 } |
1165 | 1165 |
1166 /** | 1166 /** |
1167 * The stream that is notified when contexts are added or removed. | 1167 * The stream that is notified when contexts are added or removed. |
1168 */ | 1168 */ |
1169 Stream<ContextsChangedEvent> get onContextsChanged => | 1169 Stream<ContextsChangedEvent> get onContextsChanged => |
1170 _onContextsChangedController.stream; | 1170 _onContextsChangedController.stream; |
1171 | 1171 |
1172 @override | 1172 @override |
1173 void addContext(Folder folder, UriResolver packageUriResolver) { | 1173 AnalysisContext addContext(Folder folder, UriResolver packageUriResolver) { |
1174 InternalAnalysisContext context = | 1174 InternalAnalysisContext context = |
1175 AnalysisEngine.instance.createAnalysisContext(); | 1175 AnalysisEngine.instance.createAnalysisContext(); |
1176 context.contentCache = analysisServer._overlayState; | 1176 context.contentCache = analysisServer._overlayState; |
1177 analysisServer.folderMap[folder] = context; | 1177 analysisServer.folderMap[folder] = context; |
1178 context.sourceFactory = _createSourceFactory(packageUriResolver); | 1178 context.sourceFactory = _createSourceFactory(packageUriResolver); |
1179 context.analysisOptions = new AnalysisOptionsImpl.con1(defaultOptions); | 1179 context.analysisOptions = new AnalysisOptionsImpl.con1(defaultOptions); |
1180 _onContextsChangedController.add( | 1180 _onContextsChangedController.add( |
1181 new ContextsChangedEvent(added: [context])); | 1181 new ContextsChangedEvent(added: [context])); |
1182 analysisServer.schedulePerformAnalysisOperation(context); | 1182 analysisServer.schedulePerformAnalysisOperation(context); |
| 1183 return context; |
1183 } | 1184 } |
1184 | 1185 |
1185 @override | 1186 @override |
1186 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 1187 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
1187 AnalysisContext context = analysisServer.folderMap[contextFolder]; | 1188 AnalysisContext context = analysisServer.folderMap[contextFolder]; |
1188 if (context != null) { | 1189 if (context != null) { |
1189 context.applyChanges(changeSet); | 1190 context.applyChanges(changeSet); |
1190 analysisServer.schedulePerformAnalysisOperation(context); | 1191 analysisServer.schedulePerformAnalysisOperation(context); |
1191 } | 1192 } |
1192 } | 1193 } |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 new DateTime.now().millisecondsSinceEpoch - | 1326 new DateTime.now().millisecondsSinceEpoch - |
1326 request.clientRequestTime; | 1327 request.clientRequestTime; |
1327 requestLatency += latency; | 1328 requestLatency += latency; |
1328 maxLatency = max(maxLatency, latency); | 1329 maxLatency = max(maxLatency, latency); |
1329 if (latency > 150) { | 1330 if (latency > 150) { |
1330 ++slowRequestCount; | 1331 ++slowRequestCount; |
1331 } | 1332 } |
1332 } | 1333 } |
1333 } | 1334 } |
1334 } | 1335 } |
OLD | NEW |