Chromium Code Reviews| 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.server; | 5 library domain.server; |
| 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/protocol.dart'; | 8 import 'package:analysis_server/src/protocol.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/java_io.dart'; | 10 import 'package:analyzer/src/generated/java_io.dart'; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 * The name of the packageMap parameter. | 46 * The name of the packageMap parameter. |
| 47 */ | 47 */ |
| 48 static const String PACKAGE_MAP_PARAM = 'packageMap'; | 48 static const String PACKAGE_MAP_PARAM = 'packageMap'; |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * The name of the sdkDirectory parameter. | 51 * The name of the sdkDirectory parameter. |
| 52 */ | 52 */ |
| 53 static const String SDK_DIRECTORY_PARAM = 'sdkDirectory'; | 53 static const String SDK_DIRECTORY_PARAM = 'sdkDirectory'; |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * The name of the contextId result value. | |
| 57 */ | |
| 58 static const String CONTEXT_ID_RESULT = 'contextId'; | |
| 59 | |
| 60 /** | |
| 61 * The name of the version result value. | 56 * The name of the version result value. |
| 62 */ | 57 */ |
| 63 static const String VERSION_RESULT = 'version'; | 58 static const String VERSION_RESULT = 'version'; |
| 64 | 59 |
| 65 /** | 60 /** |
| 66 * The analysis server that is using this handler to process requests. | 61 * The analysis server that is using this handler to process requests. |
| 67 */ | 62 */ |
| 68 final AnalysisServer server; | 63 final AnalysisServer server; |
| 69 | 64 |
| 70 /** | 65 /** |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 93 | 88 |
| 94 /** | 89 /** |
| 95 * Create a new context in which analysis can be performed. The context that | 90 * Create a new context in which analysis can be performed. The context that |
| 96 * is created will persist until server.deleteContext is used to delete it. | 91 * is created will persist until server.deleteContext is used to delete it. |
| 97 * Clients, therefore, are responsible for managing the lifetime of contexts. | 92 * Clients, therefore, are responsible for managing the lifetime of contexts. |
| 98 */ | 93 */ |
| 99 Response createContext(Request request) { | 94 Response createContext(Request request) { |
| 100 String sdkDirectory = request.getRequiredParameter(SDK_DIRECTORY_PARAM); | 95 String sdkDirectory = request.getRequiredParameter(SDK_DIRECTORY_PARAM); |
| 101 Map<String, String> packageMap = request.getParameter(PACKAGE_MAP_PARAM); | 96 Map<String, String> packageMap = request.getParameter(PACKAGE_MAP_PARAM); |
| 102 | 97 |
| 103 String baseContextId = new DateTime.now().millisecondsSinceEpoch.toRadixStri ng(16); | 98 String contextId = request.getParameter(CONTEXT_ID_PARAM); |
|
Brian Wilkerson
2014/04/18 21:58:25
I think this should use getRequiredParameter.
We
Paul Berry
2014/04/18 22:21:19
Done.
| |
| 104 String contextId = baseContextId; | 99 if (server.contextMap.containsKey(contextId)) { |
| 105 int index = 1; | 100 return new Response.contextAlreadyExists(request); |
| 106 while (server.contextMap.containsKey(contextId)) { | |
| 107 contextId = '$baseContextId-$index'; | |
| 108 } | 101 } |
| 109 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); | 102 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); |
| 110 // TODO(brianwilkerson) Use the information from the request to set the | 103 // TODO(brianwilkerson) Use the information from the request to set the |
| 111 // source factory in the context. | 104 // source factory in the context. |
| 112 DirectoryBasedDartSdk sdk; | 105 DirectoryBasedDartSdk sdk; |
| 113 try { | 106 try { |
| 114 sdk = new DirectoryBasedDartSdk(new JavaFile(sdkDirectory)); | 107 sdk = new DirectoryBasedDartSdk(new JavaFile(sdkDirectory)); |
| 115 } on Exception catch (e) { | 108 } on Exception catch (e) { |
| 116 // TODO what error code should be returned here? | 109 // TODO what error code should be returned here? |
| 117 return new Response(request.id, new RequestError( | 110 return new Response(request.id, new RequestError( |
| 118 RequestError.CODE_SDK_ERROR, 'Failed to access sdk: $e')); | 111 RequestError.CODE_SDK_ERROR, 'Failed to access sdk: $e')); |
| 119 } | 112 } |
| 120 context.sourceFactory = new SourceFactory([ | 113 context.sourceFactory = new SourceFactory([ |
| 121 new DartUriResolver(sdk), | 114 new DartUriResolver(sdk), |
| 122 new FileUriResolver(), | 115 new FileUriResolver(), |
| 123 // new PackageUriResolver(), | 116 // new PackageUriResolver(), |
| 124 ]); | 117 ]); |
| 125 server.contextMap[contextId] = context; | 118 server.contextMap[contextId] = context; |
| 126 | 119 |
| 127 Response response = new Response(request.id); | 120 Response response = new Response(request.id); |
| 128 response.setResult(CONTEXT_ID_RESULT, contextId); | |
| 129 return response; | 121 return response; |
| 130 } | 122 } |
| 131 | 123 |
| 132 /** | 124 /** |
| 133 * Delete the context with the given id. Future attempts to use the context id | 125 * Delete the context with the given id. Future attempts to use the context id |
| 134 * will result in an error being returned. | 126 * will result in an error being returned. |
| 135 */ | 127 */ |
| 136 Response deleteContext(Request request) { | 128 Response deleteContext(Request request) { |
| 137 String contextId = request.getRequiredParameter(CONTEXT_ID_PARAM); | 129 String contextId = request.getRequiredParameter(CONTEXT_ID_PARAM); |
| 138 | 130 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 155 | 147 |
| 156 /** | 148 /** |
| 157 * Return the version number of the analysis server. | 149 * Return the version number of the analysis server. |
| 158 */ | 150 */ |
| 159 Response version(Request request) { | 151 Response version(Request request) { |
| 160 Response response = new Response(request.id); | 152 Response response = new Response(request.id); |
| 161 response.setResult(VERSION_RESULT, '0.0.1'); | 153 response.setResult(VERSION_RESULT, '0.0.1'); |
| 162 return response; | 154 return response; |
| 163 } | 155 } |
| 164 } | 156 } |
| OLD | NEW |