| 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_navigation.dart'; | 9 import 'package:analysis_server/src/computer/computer_navigation.dart'; |
| 10 import 'package:analysis_server/src/computer/computer_occurrences.dart'; | 10 import 'package:analysis_server/src/computer/computer_occurrences.dart'; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 } catch (exception, stackTrace) { | 99 } catch (exception, stackTrace) { |
| 100 server.sendServerErrorNotification(exception, stackTrace); | 100 server.sendServerErrorNotification(exception, stackTrace); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * Instances of [PerformAnalysisOperation] perform a single analysis task. | 106 * Instances of [PerformAnalysisOperation] perform a single analysis task. |
| 107 */ | 107 */ |
| 108 class PerformAnalysisOperation extends ServerOperation { | 108 class PerformAnalysisOperation extends ServerOperation { |
| 109 static const int IDLE_CACHE_SIZE = AnalysisOptionsImpl.DEFAULT_CACHE_SIZE; |
| 110 static const int WORKING_CACHE_SIZE = 512; |
| 111 |
| 109 final AnalysisContext context; | 112 final AnalysisContext context; |
| 110 final bool isContinue; | 113 final bool isContinue; |
| 111 | 114 |
| 112 PerformAnalysisOperation(this.context, this.isContinue); | 115 PerformAnalysisOperation(this.context, this.isContinue); |
| 113 | 116 |
| 114 @override | 117 @override |
| 115 ServerOperationPriority get priority { | 118 ServerOperationPriority get priority { |
| 116 if (isContinue) { | 119 if (isContinue) { |
| 117 return ServerOperationPriority.ANALYSIS_CONTINUE; | 120 return ServerOperationPriority.ANALYSIS_CONTINUE; |
| 118 } else { | 121 } else { |
| 119 return ServerOperationPriority.ANALYSIS; | 122 return ServerOperationPriority.ANALYSIS; |
| 120 } | 123 } |
| 121 } | 124 } |
| 122 | 125 |
| 123 @override | 126 @override |
| 124 void perform(AnalysisServer server) { | 127 void perform(AnalysisServer server) { |
| 125 // | 128 // |
| 126 // TODO(brianwilkerson) Add an optional function-valued parameter to | 129 // TODO(brianwilkerson) Add an optional function-valued parameter to |
| 127 // performAnalysisTask that will be called when the task has been computed | 130 // performAnalysisTask that will be called when the task has been computed |
| 128 // but before it is performed and send notification in the function: | 131 // but before it is performed and send notification in the function: |
| 129 // | 132 // |
| 130 // AnalysisResult result = context.performAnalysisTask((taskDescription) { | 133 // AnalysisResult result = context.performAnalysisTask((taskDescription) { |
| 131 // sendStatusNotification(context.toString(), taskDescription); | 134 // sendStatusNotification(context.toString(), taskDescription); |
| 132 // }); | 135 // }); |
| 136 if (!isContinue) { |
| 137 _setCacheSize(WORKING_CACHE_SIZE); |
| 138 } |
| 133 // prepare results | 139 // prepare results |
| 134 AnalysisResult result = context.performAnalysisTask(); | 140 AnalysisResult result = context.performAnalysisTask(); |
| 135 List<ChangeNotice> notices = result.changeNotices; | 141 List<ChangeNotice> notices = result.changeNotices; |
| 136 if (notices == null) { | 142 if (notices == null) { |
| 143 _setCacheSize(IDLE_CACHE_SIZE); |
| 137 server.sendContextAnalysisDoneNotifications( | 144 server.sendContextAnalysisDoneNotifications( |
| 138 context, | 145 context, |
| 139 AnalysisDoneReason.COMPLETE); | 146 AnalysisDoneReason.COMPLETE); |
| 140 return; | 147 return; |
| 141 } | 148 } |
| 142 // process results | 149 // process results |
| 143 sendNotices(server, notices); | 150 sendNotices(server, notices); |
| 144 updateIndex(server, notices); | 151 updateIndex(server, notices); |
| 145 // continue analysis | 152 // continue analysis |
| 146 server.addOperation(new PerformAnalysisOperation(context, true)); | 153 server.addOperation(new PerformAnalysisOperation(context, true)); |
| 147 } | 154 } |
| 148 | 155 |
| 156 void _setCacheSize(int cacheSize) { |
| 157 AnalysisOptionsImpl options = new AnalysisOptionsImpl.con1(context.analysisO
ptions); |
| 158 options.cacheSize = cacheSize; |
| 159 context.analysisOptions = options; |
| 160 } |
| 161 |
| 149 /** | 162 /** |
| 150 * Send the information in the given list of notices back to the client. | 163 * Send the information in the given list of notices back to the client. |
| 151 */ | 164 */ |
| 152 void sendNotices(AnalysisServer server, List<ChangeNotice> notices) { | 165 void sendNotices(AnalysisServer server, List<ChangeNotice> notices) { |
| 153 for (int i = 0; i < notices.length; i++) { | 166 for (int i = 0; i < notices.length; i++) { |
| 154 ChangeNotice notice = notices[i]; | 167 ChangeNotice notice = notices[i]; |
| 155 Source source = notice.source; | 168 Source source = notice.source; |
| 156 String file = source.fullName; | 169 String file = source.fullName; |
| 157 // Dart | 170 // Dart |
| 158 CompilationUnit dartUnit = notice.compilationUnit; | 171 CompilationUnit dartUnit = notice.compilationUnit; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 HtmlUnit htmlUnit = notice.htmlUnit; | 228 HtmlUnit htmlUnit = notice.htmlUnit; |
| 216 if (htmlUnit != null) { | 229 if (htmlUnit != null) { |
| 217 index.indexHtmlUnit(context, htmlUnit); | 230 index.indexHtmlUnit(context, htmlUnit); |
| 218 } | 231 } |
| 219 } catch (exception, stackTrace) { | 232 } catch (exception, stackTrace) { |
| 220 server.sendServerErrorNotification(exception, stackTrace); | 233 server.sendServerErrorNotification(exception, stackTrace); |
| 221 } | 234 } |
| 222 } | 235 } |
| 223 } | 236 } |
| 224 } | 237 } |
| OLD | NEW |