| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analysis_server/protocol/protocol.dart'; | 9 import 'package:analysis_server/protocol/protocol.dart'; |
| 10 import 'package:analysis_server/protocol/protocol_constants.dart'; |
| 10 import 'package:analysis_server/protocol/protocol_generated.dart'; | 11 import 'package:analysis_server/protocol/protocol_generated.dart'; |
| 11 import 'package:analysis_server/src/constants.dart'; | |
| 12 import 'package:analyzer_plugin/protocol/protocol_common.dart'; | 12 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| 13 import 'package:logging/logging.dart'; | 13 import 'package:logging/logging.dart'; |
| 14 import 'package:path/path.dart' as path; | 14 import 'package:path/path.dart' as path; |
| 15 | 15 |
| 16 import 'instrumentation_input_converter.dart'; | 16 import 'instrumentation_input_converter.dart'; |
| 17 import 'log_file_input_converter.dart'; | 17 import 'log_file_input_converter.dart'; |
| 18 import 'operation.dart'; | 18 import 'operation.dart'; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Common input converter superclass for sharing implementation. | 21 * Common input converter superclass for sharing implementation. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 CommonInputConverter(this.tmpSrcDirPath, this.srcPathMap); | 73 CommonInputConverter(this.tmpSrcDirPath, this.srcPathMap); |
| 74 | 74 |
| 75 Map<String, dynamic> asMap(dynamic value) => value as Map<String, dynamic>; | 75 Map<String, dynamic> asMap(dynamic value) => value as Map<String, dynamic>; |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * Return an operation for the notification or `null` if none. | 78 * Return an operation for the notification or `null` if none. |
| 79 */ | 79 */ |
| 80 Operation convertNotification(Map<String, dynamic> json) { | 80 Operation convertNotification(Map<String, dynamic> json) { |
| 81 String event = json['event']; | 81 String event = json['event']; |
| 82 if (event == SERVER_STATUS) { | 82 if (event == SERVER_NOTIFICATION_STATUS) { |
| 83 // {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}} | 83 // {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}} |
| 84 Map<String, dynamic> params = asMap(json['params']); | 84 Map<String, dynamic> params = asMap(json['params']); |
| 85 if (params != null) { | 85 if (params != null) { |
| 86 Map<String, dynamic> analysis = asMap(params['analysis']); | 86 Map<String, dynamic> analysis = asMap(params['analysis']); |
| 87 if (analysis != null && analysis['isAnalyzing'] == false) { | 87 if (analysis != null && analysis['isAnalyzing'] == false) { |
| 88 return new WaitForAnalysisCompleteOperation(); | 88 return new WaitForAnalysisCompleteOperation(); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 if (event == SERVER_CONNECTED) { | 92 if (event == SERVER_NOTIFICATION_CONNECTED) { |
| 93 // {"event":"server.connected","params":{"version":"1.7.0"}} | 93 // {"event":"server.connected","params":{"version":"1.7.0"}} |
| 94 return new StartServerOperation(); | 94 return new StartServerOperation(); |
| 95 } | 95 } |
| 96 if (eventsSeen.add(event)) { | 96 if (eventsSeen.add(event)) { |
| 97 logger.log(Level.INFO, 'Ignored notification: $event\n $json'); | 97 logger.log(Level.INFO, 'Ignored notification: $event\n $json'); |
| 98 } | 98 } |
| 99 return null; | 99 return null; |
| 100 } | 100 } |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * Return an operation for the request or `null` if none. | 103 * Return an operation for the request or `null` if none. |
| 104 */ | 104 */ |
| 105 Operation convertRequest(Map<String, dynamic> origJson) { | 105 Operation convertRequest(Map<String, dynamic> origJson) { |
| 106 Map<String, dynamic> json = asMap(translateSrcPaths(origJson)); | 106 Map<String, dynamic> json = asMap(translateSrcPaths(origJson)); |
| 107 requestMap[json['id']] = json; | 107 requestMap[json['id']] = json; |
| 108 String method = json['method']; | 108 String method = json['method']; |
| 109 // Sanity check operations that modify source | 109 // Sanity check operations that modify source |
| 110 // to ensure that the operation is on source in temp space | 110 // to ensure that the operation is on source in temp space |
| 111 if (method == ANALYSIS_UPDATE_CONTENT) { | 111 if (method == ANALYSIS_REQUEST_UPDATE_CONTENT) { |
| 112 // Track overlays in parallel with the analysis server | 112 // Track overlays in parallel with the analysis server |
| 113 // so that when an overlay is removed, the file can be updated on disk | 113 // so that when an overlay is removed, the file can be updated on disk |
| 114 Request request = new Request.fromJson(json); | 114 Request request = new Request.fromJson(json); |
| 115 var params = new AnalysisUpdateContentParams.fromRequest(request); | 115 var params = new AnalysisUpdateContentParams.fromRequest(request); |
| 116 params.files.forEach((String filePath, change) { | 116 params.files.forEach((String filePath, change) { |
| 117 if (change is AddContentOverlay) { | 117 if (change is AddContentOverlay) { |
| 118 String content = change.content; | 118 String content = change.content; |
| 119 if (content == null) { | 119 if (content == null) { |
| 120 throw 'expected new overlay content\n$json'; | 120 throw 'expected new overlay content\n$json'; |
| 121 } | 121 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 135 throw 'found path referencing source outside temp space\n$filePath\n
$json'; | 135 throw 'found path referencing source outside temp space\n$filePath\n
$json'; |
| 136 } | 136 } |
| 137 new File(filePath).writeAsStringSync(content); | 137 new File(filePath).writeAsStringSync(content); |
| 138 } else { | 138 } else { |
| 139 throw 'unknown overlay change $change\n$json'; | 139 throw 'unknown overlay change $change\n$json'; |
| 140 } | 140 } |
| 141 }); | 141 }); |
| 142 return new RequestOperation(this, json); | 142 return new RequestOperation(this, json); |
| 143 } | 143 } |
| 144 // Track performance for completion notifications | 144 // Track performance for completion notifications |
| 145 if (method == COMPLETION_GET_SUGGESTIONS) { | 145 if (method == COMPLETION_REQUEST_GET_SUGGESTIONS) { |
| 146 return new CompletionRequestOperation(this, json); | 146 return new CompletionRequestOperation(this, json); |
| 147 } | 147 } |
| 148 // TODO(danrubel) replace this with code | 148 // TODO(danrubel) replace this with code |
| 149 // that just forwards the translated request | 149 // that just forwards the translated request |
| 150 if (method == ANALYSIS_GET_HOVER || | 150 if (method == ANALYSIS_REQUEST_GET_HOVER || |
| 151 method == ANALYSIS_SET_ANALYSIS_ROOTS || | 151 method == ANALYSIS_REQUEST_SET_ANALYSIS_ROOTS || |
| 152 method == ANALYSIS_SET_PRIORITY_FILES || | 152 method == ANALYSIS_REQUEST_SET_PRIORITY_FILES || |
| 153 method == ANALYSIS_SET_SUBSCRIPTIONS || | 153 method == ANALYSIS_REQUEST_SET_SUBSCRIPTIONS || |
| 154 method == ANALYSIS_UPDATE_OPTIONS || | 154 method == ANALYSIS_REQUEST_UPDATE_OPTIONS || |
| 155 method == EDIT_GET_ASSISTS || | 155 method == EDIT_REQUEST_GET_ASSISTS || |
| 156 method == EDIT_GET_AVAILABLE_REFACTORINGS || | 156 method == EDIT_REQUEST_GET_AVAILABLE_REFACTORINGS || |
| 157 method == EDIT_GET_FIXES || | 157 method == EDIT_REQUEST_GET_FIXES || |
| 158 method == EDIT_GET_REFACTORING || | 158 method == EDIT_REQUEST_GET_REFACTORING || |
| 159 method == EDIT_SORT_MEMBERS || | 159 method == EDIT_REQUEST_SORT_MEMBERS || |
| 160 method == EXECUTION_CREATE_CONTEXT || | 160 method == EXECUTION_REQUEST_CREATE_CONTEXT || |
| 161 method == EXECUTION_DELETE_CONTEXT || | 161 method == EXECUTION_REQUEST_DELETE_CONTEXT || |
| 162 method == EXECUTION_MAP_URI || | 162 method == EXECUTION_REQUEST_MAP_URI || |
| 163 method == EXECUTION_SET_SUBSCRIPTIONS || | 163 method == EXECUTION_REQUEST_SET_SUBSCRIPTIONS || |
| 164 method == SEARCH_FIND_ELEMENT_REFERENCES || | 164 method == SEARCH_REQUEST_FIND_ELEMENT_REFERENCES || |
| 165 method == SEARCH_FIND_MEMBER_DECLARATIONS || | 165 method == SEARCH_REQUEST_FIND_MEMBER_DECLARATIONS || |
| 166 method == SERVER_GET_VERSION || | 166 method == SERVER_REQUEST_GET_VERSION || |
| 167 method == SERVER_SET_SUBSCRIPTIONS) { | 167 method == SERVER_REQUEST_SET_SUBSCRIPTIONS) { |
| 168 return new RequestOperation(this, json); | 168 return new RequestOperation(this, json); |
| 169 } | 169 } |
| 170 throw 'unknown request: $method\n $json'; | 170 throw 'unknown request: $method\n $json'; |
| 171 } | 171 } |
| 172 | 172 |
| 173 /** | 173 /** |
| 174 * Return an operation for the recorded/expected response. | 174 * Return an operation for the recorded/expected response. |
| 175 */ | 175 */ |
| 176 Operation convertResponse(Map<String, dynamic> json) { | 176 Operation convertResponse(Map<String, dynamic> json) { |
| 177 return new ResponseOperation(this, asMap(requestMap.remove(json['id'])), | 177 return new ResponseOperation(this, asMap(requestMap.remove(json['id'])), |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 if (op != null) { | 390 if (op != null) { |
| 391 outSink.add(op); | 391 outSink.add(op); |
| 392 } | 392 } |
| 393 } | 393 } |
| 394 | 394 |
| 395 @override | 395 @override |
| 396 void close() { | 396 void close() { |
| 397 outSink.close(); | 397 outSink.close(); |
| 398 } | 398 } |
| 399 } | 399 } |
| OLD | NEW |