| 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/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 return updateOptions(request); | 41 return updateOptions(request); |
| 42 } else if (requestName == ANALYSIS_UPDATE_SDKS) { | 42 } else if (requestName == ANALYSIS_UPDATE_SDKS) { |
| 43 return updateSdks(request); | 43 return updateSdks(request); |
| 44 } | 44 } |
| 45 } on RequestFailure catch (exception) { | 45 } on RequestFailure catch (exception) { |
| 46 return exception.response; | 46 return exception.response; |
| 47 } | 47 } |
| 48 return null; | 48 return null; |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** |
| 52 * Implement the 'analysis.setAnalysisRoots' request. |
| 53 */ |
| 51 Response setAnalysisRoots(Request request) { | 54 Response setAnalysisRoots(Request request) { |
| 52 // included | 55 // included |
| 53 RequestDatum includedDatum = request.getRequiredParameter(INCLUDED); | 56 RequestDatum includedDatum = request.getRequiredParameter(INCLUDED); |
| 54 List<String> includedPaths = includedDatum.asStringList(); | 57 List<String> includedPaths = includedDatum.asStringList(); |
| 55 // excluded | 58 // excluded |
| 56 RequestDatum excludedDatum = request.getRequiredParameter(EXCLUDED); | 59 RequestDatum excludedDatum = request.getRequiredParameter(EXCLUDED); |
| 57 List<String> excludedPaths = excludedDatum.asStringList(); | 60 List<String> excludedPaths = excludedDatum.asStringList(); |
| 58 // continue in server | 61 // continue in server |
| 59 server.setAnalysisRoots(request.id, includedPaths, excludedPaths); | 62 server.setAnalysisRoots(request.id, includedPaths, excludedPaths); |
| 60 return new Response(request.id); | 63 return new Response(request.id); |
| 61 } | 64 } |
| 62 | 65 |
| 66 /** |
| 67 * Implement the 'analysis.setPriorityFiles' request. |
| 68 */ |
| 63 Response setPriorityFiles(Request request) { | 69 Response setPriorityFiles(Request request) { |
| 64 // TODO(scheglov) implement | 70 // files |
| 65 return null; | 71 RequestDatum filesDatum = request.getRequiredParameter(FILES); |
| 72 List<String> files = filesDatum.asStringList(); |
| 73 server.setPriorityFiles(request, files); |
| 74 return new Response(request.id); |
| 66 } | 75 } |
| 67 | 76 |
| 77 /** |
| 78 * Implement the 'analysis.setSubscriptions' request. |
| 79 */ |
| 68 Response setSubscriptions(Request request) { | 80 Response setSubscriptions(Request request) { |
| 69 // parse subscriptions | 81 // parse subscriptions |
| 70 Map<AnalysisService, Set<String>> subMap; | 82 Map<AnalysisService, Set<String>> subMap; |
| 71 { | 83 { |
| 72 RequestDatum subDatum = request.getRequiredParameter(SUBSCRIPTIONS); | 84 RequestDatum subDatum = request.getRequiredParameter(SUBSCRIPTIONS); |
| 73 Map<String, List<String>> subStringMap = subDatum.asStringListMap(); | 85 Map<String, List<String>> subStringMap = subDatum.asStringListMap(); |
| 74 subMap = new HashMap<AnalysisService, Set<String>>(); | 86 subMap = new HashMap<AnalysisService, Set<String>>(); |
| 75 subStringMap.forEach((String serviceName, List<String> paths) { | 87 subStringMap.forEach((String serviceName, List<String> paths) { |
| 76 AnalysisService service = Enum2.valueOf(AnalysisService.VALUES, | 88 AnalysisService service = Enum2.valueOf(AnalysisService.VALUES, |
| 77 serviceName); | 89 serviceName); |
| 78 if (service == null) { | 90 if (service == null) { |
| 79 throw new RequestFailure(new Response.unknownAnalysisService(request, | 91 throw new RequestFailure(new Response.unknownAnalysisService(request, |
| 80 serviceName)); | 92 serviceName)); |
| 81 } | 93 } |
| 82 subMap[service] = new HashSet.from(paths); | 94 subMap[service] = new HashSet.from(paths); |
| 83 }); | 95 }); |
| 84 } | 96 } |
| 85 server.setAnalysisSubscriptions(subMap); | 97 server.setAnalysisSubscriptions(subMap); |
| 86 return new Response(request.id); | 98 return new Response(request.id); |
| 87 } | 99 } |
| 88 | 100 |
| 101 /** |
| 102 * Implement the 'analysis.updateContent' request. |
| 103 */ |
| 89 Response updateContent(Request request) { | 104 Response updateContent(Request request) { |
| 90 var changes = new HashMap<String, ContentChange>(); | 105 var changes = new HashMap<String, ContentChange>(); |
| 91 RequestDatum filesDatum = request.getRequiredParameter(FILES); | 106 RequestDatum filesDatum = request.getRequiredParameter(FILES); |
| 92 filesDatum.forEachMap((file, changeDatum) { | 107 filesDatum.forEachMap((file, changeDatum) { |
| 93 var change = new ContentChange(); | 108 var change = new ContentChange(); |
| 94 change.content = changeDatum[CONTENT].isNull ? null : | 109 change.content = changeDatum[CONTENT].isNull ? null : |
| 95 changeDatum[CONTENT].asString(); | 110 changeDatum[CONTENT].asString(); |
| 96 if (changeDatum.hasKey(OFFSET)) { | 111 if (changeDatum.hasKey(OFFSET)) { |
| 97 change.offset = changeDatum[OFFSET].asInt(); | 112 change.offset = changeDatum[OFFSET].asInt(); |
| 98 change.oldLength = changeDatum[OLD_LENGTH].asInt(); | 113 change.oldLength = changeDatum[OLD_LENGTH].asInt(); |
| 99 change.newLength = changeDatum[NEW_LENGTH].asInt(); | 114 change.newLength = changeDatum[NEW_LENGTH].asInt(); |
| 100 } | 115 } |
| 101 changes[file] = change; | 116 changes[file] = change; |
| 102 }); | 117 }); |
| 103 server.updateContent(changes); | 118 server.updateContent(changes); |
| 104 return new Response(request.id); | 119 return new Response(request.id); |
| 105 } | 120 } |
| 106 | 121 |
| 122 /** |
| 123 * Implement the 'analysis.updateOptions' request. |
| 124 */ |
| 107 Response updateOptions(Request request) { | 125 Response updateOptions(Request request) { |
| 126 // options |
| 127 RequestDatum optionsDatum = request.getRequiredParameter(OPTIONS); |
| 108 // TODO(scheglov) implement | 128 // TODO(scheglov) implement |
| 109 return null; | 129 return null; |
| 110 } | 130 } |
| 111 | 131 |
| 132 /** |
| 133 * Implement the 'analysis.updateSdks' request. |
| 134 */ |
| 112 Response updateSdks(Request request) { | 135 Response updateSdks(Request request) { |
| 136 // added |
| 137 RequestDatum addedDatum = request.getRequiredParameter(ADDED); |
| 138 List<String> added = addedDatum.asStringList(); |
| 139 // removed |
| 140 RequestDatum removedDatum = request.getRequiredParameter(REMOVED); |
| 141 List<String> removed = removedDatum.asStringList(); |
| 142 // default |
| 143 RequestDatum defaultDatum = request.getRequiredParameter(DEFAULT); |
| 144 String defaultSdk = defaultDatum.asString(); |
| 113 // TODO(scheglov) implement | 145 // TODO(scheglov) implement |
| 114 return null; | 146 return null; |
| 115 } | 147 } |
| 116 } | 148 } |
| 117 | 149 |
| 118 | 150 |
| 119 /** | 151 /** |
| 120 * A description of the change to the content of a file. | 152 * A description of the change to the content of a file. |
| 121 */ | 153 */ |
| 122 class ContentChange { | 154 class ContentChange { |
| 123 String content; | 155 String content; |
| 124 int offset; | 156 int offset; |
| 125 int oldLength; | 157 int oldLength; |
| 126 int newLength; | 158 int newLength; |
| 127 } | 159 } |
| OLD | NEW |