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

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

Issue 587783003: Replace AnalysisServerListener with Stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merges and fixes for comments Created 6 years, 3 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.execution; 5 library domain.execution;
6 6
7 import 'dart:async';
7 import 'dart:collection'; 8 import 'dart:collection';
8 9
9 import 'package:analysis_server/src/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/constants.dart'; 11 import 'package:analysis_server/src/constants.dart';
11 import 'package:analysis_server/src/protocol.dart'; 12 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/source.dart'; 14 import 'package:analyzer/src/generated/source.dart';
14 15
15 /** 16 /**
16 * Instances of the class [ExecutionDomainHandler] implement a [RequestHandler] 17 * Instances of the class [ExecutionDomainHandler] implement a [RequestHandler]
17 * that handles requests in the `execution` domain. 18 * that handles requests in the `execution` domain.
18 */ 19 */
19 class ExecutionDomainHandler implements RequestHandler { 20 class ExecutionDomainHandler implements RequestHandler {
20 /** 21 /**
21 * The analysis server that is using this handler to process requests. 22 * The analysis server that is using this handler to process requests.
22 */ 23 */
23 final AnalysisServer server; 24 final AnalysisServer server;
24 25
25 /** 26 /**
26 * The next execution context identifier to be returned. 27 * The next execution context identifier to be returned.
27 */ 28 */
28 int nextContextId = 0; 29 int nextContextId = 0;
29 30
30 /** 31 /**
31 * A table mapping execution context id's to the root of the context. 32 * A table mapping execution context id's to the root of the context.
32 */ 33 */
33 Map<String, String> contextMap = new HashMap<String, String>(); 34 Map<String, String> contextMap = new HashMap<String, String>();
34 35
35 /** 36 /**
36 * The listener used to send notifications when 37 * The subscription to the 'onAnalysisComplete' events,
38 * used to send notifications when
37 */ 39 */
38 LaunchDataNotificationListener launchDataListener; 40 StreamSubscription onAnalysisSubscription;
39 41
40 /** 42 /**
41 * Initialize a newly created handler to handle requests for the given [server ]. 43 * Initialize a newly created handler to handle requests for the given [server ].
42 */ 44 */
43 ExecutionDomainHandler(this.server); 45 ExecutionDomainHandler(this.server);
44 46
45 /** 47 /**
46 * Implement the `execution.createContext` request. 48 * Implement the `execution.createContext` request.
47 */ 49 */
48 Response createContext(Request request) { 50 Response createContext(Request request) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 'Either file or uri must be provided'); 119 'Either file or uri must be provided');
118 } 120 }
119 121
120 /** 122 /**
121 * Implement the 'execution.setSubscriptions' request. 123 * Implement the 'execution.setSubscriptions' request.
122 */ 124 */
123 Response setSubscriptions(Request request) { 125 Response setSubscriptions(Request request) {
124 List<ExecutionService> subscriptions = 126 List<ExecutionService> subscriptions =
125 new ExecutionSetSubscriptionsParams.fromRequest(request).subscriptions; 127 new ExecutionSetSubscriptionsParams.fromRequest(request).subscriptions;
126 if (subscriptions.contains(ExecutionService.LAUNCH_DATA)) { 128 if (subscriptions.contains(ExecutionService.LAUNCH_DATA)) {
127 if (launchDataListener == null) { 129 if (onAnalysisSubscription == null) {
128 launchDataListener = new LaunchDataNotificationListener(server); 130 onAnalysisSubscription =
129 server.addAnalysisServerListener(launchDataListener); 131 server.onAnalysisComplete.listen(_analysisComplete);
130 if (server.isAnalysisComplete()) { 132 if (server.isAnalysisComplete()) {
131 launchDataListener.analysisComplete(); 133 _analysisComplete(null);
132 } 134 }
133 } 135 }
134 } else { 136 } else {
135 if (launchDataListener != null) { 137 if (onAnalysisSubscription != null) {
136 server.removeAnalysisServerListener(launchDataListener); 138 onAnalysisSubscription.cancel();
137 launchDataListener = null; 139 onAnalysisSubscription = null;
138 } 140 }
139 } 141 }
140 return new ExecutionSetSubscriptionsResult().toResponse(request.id); 142 return new ExecutionSetSubscriptionsResult().toResponse(request.id);
141 } 143 }
142 }
143 144
144 /** 145 void _analysisComplete(_) {
145 * Instances of the class [LaunchDataNotificationListener] listen for analysis
146 * to be complete and then notify the client of the launch data that has been
147 * computed.
148 */
149 class LaunchDataNotificationListener implements AnalysisServerListener {
150 /**
151 * The analysis server used to send notifications.
152 */
153 final AnalysisServer server;
154
155 /**
156 * Initialize a newly created listener to send notifications through the given
157 * [server] when analysis is complete.
158 */
159 LaunchDataNotificationListener(this.server);
160
161 @override
162 void analysisComplete() {
163 List<ExecutableFile> executables = []; 146 List<ExecutableFile> executables = [];
164 Map<String, List<String>> dartToHtml = new HashMap<String, List<String>>(); 147 Map<String, List<String>> dartToHtml = new HashMap<String, List<String>>();
165 Map<String, List<String>> htmlToDart = new HashMap<String, List<String>>(); 148 Map<String, List<String>> htmlToDart = new HashMap<String, List<String>>();
166 for (AnalysisContext context in server.getAnalysisContexts()) { 149 for (AnalysisContext context in server.getAnalysisContexts()) {
167 List<Source> clientSources = context.launchableClientLibrarySources; 150 List<Source> clientSources = context.launchableClientLibrarySources;
168 List<Source> serverSources = context.launchableServerLibrarySources; 151 List<Source> serverSources = context.launchableServerLibrarySources;
169 for (Source source in clientSources) { 152 for (Source source in clientSources) {
170 ExecutableKind kind = ExecutableKind.CLIENT; 153 ExecutableKind kind = ExecutableKind.CLIENT;
171 if (serverSources.remove(source)) { 154 if (serverSources.remove(source)) {
172 kind = ExecutableKind.EITHER; 155 kind = ExecutableKind.EITHER;
173 } 156 }
174 executables.add(new ExecutableFile(source.fullName, kind)); 157 executables.add(new ExecutableFile(source.fullName, kind));
175 } 158 }
176 for (Source source in serverSources) { 159 for (Source source in serverSources) {
177 executables.add( 160 executables.add(
178 new ExecutableFile(source.fullName, ExecutableKind.SERVER)); 161 new ExecutableFile(source.fullName, ExecutableKind.SERVER));
179 } 162 }
180 163
181 for (Source librarySource in context.librarySources) { 164 for (Source librarySource in context.librarySources) {
182 List<Source> files = context.getHtmlFilesReferencing(librarySource); 165 List<Source> files = context.getHtmlFilesReferencing(librarySource);
183 if (files.isNotEmpty) { 166 if (files.isNotEmpty) {
184 // TODO(brianwilkerson) Handle the case where the same library is 167 // TODO(brianwilkerson) Handle the case where the same library is
185 // being analyzed in multiple contexts. 168 // being analyzed in multiple contexts.
186 dartToHtml[librarySource.fullName] = getFullNames(files); 169 dartToHtml[librarySource.fullName] = _getFullNames(files);
187 } 170 }
188 } 171 }
189 172
190 for (Source htmlSource in context.htmlSources) { 173 for (Source htmlSource in context.htmlSources) {
191 List<Source> libraries = 174 List<Source> libraries =
192 context.getLibrariesReferencedFromHtml(htmlSource); 175 context.getLibrariesReferencedFromHtml(htmlSource);
193 if (libraries.isNotEmpty) { 176 if (libraries.isNotEmpty) {
194 // TODO(brianwilkerson) Handle the case where the same HTML file is 177 // TODO(brianwilkerson) Handle the case where the same HTML file is
195 // being analyzed in multiple contexts. 178 // being analyzed in multiple contexts.
196 htmlToDart[htmlSource.fullName] = getFullNames(libraries); 179 htmlToDart[htmlSource.fullName] = _getFullNames(libraries);
197 } 180 }
198 } 181 }
199 } 182 }
200 server.sendNotification( 183 server.sendNotification(
201 new ExecutionLaunchDataParams( 184 new ExecutionLaunchDataParams(
202 executables, 185 executables,
203 dartToHtml, 186 dartToHtml,
204 htmlToDart).toNotification()); 187 htmlToDart).toNotification());
205 } 188 }
206 189
207 @override 190 static List<String> _getFullNames(List<Source> sources) {
208 void analysisStarted(AnalysisContext context) {
209 }
210
211 List<String> getFullNames(List<Source> sources) {
212 return sources.map((Source source) => source.fullName).toList(); 191 return sources.map((Source source) => source.fullName).toList();
213 } 192 }
214 } 193 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | pkg/analysis_server/lib/src/edit/edit_domain.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698