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

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

Issue 307533004: Send 'notification.errors' for all non-SDK files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 analysis.server; 5 library analysis.server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_logger.dart'; 9 import 'package:analysis_server/src/analysis_logger.dart';
10 import 'package:analysis_server/src/channel.dart'; 10 import 'package:analysis_server/src/channel.dart';
11 import 'package:analysis_server/src/domain_analysis.dart';
11 import 'package:analysis_server/src/protocol.dart'; 12 import 'package:analysis_server/src/protocol.dart';
12 import 'package:analysis_server/src/resource.dart'; 13 import 'package:analysis_server/src/resource.dart';
13 import 'package:analyzer/src/generated/ast.dart'; 14 import 'package:analyzer/src/generated/ast.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 15 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/error.dart'; 16 import 'package:analyzer/src/generated/error.dart';
16 import 'package:analyzer/src/generated/java_core.dart'; 17 import 'package:analyzer/src/generated/java_core.dart';
17 import 'package:analyzer/src/generated/sdk.dart'; 18 import 'package:analyzer/src/generated/sdk.dart';
18 import 'package:analyzer/src/generated/sdk_io.dart'; 19 import 'package:analyzer/src/generated/sdk_io.dart';
19 import 'package:analyzer/src/generated/source_io.dart'; 20 import 'package:analyzer/src/generated/source_io.dart';
20 21
22
23 /**
24 * An instance of [DirectoryBasedDartSdk] that is shared between
25 * [AnalysisServer] instances to improve performance.
26 */
27 final DirectoryBasedDartSdk SHARED_SDK = DirectoryBasedDartSdk.defaultSdk;
28
21 /** 29 /**
22 * Instances of the class [AnalysisServer] implement a server that listens on a 30 * Instances of the class [AnalysisServer] implement a server that listens on a
23 * [CommunicationChannel] for analysis requests and process them. 31 * [CommunicationChannel] for analysis requests and process them.
24 */ 32 */
25 class AnalysisServer { 33 class AnalysisServer {
26 /** 34 /**
27 * The name of the notification of new errors associated with a source.
28 */
29 static const String ERROR_NOTIFICATION_NAME = 'context.errors';
30
31 /**
32 * The name of the contextId parameter.
33 */
34 static const String CONTEXT_ID_PARAM = 'contextId';
35
36 /**
37 * The name of the parameter whose value is a list of errors. 35 * The name of the parameter whose value is a list of errors.
38 */ 36 */
39 static const String ERRORS_PARAM = 'errors'; 37 static const String ERRORS_PARAM = 'errors';
40 38
41 /** 39 /**
42 * The name of the parameter whose value is a source. 40 * The name of the parameter whose value is a file path.
43 */ 41 */
44 static const String SOURCE_PARAM = 'source'; 42 static const String FILE_PARAM = 'file';
45 43
46 /** 44 /**
47 * The event name of the connected notification. 45 * The event name of the connected notification.
48 */ 46 */
49 static const String CONNECTED_NOTIFICATION = 'server.connected'; 47 static const String CONNECTED_NOTIFICATION = 'server.connected';
50 48
51 /** 49 /**
52 * The channel from which requests are received and to which responses should 50 * The channel from which requests are received and to which responses should
53 * be sent. 51 * be sent.
54 */ 52 */
(...skipping 24 matching lines...) Expand all
79 // final Map<String, AnalysisContext> contextMap = new Map<String, AnalysisCont ext>(); 77 // final Map<String, AnalysisContext> contextMap = new Map<String, AnalysisCont ext>();
80 // 78 //
81 // /** 79 // /**
82 // * A table mapping analysis contexts to the context id's associated with the m. 80 // * A table mapping analysis contexts to the context id's associated with the m.
83 // */ 81 // */
84 // final Map<AnalysisContext, String> contextIdMap = new Map<AnalysisContext, S tring>(); 82 // final Map<AnalysisContext, String> contextIdMap = new Map<AnalysisContext, S tring>();
85 83
86 /** 84 /**
87 * The current default [DartSdk]. 85 * The current default [DartSdk].
88 */ 86 */
89 DartSdk defaultSdk = DirectoryBasedDartSdk.defaultSdk; 87 DartSdk defaultSdk = SHARED_SDK;
Brian Wilkerson 2014/05/28 14:25:21 For discussion: I'm not sure this is the behavior
scheglov 2014/05/28 15:46:37 I agree. This API is just not implemented yet.
90 88
91 /** 89 /**
92 * A table mapping [Folder]s to the [PubFolder]s associated with them. 90 * A table mapping [Folder]s to the [PubFolder]s associated with them.
93 */ 91 */
94 final Map<Folder, PubFolder> folderMap = <Folder, PubFolder>{}; 92 final Map<Folder, PubFolder> folderMap = <Folder, PubFolder>{};
95 93
96 /** 94 /**
97 * A list of the analysis contexts for which analysis work needs to be 95 * A list of the analysis contexts for which analysis work needs to be
98 * performed. 96 * performed.
99 * 97 *
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 contextWorkQueue.removeAt(0); 206 contextWorkQueue.removeAt(0);
209 } 207 }
210 // 208 //
211 // Schedule this method to be run again if there is any more work to be 209 // Schedule this method to be run again if there is any more work to be
212 // done. 210 // done.
213 // 211 //
214 if (!contextWorkQueue.isEmpty) { 212 if (!contextWorkQueue.isEmpty) {
215 _scheduleTask(); 213 _scheduleTask();
216 } 214 }
217 } 215 }
218 // TODO(scheglov) implement for [PubFolder] 216 if (notices != null) {
219 // if (notices != null) { 217 sendNotices(notices);
220 // sendNotices(contextId, notices); 218 }
221 // }
222 } 219 }
223 220
224 // TODO(scheglov) rewrite for the new API. 221 /**
225 // /** 222 * Send the information in the given list of notices back to the client.
226 // * Send the information in the given list of notices back to the client. 223 */
227 // */ 224 void sendNotices(List<ChangeNotice> notices) {
228 // void sendNotices(String contextId, List<ChangeNotice> notices) { 225 for (int i = 0; i < notices.length; i++) {
229 // for (int i = 0; i < notices.length; i++) { 226 ChangeNotice notice = notices[i];
230 // ChangeNotice notice = notices[i]; 227 Source source = notice.source;
231 // Notification notification = new Notification(ERROR_NOTIFICATION_NAME); 228 // send "analysis.errors" notification
232 // notification.setParameter(CONTEXT_ID_PARAM, contextId); 229 // TODO(scheglov) use subscriptions to determine if we should do this
233 // notification.setParameter(SOURCE_PARAM, notice.source.encoding); 230 if (!source.isInSystemLibrary) {
234 // notification.setParameter(ERRORS_PARAM, notice.errors.map( 231 Notification notification = new Notification(AnalysisDomainHandler.ERROR S_NOTIFICATION);
235 // errorToJson).toList()); 232 notification.setParameter(FILE_PARAM, source.fullName);
236 // sendNotification(notification); 233 notification.setParameter(ERRORS_PARAM, notice.errors.map(errorToJson).t oList());
237 // } 234 sendNotification(notification);
238 // } 235 }
236 }
237 }
239 238
240 /** 239 /**
241 * Implementation for `server.setAnalysisRoots`. 240 * Implementation for `server.setAnalysisRoots`.
242 * 241 *
243 * TODO(scheglov) implement complete projects/contexts semantics. 242 * TODO(scheglov) implement complete projects/contexts semantics.
244 * 243 *
245 * The current implementation is intentionally simplified and expected 244 * The current implementation is intentionally simplified and expected
246 * that only folders are given each given folder corresponds to the exactly 245 * that only folders are given each given folder corresponds to the exactly
247 * one context. 246 * one context.
248 * 247 *
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 File file = resourceProvider.getResource(path); 319 File file = resourceProvider.getResource(path);
321 Source unitSource = file.createSource(UriKind.FILE_URI); 320 Source unitSource = file.createSource(UriKind.FILE_URI);
322 List<Source> librarySources = context.getLibrariesContaining(unitSource); 321 List<Source> librarySources = context.getLibrariesContaining(unitSource);
323 if (librarySources.isEmpty) { 322 if (librarySources.isEmpty) {
324 return null; 323 return null;
325 } 324 }
326 // get a resolved unit 325 // get a resolved unit
327 return context.getResolvedCompilationUnit2(unitSource, librarySources[0]); 326 return context.getResolvedCompilationUnit2(unitSource, librarySources[0]);
328 } 327 }
329 328
329 /**
330 * Return `true` if all tasks are finished in this [AnalysisServer].
331 */
332 bool test_areTasksFinished() {
333 return contextWorkQueue.isEmpty;
334 }
335
330 static Map<String, Object> errorToJson(AnalysisError analysisError) { 336 static Map<String, Object> errorToJson(AnalysisError analysisError) {
331 // TODO(paulberry): move this function into the AnalysisError class. 337 // TODO(paulberry): move this function into the AnalysisError class.
332 338 ErrorCode errorCode = analysisError.errorCode;
333 // TODO(paulberry): we really shouldn't be exposing errorCode.ordinal
334 // outside the analyzer, since the ordinal numbers change whenever we
335 // regenerate the analysis engine.
336 Map<String, Object> result = { 339 Map<String, Object> result = {
337 'source': analysisError.source.encoding, 340 'file': analysisError.source.fullName,
Brian Wilkerson 2014/05/28 14:25:21 These strings should be constants.
scheglov 2014/05/28 15:46:37 Will extract them in a separate CL.
338 'errorCode': (analysisError.errorCode as Enum).ordinal, 341 // TODO(scheglov) add Enum.fullName ?
342 'errorCode': '${errorCode.runtimeType}.${(errorCode as Enum).name}',
339 'offset': analysisError.offset, 343 'offset': analysisError.offset,
340 'length': analysisError.length, 344 'length': analysisError.length,
341 'message': analysisError.message 345 'message': analysisError.message
342 }; 346 };
343 if (analysisError.correction != null) { 347 if (analysisError.correction != null) {
344 result['correction'] = analysisError.correction; 348 result['correction'] = analysisError.correction;
345 } 349 }
346 return result; 350 return result;
347 } 351 }
348 352
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 /** 457 /**
454 * An enumeration of the services provided by the server domain. 458 * An enumeration of the services provided by the server domain.
455 */ 459 */
456 class ServerService extends Enum2<ServerService> { 460 class ServerService extends Enum2<ServerService> {
457 static const ServerService STATUS = const ServerService('STATUS', 0); 461 static const ServerService STATUS = const ServerService('STATUS', 0);
458 462
459 static const List<ServerService> VALUES = const [STATUS]; 463 static const List<ServerService> VALUES = const [STATUS];
460 464
461 const ServerService(String name, int ordinal) : super(name, ordinal); 465 const ServerService(String name, int ordinal) : super(name, ordinal);
462 } 466 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis_server_test.dart » ('j') | pkg/analysis_server/test/domain_analysis_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698