| 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 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/computer/computer_hover.dart'; | 10 import 'package:analysis_server/src/computer/computer_hover.dart'; |
| 11 import 'package:analysis_server/src/computer/error.dart'; | 11 import 'package:analysis_server/src/computer/error.dart'; |
| 12 import 'package:analysis_server/src/constants.dart'; | 12 import 'package:analysis_server/src/constants.dart'; |
| 13 import 'package:analysis_server/src/protocol.dart'; | 13 import 'package:analysis_server/src/protocol.dart'; |
| 14 import 'package:analysis_services/constants.dart'; | 14 import 'package:analysis_services/constants.dart'; |
| 15 import 'package:analysis_services/search/search_engine.dart'; | |
| 16 import 'package:analyzer/src/generated/ast.dart'; | 15 import 'package:analyzer/src/generated/ast.dart'; |
| 17 import 'package:analyzer/src/generated/engine.dart'; | 16 import 'package:analyzer/src/generated/engine.dart'; |
| 18 | 17 |
| 19 | 18 |
| 20 /** | 19 /** |
| 21 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] | 20 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] |
| 22 * that handles requests in the `analysis` domain. | 21 * that handles requests in the `analysis` domain. |
| 23 */ | 22 */ |
| 24 class AnalysisDomainHandler implements RequestHandler { | 23 class AnalysisDomainHandler implements RequestHandler { |
| 25 /** | 24 /** |
| 26 * The analysis server that is using this handler to process requests. | 25 * The analysis server that is using this handler to process requests. |
| 27 */ | 26 */ |
| 28 final AnalysisServer server; | 27 final AnalysisServer server; |
| 29 | 28 |
| 30 /** | 29 /** |
| 31 * The [SearchEngine] for this server. | |
| 32 */ | |
| 33 SearchEngine searchEngine; | |
| 34 | |
| 35 /** | |
| 36 * Initialize a newly created handler to handle requests for the given [server
]. | 30 * Initialize a newly created handler to handle requests for the given [server
]. |
| 37 */ | 31 */ |
| 38 AnalysisDomainHandler(this.server) { | 32 AnalysisDomainHandler(this.server); |
| 39 searchEngine = server.searchEngine; | |
| 40 } | |
| 41 | 33 |
| 42 /** | 34 /** |
| 43 * Implement the `analysis.getErrors` request. | 35 * Implement the `analysis.getErrors` request. |
| 44 */ | 36 */ |
| 45 Response getErrors(Request request) { | 37 Response getErrors(Request request) { |
| 46 String file = request.getRequiredParameter(FILE).asString(); | 38 String file = request.getRequiredParameter(FILE).asString(); |
| 47 server.onFileAnalysisComplete(file).then((_) { | 39 server.onFileAnalysisComplete(file).then((_) { |
| 48 Response response = new Response(request.id); | 40 Response response = new Response(request.id); |
| 49 AnalysisErrorInfo errorInfo = server.getErrors(file); | 41 AnalysisErrorInfo errorInfo = server.getErrors(file); |
| 50 if (errorInfo == null) { | 42 if (errorInfo == null) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 server.setAnalysisSubscriptions(subMap); | 156 server.setAnalysisSubscriptions(subMap); |
| 165 return new Response(request.id); | 157 return new Response(request.id); |
| 166 } | 158 } |
| 167 | 159 |
| 168 /** | 160 /** |
| 169 * Implement the 'analysis.updateContent' request. | 161 * Implement the 'analysis.updateContent' request. |
| 170 */ | 162 */ |
| 171 Response updateContent(Request request) { | 163 Response updateContent(Request request) { |
| 172 var changes = new HashMap<String, ContentChange>(); | 164 var changes = new HashMap<String, ContentChange>(); |
| 173 RequestDatum filesDatum = request.getRequiredParameter(FILES); | 165 RequestDatum filesDatum = request.getRequiredParameter(FILES); |
| 174 Response errorResponse; | |
| 175 for (String file in filesDatum.keys) { | 166 for (String file in filesDatum.keys) { |
| 176 RequestDatum changeDatum = filesDatum[file]; | 167 RequestDatum changeDatum = filesDatum[file]; |
| 177 ContentChange change = new ContentChange(); | 168 ContentChange change = new ContentChange(); |
| 178 switch (changeDatum[TYPE].asString()) { | 169 switch (changeDatum[TYPE].asString()) { |
| 179 case 'add': | 170 case ANALYSIS_OVERLAY_ADD: |
| 180 change.contentOrReplacement = changeDatum[CONTENT].asString(); | 171 change.contentOrReplacement = changeDatum[CONTENT].asString(); |
| 181 break; | 172 break; |
| 182 case 'change': | 173 case ANALYSIS_OVERLAY_CHANGE: |
| 183 change.offset = changeDatum[OFFSET].asInt(); | 174 change.offset = changeDatum[OFFSET].asInt(); |
| 184 change.length = changeDatum[LENGTH].asInt(); | 175 change.length = changeDatum[LENGTH].asInt(); |
| 185 change.contentOrReplacement = changeDatum[REPLACEMENT].asString(); | 176 change.contentOrReplacement = changeDatum[REPLACEMENT].asString(); |
| 186 break; | 177 break; |
| 187 case 'remove': | 178 case ANALYSIS_OVERLAY_REMOVE: |
| 188 break; | 179 break; |
| 189 default: | 180 default: |
| 190 return new Response.invalidParameter(request, | 181 return new Response.invalidParameter( |
| 191 changeDatum[TYPE].path, 'be one of "add", "change", or "remove"'); | 182 request, |
| 183 changeDatum[TYPE].path, |
| 184 'be one of "add", "change", or "remove"'); |
| 192 } | 185 } |
| 193 changes[file] = change; | 186 changes[file] = change; |
| 194 } | 187 } |
| 195 if (errorResponse != null) { | |
| 196 return errorResponse; | |
| 197 } | |
| 198 server.updateContent(changes); | 188 server.updateContent(changes); |
| 199 return new Response(request.id); | 189 return new Response(request.id); |
| 200 } | 190 } |
| 201 | 191 |
| 202 /** | 192 /** |
| 203 * Implement the 'analysis.updateOptions' request. | 193 * Implement the 'analysis.updateOptions' request. |
| 204 */ | 194 */ |
| 205 Response updateOptions(Request request) { | 195 Response updateOptions(Request request) { |
| 206 // options | 196 // options |
| 207 RequestDatum optionsDatum = request.getRequiredParameter(OPTIONS); | 197 RequestDatum optionsDatum = request.getRequiredParameter(OPTIONS); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 * if the file should be read from the filesystem). | 254 * if the file should be read from the filesystem). |
| 265 * | 255 * |
| 266 * If [offset] and [length] are non-null, the replacement text which should | 256 * If [offset] and [length] are non-null, the replacement text which should |
| 267 * take the place of the [length] characters of the file starting at [offset]. | 257 * take the place of the [length] characters of the file starting at [offset]. |
| 268 */ | 258 */ |
| 269 String contentOrReplacement; | 259 String contentOrReplacement; |
| 270 | 260 |
| 271 int offset; | 261 int offset; |
| 272 int length; | 262 int length; |
| 273 } | 263 } |
| OLD | NEW |