| 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; |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 /** | 625 /** |
| 626 * Return the analysis result for the file with the given [path]. The file is | 626 * Return the analysis result for the file with the given [path]. The file is |
| 627 * analyzed in one of the analysis drivers to which the file was added, | 627 * analyzed in one of the analysis drivers to which the file was added, |
| 628 * otherwise in the first driver, otherwise `null` is returned. | 628 * otherwise in the first driver, otherwise `null` is returned. |
| 629 */ | 629 */ |
| 630 Future<nd.AnalysisResult> getAnalysisResult(String path) async { | 630 Future<nd.AnalysisResult> getAnalysisResult(String path) async { |
| 631 nd.AnalysisResult result = priorityFileResults[path]; | 631 nd.AnalysisResult result = priorityFileResults[path]; |
| 632 if (result != null) { | 632 if (result != null) { |
| 633 return result; | 633 return result; |
| 634 } | 634 } |
| 635 nd.AnalysisDriver driver = getAnalysisDriver(path); | 635 try { |
| 636 return driver?.getResult(path); | 636 nd.AnalysisDriver driver = getAnalysisDriver(path); |
| 637 return await driver?.getResult(path); |
| 638 } catch (e) { |
| 639 // Ignore the exception. |
| 640 // We don't want to log the same exception again and again. |
| 641 return null; |
| 642 } |
| 637 } | 643 } |
| 638 | 644 |
| 639 CompilationUnitElement getCompilationUnitElement(String file) { | 645 CompilationUnitElement getCompilationUnitElement(String file) { |
| 640 ContextSourcePair pair = getContextSourcePair(file); | 646 ContextSourcePair pair = getContextSourcePair(file); |
| 641 if (pair == null) { | 647 if (pair == null) { |
| 642 return null; | 648 return null; |
| 643 } | 649 } |
| 644 // prepare AnalysisContext and Source | 650 // prepare AnalysisContext and Source |
| 645 AnalysisContext context = pair.context; | 651 AnalysisContext context = pair.context; |
| 646 Source unitSource = pair.source; | 652 Source unitSource = pair.source; |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 if (drivers.isNotEmpty) { | 1210 if (drivers.isNotEmpty) { |
| 1205 Set<String> allNewFiles = | 1211 Set<String> allNewFiles = |
| 1206 subscriptions.values.expand((files) => files).toSet(); | 1212 subscriptions.values.expand((files) => files).toSet(); |
| 1207 for (String file in allNewFiles) { | 1213 for (String file in allNewFiles) { |
| 1208 nd.AnalysisDriver driver = drivers.firstWhere( | 1214 nd.AnalysisDriver driver = drivers.firstWhere( |
| 1209 (driver) => driver.addedFiles.contains(file), | 1215 (driver) => driver.addedFiles.contains(file), |
| 1210 orElse: () => drivers.first); | 1216 orElse: () => drivers.first); |
| 1211 // The result will be produced by the "results" stream with | 1217 // The result will be produced by the "results" stream with |
| 1212 // the fully resolved unit, and processed with sending analysis | 1218 // the fully resolved unit, and processed with sending analysis |
| 1213 // notifications as it happens after content changes. | 1219 // notifications as it happens after content changes. |
| 1214 driver.getResult(file); | 1220 driver.getResult(file).catchError((exception, stackTrace) {}); |
| 1215 } | 1221 } |
| 1216 } | 1222 } |
| 1217 return; | 1223 return; |
| 1218 } | 1224 } |
| 1219 // send notifications for already analyzed sources | 1225 // send notifications for already analyzed sources |
| 1220 subscriptions.forEach((service, Set<String> newFiles) { | 1226 subscriptions.forEach((service, Set<String> newFiles) { |
| 1221 Set<String> oldFiles = analysisServices[service]; | 1227 Set<String> oldFiles = analysisServices[service]; |
| 1222 Set<String> todoFiles = | 1228 Set<String> todoFiles = |
| 1223 oldFiles != null ? newFiles.difference(oldFiles) : newFiles; | 1229 oldFiles != null ? newFiles.difference(oldFiles) : newFiles; |
| 1224 for (String file in todoFiles) { | 1230 for (String file in todoFiles) { |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1841 _runDelayed(() { | 1847 _runDelayed(() { |
| 1842 sendAnalysisNotificationOverrides(analysisServer, path, unit); | 1848 sendAnalysisNotificationOverrides(analysisServer, path, unit); |
| 1843 }); | 1849 }); |
| 1844 } | 1850 } |
| 1845 } | 1851 } |
| 1846 // TODO(scheglov) Implement more notifications. | 1852 // TODO(scheglov) Implement more notifications. |
| 1847 // IMPLEMENTED | 1853 // IMPLEMENTED |
| 1848 // OCCURRENCES (not used in IDEA) | 1854 // OCCURRENCES (not used in IDEA) |
| 1849 // OUTLINE (not used in IDEA) | 1855 // OUTLINE (not used in IDEA) |
| 1850 }); | 1856 }); |
| 1857 analysisDriver.exceptions.listen((nd.ExceptionResult result) { |
| 1858 AnalysisEngine.instance.logger |
| 1859 .logError('Analysis failed: ${result.path}', result.exception); |
| 1860 }); |
| 1851 analysisServer.driverMap[folder] = analysisDriver; | 1861 analysisServer.driverMap[folder] = analysisDriver; |
| 1852 return analysisDriver; | 1862 return analysisDriver; |
| 1853 } | 1863 } |
| 1854 | 1864 |
| 1855 @override | 1865 @override |
| 1856 AnalysisContext addContext(Folder folder, AnalysisOptions options) { | 1866 AnalysisContext addContext(Folder folder, AnalysisOptions options) { |
| 1857 ContextBuilder builder = createContextBuilder(folder, options); | 1867 ContextBuilder builder = createContextBuilder(folder, options); |
| 1858 AnalysisContext context = builder.buildContext(folder.path); | 1868 AnalysisContext context = builder.buildContext(folder.path); |
| 1859 | 1869 |
| 1860 analysisServer.folderMap[folder] = context; | 1870 analysisServer.folderMap[folder] = context; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2085 */ | 2095 */ |
| 2086 static PerformanceTag splitStore = new PerformanceTag('splitStore'); | 2096 static PerformanceTag splitStore = new PerformanceTag('splitStore'); |
| 2087 } | 2097 } |
| 2088 | 2098 |
| 2089 class _NullStringSink implements StringSink { | 2099 class _NullStringSink implements StringSink { |
| 2090 void write(Object obj) {} | 2100 void write(Object obj) {} |
| 2091 void writeAll(Iterable objects, [String separator = ""]) {} | 2101 void writeAll(Iterable objects, [String separator = ""]) {} |
| 2092 void writeCharCode(int charCode) {} | 2102 void writeCharCode(int charCode) {} |
| 2093 void writeln([Object obj = ""]) {} | 2103 void writeln([Object obj = ""]) {} |
| 2094 } | 2104 } |
| OLD | NEW |