| 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 domain.analysis; | 5 library domain.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/constants.dart'; |
| 8 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 9 | 10 |
| 10 /** | 11 /** |
| 11 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] | 12 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] |
| 12 * that handles requests in the `analysis` domain. | 13 * that handles requests in the `analysis` domain. |
| 13 */ | 14 */ |
| 14 class AnalysisDomainHandler implements RequestHandler { | 15 class AnalysisDomainHandler implements RequestHandler { |
| 15 /** | 16 /** |
| 16 * The name of the `analysis.getFixes` request. | |
| 17 */ | |
| 18 static const String GET_FIXES_METHOD = 'analysis.getFixes'; | |
| 19 | |
| 20 /** | |
| 21 * The name of the `analysis.getMinorRefactorings` request. | |
| 22 */ | |
| 23 static const String GET_MINOR_REFACTORINGS_METHOD = 'analysis.getMinorRefactor
ings'; | |
| 24 | |
| 25 /** | |
| 26 * The name of the `analysis.setAnalysisRoots` request. | |
| 27 */ | |
| 28 static const String SET_ANALYSIS_ROOTS_METHOD = 'analysis.setAnalysisRoots'; | |
| 29 | |
| 30 /** | |
| 31 * The name of the `analysis.setPriorityFiles` request. | |
| 32 */ | |
| 33 static const String SET_PRIORITY_FILES_METHOD = 'analysis.setPriorityFiles'; | |
| 34 | |
| 35 /** | |
| 36 * The name of the `analysis.setSubscriptions` request. | |
| 37 */ | |
| 38 static const String SET_SUBSCRIPTIONS_METHOD = 'analysis.setSubscriptions'; | |
| 39 | |
| 40 /** | |
| 41 * The name of the `analysis.updateContent` request. | |
| 42 */ | |
| 43 static const String UPDATE_CONTENT_METHOD = 'analysis.updateContent'; | |
| 44 | |
| 45 /** | |
| 46 * The name of the `analysis.updateOptions` request. | |
| 47 */ | |
| 48 static const String UPDATE_OPTIONS_METHOD = 'analysis.updateOptions'; | |
| 49 | |
| 50 /** | |
| 51 * The name of the `analysis.updateSdks` request. | |
| 52 */ | |
| 53 static const String UPDATE_SDKS_METHOD = 'analysis.updateSdks'; | |
| 54 | |
| 55 /** | |
| 56 * The name of the `analysis.errors` notification. | |
| 57 */ | |
| 58 static const String ERRORS_NOTIFICATION = 'analysis.errors'; | |
| 59 | |
| 60 /** | |
| 61 * The name of the `analysis.highlights` notification. | |
| 62 */ | |
| 63 static const String HIGHLIGHTS_NOTIFICATION = 'analysis.highlights'; | |
| 64 | |
| 65 /** | |
| 66 * The name of the `analysis.navigation` notification. | |
| 67 */ | |
| 68 static const String NAVIGATION_NOTIFICATION = 'analysis.navigation'; | |
| 69 | |
| 70 /** | |
| 71 * The name of the `analysis.outline` notification. | |
| 72 */ | |
| 73 static const String OUTLINE_NOTIFICATION = 'analysis.outline'; | |
| 74 | |
| 75 /** | |
| 76 * The name of the `aadded` parameter. | |
| 77 */ | |
| 78 static const String ADDED_PARAM = 'added'; | |
| 79 | |
| 80 /** | |
| 81 * The name of the `content` parameter. | |
| 82 */ | |
| 83 static const String CONTENT_PARAM = 'content'; | |
| 84 | |
| 85 /** | |
| 86 * The name of the `default` parameter. | |
| 87 */ | |
| 88 static const String DEFAULT_PARAM = 'default'; | |
| 89 | |
| 90 /** | |
| 91 * The name of the `errors` parameter. | |
| 92 */ | |
| 93 static const String ERRORS_PARAM = 'errors'; | |
| 94 | |
| 95 /** | |
| 96 * The name of the `excluded` parameter. | |
| 97 */ | |
| 98 static const String EXCLUDED_PARAM = 'excluded'; | |
| 99 | |
| 100 /** | |
| 101 * The name of the `file` parameter. | |
| 102 */ | |
| 103 static const String FILE_PARAM = 'file'; | |
| 104 | |
| 105 /** | |
| 106 * The name of the `files` parameter. | |
| 107 */ | |
| 108 static const String FILES_PARAM = 'files'; | |
| 109 | |
| 110 /** | |
| 111 * The name of the `fixes` parameter. | |
| 112 */ | |
| 113 static const String FIXES_PARAM = 'fixes'; | |
| 114 | |
| 115 /** | |
| 116 * The name of the `included` parameter. | |
| 117 */ | |
| 118 static const String INCLUDED_PARAM = 'included'; | |
| 119 | |
| 120 /** | |
| 121 * The name of the `length` parameter. | |
| 122 */ | |
| 123 static const String LENGTH_PARAM = 'length'; | |
| 124 | |
| 125 /** | |
| 126 * The name of the `newLength` parameter. | |
| 127 */ | |
| 128 static const String NEW_LENGTH_PARAM = 'newLength'; | |
| 129 | |
| 130 /** | |
| 131 * The name of the `offset` parameter. | |
| 132 */ | |
| 133 static const String OFFSET_PARAM = 'offset'; | |
| 134 | |
| 135 /** | |
| 136 * The name of the `oldLength` parameter. | |
| 137 */ | |
| 138 static const String OLD_LENGTH_PARAM = 'oldLength'; | |
| 139 | |
| 140 /** | |
| 141 * The name of the `options` parameter. | |
| 142 */ | |
| 143 static const String OPTIONS_PARAM = 'options'; | |
| 144 | |
| 145 /** | |
| 146 * The name of the `outline` parameter. | |
| 147 */ | |
| 148 static const String OUTLINE_PARAM = 'outline'; | |
| 149 | |
| 150 /** | |
| 151 * The name of the `refactorings` parameter. | |
| 152 */ | |
| 153 static const String REFACTORINGS_PARAM = 'refactorings'; | |
| 154 | |
| 155 /** | |
| 156 * The name of the `regions` parameter. | |
| 157 */ | |
| 158 static const String REGIONS_PARAM = 'regions'; | |
| 159 | |
| 160 /** | |
| 161 * The name of the `removed` parameter. | |
| 162 */ | |
| 163 static const String REMOVED_PARAM = 'removed'; | |
| 164 | |
| 165 /** | |
| 166 * The name of the `subscriptions` parameter. | |
| 167 */ | |
| 168 static const String SUBSCRIPTIONS_PARAM = 'subscriptions'; | |
| 169 | |
| 170 /** | |
| 171 * The analysis server that is using this handler to process requests. | 17 * The analysis server that is using this handler to process requests. |
| 172 */ | 18 */ |
| 173 final AnalysisServer server; | 19 final AnalysisServer server; |
| 174 | 20 |
| 175 /** | 21 /** |
| 176 * Initialize a newly created handler to handle requests for the given [server
]. | 22 * Initialize a newly created handler to handle requests for the given [server
]. |
| 177 */ | 23 */ |
| 178 AnalysisDomainHandler(this.server); | 24 AnalysisDomainHandler(this.server); |
| 179 | 25 |
| 180 @override | 26 @override |
| 181 Response handleRequest(Request request) { | 27 Response handleRequest(Request request) { |
| 182 try { | 28 try { |
| 183 String requestName = request.method; | 29 String requestName = request.method; |
| 184 if (requestName == GET_FIXES_METHOD) { | 30 if (requestName == METHOD_GET_FIXES) { |
| 185 return getFixes(request); | 31 return getFixes(request); |
| 186 } else if (requestName == GET_MINOR_REFACTORINGS_METHOD) { | 32 } else if (requestName == METHOD_GET_MINOR_REFACTORINGS) { |
| 187 return getMinorRefactorings(request); | 33 return getMinorRefactorings(request); |
| 188 } else if (requestName == SET_ANALYSIS_ROOTS_METHOD) { | 34 } else if (requestName == METHOD_SET_ANALYSIS_ROOTS) { |
| 189 return setAnalysisRoots(request); | 35 return setAnalysisRoots(request); |
| 190 } else if (requestName == SET_PRIORITY_FILES_METHOD) { | 36 } else if (requestName == METHOD_SET_PRIORITY_FILES) { |
| 191 return setPriorityFiles(request); | 37 return setPriorityFiles(request); |
| 192 } else if (requestName == SET_SUBSCRIPTIONS_METHOD) { | 38 } else if (requestName == METHOD_SET_SUBSCRIPTIONS) { |
| 193 return setSubscriptions(request); | 39 return setSubscriptions(request); |
| 194 } else if (requestName == UPDATE_CONTENT_METHOD) { | 40 } else if (requestName == METHOD_UPDATE_CONTENT) { |
| 195 return updateContent(request); | 41 return updateContent(request); |
| 196 } else if (requestName == UPDATE_OPTIONS_METHOD) { | 42 } else if (requestName == METHOD_UPDATE_OPTIONS) { |
| 197 return updateOptions(request); | 43 return updateOptions(request); |
| 198 } else if (requestName == UPDATE_SDKS_METHOD) { | 44 } else if (requestName == METHOD_UPDATE_SDKS) { |
| 199 return updateSdks(request); | 45 return updateSdks(request); |
| 200 } | 46 } |
| 201 } on RequestFailure catch (exception) { | 47 } on RequestFailure catch (exception) { |
| 202 return exception.response; | 48 return exception.response; |
| 203 } | 49 } |
| 204 return null; | 50 return null; |
| 205 } | 51 } |
| 206 | 52 |
| 207 Response getFixes(Request request) { | 53 Response getFixes(Request request) { |
| 208 // TODO(scheglov) implement | 54 // TODO(scheglov) implement |
| 209 return null; | 55 return null; |
| 210 } | 56 } |
| 211 | 57 |
| 212 Response getMinorRefactorings(Request request) { | 58 Response getMinorRefactorings(Request request) { |
| 213 // TODO(scheglov) implement | 59 // TODO(scheglov) implement |
| 214 return null; | 60 return null; |
| 215 } | 61 } |
| 216 | 62 |
| 217 Response setAnalysisRoots(Request request) { | 63 Response setAnalysisRoots(Request request) { |
| 218 // included | 64 // included |
| 219 RequestDatum includedDatum = request.getRequiredParameter(INCLUDED_PARAM); | 65 RequestDatum includedDatum = request.getRequiredParameter(INCLUDED); |
| 220 List<String> includedPaths = includedDatum.asStringList(); | 66 List<String> includedPaths = includedDatum.asStringList(); |
| 221 // excluded | 67 // excluded |
| 222 RequestDatum excludedDatum = request.getRequiredParameter(EXCLUDED_PARAM); | 68 RequestDatum excludedDatum = request.getRequiredParameter(EXCLUDED); |
| 223 List<String> excludedPaths = excludedDatum.asStringList(); | 69 List<String> excludedPaths = excludedDatum.asStringList(); |
| 224 // continue in server | 70 // continue in server |
| 225 server.setAnalysisRoots(request.id, includedPaths, excludedPaths); | 71 server.setAnalysisRoots(request.id, includedPaths, excludedPaths); |
| 226 return new Response(request.id); | 72 return new Response(request.id); |
| 227 } | 73 } |
| 228 | 74 |
| 229 Response setPriorityFiles(Request request) { | 75 Response setPriorityFiles(Request request) { |
| 230 // TODO(scheglov) implement | 76 // TODO(scheglov) implement |
| 231 return null; | 77 return null; |
| 232 } | 78 } |
| 233 | 79 |
| 234 Response setSubscriptions(Request request) { | 80 Response setSubscriptions(Request request) { |
| 235 // TODO(scheglov) implement | 81 // TODO(scheglov) implement |
| 236 return null; | 82 return null; |
| 237 } | 83 } |
| 238 | 84 |
| 239 Response updateContent(Request request) { | 85 Response updateContent(Request request) { |
| 240 var changes = new Map<String, ContentChange>(); | 86 var changes = new Map<String, ContentChange>(); |
| 241 RequestDatum filesDatum = request.getRequiredParameter(FILES_PARAM); | 87 RequestDatum filesDatum = request.getRequiredParameter(FILES); |
| 242 filesDatum.forEachMap((file, changeDatum) { | 88 filesDatum.forEachMap((file, changeDatum) { |
| 243 var change = new ContentChange(); | 89 var change = new ContentChange(); |
| 244 change.content = changeDatum[CONTENT_PARAM].asString(); | 90 change.content = changeDatum[CONTENT].asString(); |
| 245 if (changeDatum.hasKey(OFFSET_PARAM)) { | 91 if (changeDatum.hasKey(OFFSET)) { |
| 246 change.offset = changeDatum[OFFSET_PARAM].asInt(); | 92 change.offset = changeDatum[OFFSET].asInt(); |
| 247 change.oldLength = changeDatum[OLD_LENGTH_PARAM].asInt(); | 93 change.oldLength = changeDatum[OLD_LENGTH].asInt(); |
| 248 change.newLength = changeDatum[NEW_LENGTH_PARAM].asInt(); | 94 change.newLength = changeDatum[NEW_LENGTH].asInt(); |
| 249 } | 95 } |
| 250 changes[file] = change; | 96 changes[file] = change; |
| 251 }); | 97 }); |
| 252 server.updateContent(changes); | 98 server.updateContent(changes); |
| 253 return new Response(request.id); | 99 return new Response(request.id); |
| 254 } | 100 } |
| 255 | 101 |
| 256 Response updateOptions(Request request) { | 102 Response updateOptions(Request request) { |
| 257 // TODO(scheglov) implement | 103 // TODO(scheglov) implement |
| 258 return null; | 104 return null; |
| 259 } | 105 } |
| 260 | 106 |
| 261 Response updateSdks(Request request) { | 107 Response updateSdks(Request request) { |
| 262 // TODO(scheglov) implement | 108 // TODO(scheglov) implement |
| 263 return null; | 109 return null; |
| 264 } | 110 } |
| 265 } | 111 } |
| 266 | 112 |
| 267 | 113 |
| 268 /** | 114 /** |
| 269 * A description of the change to the content of a file. | 115 * A description of the change to the content of a file. |
| 270 */ | 116 */ |
| 271 class ContentChange { | 117 class ContentChange { |
| 272 String content; | 118 String content; |
| 273 int offset; | 119 int offset; |
| 274 int oldLength; | 120 int oldLength; |
| 275 int newLength; | 121 int newLength; |
| 276 } | 122 } |
| OLD | NEW |