Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: pkg/analysis_server/lib/src/domain_server.dart

Issue 297153002: Implementation of 'Server Domain' in dart analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More fixes for comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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';
10 import 'package:analyzer/src/generated/java_io.dart';
11 import 'package:analyzer/src/generated/sdk_io.dart';
12 import 'package:analyzer/src/generated/source.dart';
13 import 'package:analyzer/src/generated/source_io.dart';
14 9
15 /** 10 /**
16 * Instances of the class [ServerDomainHandler] implement a [RequestHandler] 11 * Instances of the class [ServerDomainHandler] implement a [RequestHandler]
17 * that handles requests in the server domain. 12 * that handles requests in the server domain.
18 */ 13 */
19 class ServerDomainHandler implements RequestHandler { 14 class ServerDomainHandler implements RequestHandler {
20 /** 15 /**
21 * The name of the server.createContext request. 16 * The name of the `server.getVersion` request.
22 */ 17 */
23 static const String CREATE_CONTEXT_METHOD = 'server.createContext'; 18 static const String GET_VERSION_METHOD = 'server.getVersion';
24 19
25 /** 20 /**
26 * The name of the server.deleteContext request. 21 * The name of the `server.setSubscriptions` request.
27 */ 22 */
28 static const String DELETE_CONTEXT_METHOD = 'server.deleteContext'; 23 static const String SET_SUBSCRIPTIONS_METHOD = 'server.setSubscriptions';
29 24
30 /** 25 /**
31 * The name of the server.shutdown request. 26 * The name of the `server.shutdown` request.
32 */ 27 */
33 static const String SHUTDOWN_METHOD = 'server.shutdown'; 28 static const String SHUTDOWN_METHOD = 'server.shutdown';
34 29
35 /** 30 /**
36 * The name of the server.version request. 31 * The name of the `subscriptions` parameter.
37 */ 32 */
38 static const String VERSION_METHOD = 'server.version'; 33 static const String SUBSCRIPTIONS_PARAMETER = 'subscriptions';
39
40 /**
41 * The name of the packageMap parameter.
42 */
43 static const String PACKAGE_MAP_PARAM = 'packageMap';
44
45 /**
46 * The name of the sdkDirectory parameter.
47 */
48 static const String SDK_DIRECTORY_PARAM = 'sdkDirectory';
49 34
50 /** 35 /**
51 * The name of the version result value. 36 * The name of the version result value.
52 */ 37 */
53 static const String VERSION_RESULT = 'version'; 38 static const String VERSION_RESULT = 'version';
54 39
55 /** 40 /**
56 * The analysis server that is using this handler to process requests. 41 * The analysis server that is using this handler to process requests.
57 */ 42 */
58 final AnalysisServer server; 43 final AnalysisServer server;
59 44
60 /** 45 /**
61 * Initialize a newly created handler to handle requests for the given [server ]. 46 * Initialize a newly created handler to handle requests for the given [server ].
62 */ 47 */
63 ServerDomainHandler(this.server); 48 ServerDomainHandler(this.server);
64 49
65 @override 50 @override
66 Response handleRequest(Request request) { 51 Response handleRequest(Request request) {
67 try { 52 try {
68 String requestName = request.method; 53 String requestName = request.method;
69 if (requestName == CREATE_CONTEXT_METHOD) { 54 if (requestName == GET_VERSION_METHOD) {
70 return createContext(request); 55 return getVersion(request);
71 } else if (requestName == DELETE_CONTEXT_METHOD) { 56 } else if (requestName == SET_SUBSCRIPTIONS_METHOD) {
72 return deleteContext(request); 57 return setSubscriptions(request);
73 } else if (requestName == SHUTDOWN_METHOD) { 58 } else if (requestName == SHUTDOWN_METHOD) {
74 return shutdown(request); 59 return shutdown(request);
75 } else if (requestName == VERSION_METHOD) {
76 return version(request);
77 } 60 }
78 } on RequestFailure catch (exception) { 61 } on RequestFailure catch (exception) {
79 return exception.response; 62 return exception.response;
80 } 63 }
81 return null; 64 return null;
82 } 65 }
83 66
84 /** 67 /**
85 * Create a new context in which analysis can be performed. The context that 68 * Subscribe for services.
86 * is created will persist until server.deleteContext is used to delete it. 69 *
87 * Clients, therefore, are responsible for managing the lifetime of contexts. 70 * All previous subscriptions are replaced by the given set of subscriptions.
88 */ 71 */
89 Response createContext(Request request) { 72 Response setSubscriptions(Request request) {
90 String sdkDirectory = request.getRequiredParameter(SDK_DIRECTORY_PARAM).asSt ring(); 73 RequestDatum subDatum = request.getRequiredParameter(SUBSCRIPTIONS_PARAMETER );
91 Map<String, String> packageMap = request.getParameter(PACKAGE_MAP_PARAM, {}) .asStringMap(); 74 server.serverServices = subDatum.asEnumSet(ServerService.VALUES);
92 75 return new Response(request.id);
93 String contextId = request.getRequiredParameter(AnalysisServer.CONTEXT_ID_PA RAM).asString();
94 if (server.contextMap.containsKey(contextId)) {
95 return new Response.contextAlreadyExists(request);
96 }
97 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
98 // TODO(brianwilkerson) Use the information from the request to set the
99 // source factory in the context.
100 DirectoryBasedDartSdk sdk;
101 try {
102 sdk = new DirectoryBasedDartSdk(new JavaFile(sdkDirectory));
103 } on Exception catch (e) {
104 // TODO what error code should be returned here?
105 return new Response(request.id, new RequestError(
106 RequestError.CODE_SDK_ERROR, 'Failed to access sdk: $e'));
107 }
108 context.sourceFactory = new SourceFactory([
109 new DartUriResolver(sdk),
110 new FileUriResolver(),
111 // new PackageUriResolver(),
112 ]);
113 server.contextMap[contextId] = context;
114 server.contextIdMap[context] = contextId;
115
116 Response response = new Response(request.id);
117 return response;
118 } 76 }
119 77
120 /** 78 // TODO(scheglov) remove or move to the 'analysis' domain
121 * Delete the context with the given id. Future attempts to use the context id 79 // /**
122 * will result in an error being returned. 80 // * Create a new context in which analysis can be performed. The context that
123 */ 81 // * is created will persist until server.deleteContext is used to delete it.
124 Response deleteContext(Request request) { 82 // * Clients, therefore, are responsible for managing the lifetime of contexts .
125 String contextId = request.getRequiredParameter(AnalysisServer.CONTEXT_ID_PA RAM).asString(); 83 // */
126 84 // Response createContext(Request request) {
127 AnalysisContext removedContext = server.contextMap.remove(contextId); 85 // String sdkDirectory = request.getRequiredParameter(SDK_DIRECTORY_PARAM).as String();
128 if (removedContext == null) { 86 // Map<String, String> packageMap = request.getParameter(PACKAGE_MAP_PARAM, { }).asStringMap();
129 return new Response.contextDoesNotExist(request); 87 //
130 } 88 // String contextId = request.getRequiredParameter(AnalysisServer.CONTEXT_ID_ PARAM).asString();
131 server.contextIdMap.remove(removedContext); 89 // if (server.contextMap.containsKey(contextId)) {
132 Response response = new Response(request.id); 90 // return new Response.contextAlreadyExists(request);
133 return response; 91 // }
134 } 92 // AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
93 // // TODO(brianwilkerson) Use the information from the request to set the
94 // // source factory in the context.
95 // DirectoryBasedDartSdk sdk;
96 // try {
97 // sdk = new DirectoryBasedDartSdk(new JavaFile(sdkDirectory));
98 // } on Exception catch (e) {
99 // // TODO what error code should be returned here?
100 // return new Response(request.id, new RequestError(
101 // RequestError.CODE_SDK_ERROR, 'Failed to access sdk: $e'));
102 // }
103 // context.sourceFactory = new SourceFactory([
104 // new DartUriResolver(sdk),
105 // new FileUriResolver(),
106 // // new PackageUriResolver(),
107 // ]);
108 // server.contextMap[contextId] = context;
109 // server.contextIdMap[context] = contextId;
110 //
111 // Response response = new Response(request.id);
112 // return response;
113 // }
114 //
115 // /**
116 // * Delete the context with the given id. Future attempts to use the context id
117 // * will result in an error being returned.
118 // */
119 // Response deleteContext(Request request) {
120 // String contextId = request.getRequiredParameter(AnalysisServer.CONTEXT_ID_ PARAM).asString();
121 //
122 // AnalysisContext removedContext = server.contextMap.remove(contextId);
123 // if (removedContext == null) {
124 // return new Response.contextDoesNotExist(request);
125 // }
126 // server.contextIdMap.remove(removedContext);
127 // Response response = new Response(request.id);
128 // return response;
129 // }
135 130
136 /** 131 /**
137 * Cleanly shutdown the analysis server. 132 * Cleanly shutdown the analysis server.
138 */ 133 */
139 Response shutdown(Request request) { 134 Response shutdown(Request request) {
140 server.running = false; 135 server.running = false;
141 Response response = new Response(request.id); 136 Response response = new Response(request.id);
142 return response; 137 return response;
143 } 138 }
144 139
145 /** 140 /**
146 * Return the version number of the analysis server. 141 * Return the version number of the analysis server.
147 */ 142 */
148 Response version(Request request) { 143 Response getVersion(Request request) {
149 Response response = new Response(request.id); 144 Response response = new Response(request.id);
150 response.setResult(VERSION_RESULT, '0.0.1'); 145 response.setResult(VERSION_RESULT, '0.0.1');
151 return response; 146 return response;
152 } 147 }
153 } 148 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/lib/src/protocol.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698