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

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

Issue 339933006: Fix for subscribing for notifications after analysis. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweaks for review comments Created 6 years, 6 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis_notification_navigation_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/analysis_logger.dart'; 10 import 'package:analysis_server/src/analysis_logger.dart';
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 subscriptions.forEach((service, Set<String> newFiles) { 391 subscriptions.forEach((service, Set<String> newFiles) {
392 Set<String> oldFiles = analysisServices[service]; 392 Set<String> oldFiles = analysisServices[service];
393 Set<String> todoFiles = oldFiles != null ? newFiles.difference(oldFiles) : newFiles; 393 Set<String> todoFiles = oldFiles != null ? newFiles.difference(oldFiles) : newFiles;
394 for (String file in todoFiles) { 394 for (String file in todoFiles) {
395 if (service == AnalysisService.ERRORS) { 395 if (service == AnalysisService.ERRORS) {
396 Source source = _getSource(file); 396 Source source = _getSource(file);
397 AnalysisContext analysisContext = _getAnalysisContext(file); 397 AnalysisContext analysisContext = _getAnalysisContext(file);
398 List<AnalysisError> errors = analysisContext.getErrors(source).errors; 398 List<AnalysisError> errors = analysisContext.getErrors(source).errors;
399 sendAnalysisNotificationErrors(this, file, errors); 399 sendAnalysisNotificationErrors(this, file, errors);
400 } 400 }
401 // TODO(scheglov) 401 // Dart unit notifications.
402 // 1. implement resolveCompilationUnit() 402 if (AnalysisEngine.isDartFileName(file)) {
403 // 2. Share "if (dartUnit != null)" 403 CompilationUnit dartUnit = getResolvedCompilationUnitToResendNotificat ion(file);
404 if (service == AnalysisService.HIGHLIGHTS) {
405 CompilationUnit dartUnit = test_getResolvedCompilationUnit(file);
406 if (dartUnit != null) { 404 if (dartUnit != null) {
407 sendAnalysisNotificationHighlights(this, file, dartUnit); 405 switch (service) {
408 } 406 case AnalysisService.HIGHLIGHTS:
409 } 407 sendAnalysisNotificationHighlights(this, file, dartUnit);
410 if (service == AnalysisService.NAVIGATION) { 408 break;
411 CompilationUnit dartUnit = test_getResolvedCompilationUnit(file); 409 case AnalysisService.NAVIGATION:
412 if (dartUnit != null) { 410 // TODO(scheglov) consider support for one unit in 2+ libraries
413 sendAnalysisNotificationNavigation(this, file, dartUnit); 411 sendAnalysisNotificationNavigation(this, file, dartUnit);
414 } 412 break;
415 } 413 case AnalysisService.OUTLINE:
416 if (service == AnalysisService.OUTLINE) { 414 sendAnalysisNotificationOutline(this, file, dartUnit);
417 CompilationUnit dartUnit = test_getResolvedCompilationUnit(file); 415 break;
418 if (dartUnit != null) { 416 }
419 sendAnalysisNotificationOutline(this, file, dartUnit);
420 } 417 }
421 } 418 }
422 } 419 }
423 }); 420 });
424 // remember new subscriptions 421 // remember new subscriptions
425 this.analysisServices = subscriptions; 422 this.analysisServices = subscriptions;
426 } 423 }
427 424
428 /** 425 /**
429 * Return the [AnalysisContext] that is used to analyze the given [path]. 426 * Return the [AnalysisContext] that is used to analyze the given [path].
(...skipping 10 matching lines...) Expand all
440 437
441 /** 438 /**
442 * Return the [Source] of the Dart file with the given [path]. 439 * Return the [Source] of the Dart file with the given [path].
443 */ 440 */
444 Source _getSource(String path) { 441 Source _getSource(String path) {
445 File file = contextDirectoryManager.resourceProvider.getResource(path); 442 File file = contextDirectoryManager.resourceProvider.getResource(path);
446 return file.createSource(UriKind.FILE_URI); 443 return file.createSource(UriKind.FILE_URI);
447 } 444 }
448 445
449 /** 446 /**
447 * Returns the [CompilationUnit] of the Dart file with the given [path] that
448 * should be used to resend notifications for already resolved unit.
449 * Returns `null` if the file is not a part of any context, library has not
450 * been yet resolved, or any problem happened.
451 */
452 CompilationUnit getResolvedCompilationUnitToResendNotification(String path) {
453 // prepare AnalysisContext
454 AnalysisContext context = _getAnalysisContext(path);
455 if (context == null) {
456 return null;
457 }
458 // prepare sources
459 Source unitSource = _getSource(path);
460 List<Source> librarySources = context.getLibrariesContaining(unitSource);
461 if (librarySources.isEmpty) {
462 return null;
463 }
464 // if library has not been resolved yet, the unit will be resolved later
465 Source librarySource = librarySources[0];
466 if (context.getLibraryElement(librarySource) == null) {
467 return null;
468 }
469 // if library has been already resolved, resolve unit
470 return context.resolveCompilationUnit2(unitSource, librarySource);
471 }
472
473 /**
450 * Return the [CompilationUnit] of the Dart file with the given [path]. 474 * Return the [CompilationUnit] of the Dart file with the given [path].
451 * Return `null` if the file is not a part of any context. 475 * Return `null` if the file is not a part of any context.
452 */ 476 */
453 CompilationUnit test_getResolvedCompilationUnit(String path) { 477 CompilationUnit test_getResolvedCompilationUnit(String path) {
454 // prepare AnalysisContext 478 // prepare AnalysisContext
455 AnalysisContext context = _getAnalysisContext(path); 479 AnalysisContext context = _getAnalysisContext(path);
456 if (context == null) { 480 if (context == null) {
457 return null; 481 return null;
458 } 482 }
459 // prepare sources 483 // prepare sources
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 /** 602 /**
579 * An enumeration of the services provided by the server domain. 603 * An enumeration of the services provided by the server domain.
580 */ 604 */
581 class ServerService extends Enum2<ServerService> { 605 class ServerService extends Enum2<ServerService> {
582 static const ServerService STATUS = const ServerService('STATUS', 0); 606 static const ServerService STATUS = const ServerService('STATUS', 0);
583 607
584 static const List<ServerService> VALUES = const [STATUS]; 608 static const List<ServerService> VALUES = const [STATUS];
585 609
586 const ServerService(String name, int ordinal) : super(name, ordinal); 610 const ServerService(String name, int ordinal) : super(name, ordinal);
587 } 611 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis_notification_navigation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698