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.execution; | 5 library domain.execution; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analysis_server/src/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
11 import 'package:analysis_server/src/constants.dart'; | 11 import 'package:analysis_server/src/constants.dart'; |
12 import 'package:analysis_server/src/protocol.dart'; | 12 import 'package:analysis_server/src/protocol.dart'; |
13 import 'package:analyzer/file_system/file_system.dart'; | |
13 import 'package:analyzer/src/generated/engine.dart'; | 14 import 'package:analyzer/src/generated/engine.dart'; |
14 import 'package:analyzer/src/generated/source.dart'; | 15 import 'package:analyzer/src/generated/source.dart'; |
15 | 16 |
16 /** | 17 /** |
17 * Instances of the class [ExecutionDomainHandler] implement a [RequestHandler] | 18 * Instances of the class [ExecutionDomainHandler] implement a [RequestHandler] |
18 * that handles requests in the `execution` domain. | 19 * that handles requests in the `execution` domain. |
19 */ | 20 */ |
20 class ExecutionDomainHandler implements RequestHandler { | 21 class ExecutionDomainHandler implements RequestHandler { |
21 /** | 22 /** |
22 * The analysis server that is using this handler to process requests. | 23 * The analysis server that is using this handler to process requests. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 new ExecutionMapUriParams.fromRequest(request); | 92 new ExecutionMapUriParams.fromRequest(request); |
92 String contextId = params.id; | 93 String contextId = params.id; |
93 String path = contextMap[contextId]; | 94 String path = contextMap[contextId]; |
94 if (path == null) { | 95 if (path == null) { |
95 return new Response.invalidParameter( | 96 return new Response.invalidParameter( |
96 request, | 97 request, |
97 'id', | 98 'id', |
98 'There is no execution context with an id of $contextId'); | 99 'There is no execution context with an id of $contextId'); |
99 } | 100 } |
100 AnalysisContext context = server.getAnalysisContext(path); | 101 AnalysisContext context = server.getAnalysisContext(path); |
101 if (params.file != null) { | 102 if (context == null) { |
102 if (params.uri != null) { | 103 return new Response.invalidExecutionContext(request, contextId); |
104 } | |
105 String file = params.file; | |
106 String uri = params.uri; | |
107 if (file != null) { | |
108 if (uri != null) { | |
103 return new Response.invalidParameter( | 109 return new Response.invalidParameter( |
104 request, | 110 request, |
105 'file', | 111 'file', |
106 'Either file or uri must be provided, but not both'); | 112 'Either file or uri must be provided, but not both'); |
107 } | 113 } |
108 Source source = server.getSource(params.file); | 114 Resource resource = server.resourceProvider.getResource(file); |
109 String uri = context.sourceFactory.restoreUri(source).toString(); | 115 if (!resource.exists) { |
116 return new Response.invalidParameter(request, 'file', 'The file must exi st'); | |
117 } else if (resource is! File) { | |
118 return new Response.invalidParameter(request, 'file', 'The file must be a file'); | |
Paul Berry
2015/02/06 03:55:33
This seems like a confusing error message. Consid
Brian Wilkerson
2015/02/06 15:49:00
Done
| |
119 } | |
120 Source source = server.getSource(file); | |
121 uri = context.sourceFactory.restoreUri(source).toString(); | |
110 return new ExecutionMapUriResult(uri: uri).toResponse(request.id); | 122 return new ExecutionMapUriResult(uri: uri).toResponse(request.id); |
111 } else if (params.uri != null) { | 123 } else if (uri != null) { |
112 Source source = context.sourceFactory.forUri(params.uri); | 124 Source source = context.sourceFactory.forUri(uri); |
113 String file = source.fullName; | 125 if (source == null) { |
126 return new Response.invalidParameter( | |
127 request, | |
128 'uri', | |
129 'The uri must be a valid URI'); | |
Paul Berry
2015/02/06 03:55:33
Similarly, this will be formatted as "Invalid para
Brian Wilkerson
2015/02/06 15:49:00
Done
| |
130 } | |
131 file = source.fullName; | |
114 return new ExecutionMapUriResult(file: file).toResponse(request.id); | 132 return new ExecutionMapUriResult(file: file).toResponse(request.id); |
115 } | 133 } |
116 return new Response.invalidParameter( | 134 return new Response.invalidParameter( |
117 request, | 135 request, |
118 'file', | 136 'file', |
119 'Either file or uri must be provided'); | 137 'Either file or uri must be provided'); |
120 } | 138 } |
121 | 139 |
122 /** | 140 /** |
123 * Implement the 'execution.setSubscriptions' request. | 141 * Implement the 'execution.setSubscriptions' request. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 if (_isInAnalysisRoot(filePath)) { | 234 if (_isInAnalysisRoot(filePath)) { |
217 server.sendNotification( | 235 server.sendNotification( |
218 new ExecutionLaunchDataParams(filePath, kind: kind).toNotification()); | 236 new ExecutionLaunchDataParams(filePath, kind: kind).toNotification()); |
219 } | 237 } |
220 } | 238 } |
221 | 239 |
222 static List<String> _getFullNames(List<Source> sources) { | 240 static List<String> _getFullNames(List<Source> sources) { |
223 return sources.map((Source source) => source.fullName).toList(); | 241 return sources.map((Source source) => source.fullName).toList(); |
224 } | 242 } |
225 } | 243 } |
OLD | NEW |