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

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

Issue 417433003: Send responses for any pending 'analysis.getErrors' requests during context removal. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext(); 49 AnalysisContext context = AnalysisEngine.instance.createAnalysisContext();
50 analysisServer.folderMap[folder] = context; 50 analysisServer.folderMap[folder] = context;
51 context.sourceFactory = _createSourceFactory(packageMap); 51 context.sourceFactory = _createSourceFactory(packageMap);
52 context.analysisOptions = new AnalysisOptionsImpl.con1(defaultOptions); 52 context.analysisOptions = new AnalysisOptionsImpl.con1(defaultOptions);
53 analysisServer.schedulePerformAnalysisOperation(context); 53 analysisServer.schedulePerformAnalysisOperation(context);
54 } 54 }
55 55
56 @override 56 @override
57 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { 57 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) {
58 AnalysisContext context = analysisServer.folderMap[contextFolder]; 58 AnalysisContext context = analysisServer.folderMap[contextFolder];
59 context.applyChanges(changeSet); 59 if (context != null) {
Paul Berry 2014/07/23 15:06:51 This check shouldn't be necessary. The caller wil
scheglov 2014/07/24 16:54:04 We need this in case if "folder removed" watch eve
Paul Berry 2014/07/24 17:32:04 I believe this won't ever happen in production cod
60 analysisServer.schedulePerformAnalysisOperation(context); 60 context.applyChanges(changeSet);
61 analysisServer.schedulePerformAnalysisOperation(context);
62 }
61 } 63 }
62 64
63 @override 65 @override
64 void removeContext(Folder folder) { 66 void removeContext(Folder folder) {
65 analysisServer.folderMap.remove(folder); 67 AnalysisContext context = analysisServer.folderMap.remove(folder);
68 if (context != null) {
Paul Berry 2014/07/23 15:06:51 Similar situation with this check.
scheglov 2014/07/24 16:54:03 OK I think we can trust watcher that it won't tel
69 analysisServer.sendContextAnalysisCancelledNotifications(
70 context,
71 'Context was removed');
72 }
66 } 73 }
67 74
68 @override 75 @override
69 void updateContextPackageMap(Folder contextFolder, 76 void updateContextPackageMap(Folder contextFolder,
70 Map<String, List<Folder>> packageMap) { 77 Map<String, List<Folder>> packageMap) {
71 AnalysisContext context = analysisServer.folderMap[contextFolder]; 78 AnalysisContext context = analysisServer.folderMap[contextFolder];
72 context.sourceFactory = _createSourceFactory(packageMap); 79 context.sourceFactory = _createSourceFactory(packageMap);
73 analysisServer.schedulePerformAnalysisOperation(context); 80 analysisServer.schedulePerformAnalysisOperation(context);
74 } 81 }
75 82
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // if library has not been resolved yet, the unit will be resolved later 572 // if library has not been resolved yet, the unit will be resolved later
566 Source librarySource = librarySources[0]; 573 Source librarySource = librarySources[0];
567 if (context.getLibraryElement(librarySource) == null) { 574 if (context.getLibraryElement(librarySource) == null) {
568 return null; 575 return null;
569 } 576 }
570 // if library has been already resolved, resolve unit 577 // if library has been already resolved, resolve unit
571 return context.resolveCompilationUnit2(unitSource, librarySource); 578 return context.resolveCompilationUnit2(unitSource, librarySource);
572 } 579 }
573 580
574 /** 581 /**
575 * Returns all the [AnalysisErrorInfo] for [file]. 582 * Return an analysis error info containing the array of all of the errors and
576 * It does not wait for all errors to be computed, and returns just the 583 * the line info associated with [file].
577 * current state.
578 * 584 *
579 * May return `null`. 585 * Returns `null` if [file] does not belong to any [AnalysisContext].
586 *
587 * The array of errors will be empty if [file] does not exist or if there are
588 * no errors in [file]. The errors contained in the array can be incomplete.
589 *
590 * This method does not wait for all errors to be computed, and returns just
591 * the current state.
580 */ 592 */
581 AnalysisErrorInfo getErrors(String file) { 593 AnalysisErrorInfo getErrors(String file) {
582 // prepare AnalysisContext 594 // prepare AnalysisContext
583 AnalysisContext context = getAnalysisContext(file); 595 AnalysisContext context = getAnalysisContext(file);
584 if (context == null) { 596 if (context == null) {
585 return null; 597 return null;
586 } 598 }
587 // get errors for the file 599 // get errors for the file
588 Source source = getSource(file); 600 Source source = getSource(file);
589 return context.getErrors(source); 601 return context.getErrors(source);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 /** 648 /**
637 * Returns a [Future] completing when [file] has been completely analyzed, in 649 * Returns a [Future] completing when [file] has been completely analyzed, in
638 * particular, all its errors have been computed. 650 * particular, all its errors have been computed.
639 * 651 *
640 * TODO(scheglov) this method should be improved. 652 * TODO(scheglov) this method should be improved.
641 * 653 *
642 * 1. The analysis context should be told to analyze this particular file ASAP . 654 * 1. The analysis context should be told to analyze this particular file ASAP .
643 * 655 *
644 * 2. We should complete the future as soon as the file is analyzed (not wait 656 * 2. We should complete the future as soon as the file is analyzed (not wait
645 * until the context is completely finished) 657 * until the context is completely finished)
646 *
647 * 3. Since contexts can be created and deleted asynchronously as a result of
648 * changes to the filesystem, there's a danger that the future might never
649 * get completed. We should add a mechanism to make sure that we return an
650 * error for any getErrors request that is unsatisfiable due to its context
651 * being deleted.
652 */ 658 */
653 Future onFileAnalysisComplete(String file) { 659 Future onFileAnalysisComplete(String file) {
654 // prepare AnalysisContext 660 // prepare AnalysisContext
655 AnalysisContext context = getAnalysisContext(file); 661 AnalysisContext context = getAnalysisContext(file);
656 if (context == null) { 662 if (context == null) {
657 return new Future.value(); 663 return new Future.value();
658 } 664 }
659 // schedule context analysis 665 // schedule context analysis
660 schedulePerformAnalysisOperation(context); 666 schedulePerformAnalysisOperation(context);
661 // associate with the context completer 667 // associate with the context completer
662 Completer completer = contextAnalysisDoneCompleters[context]; 668 Completer completer = contextAnalysisDoneCompleters[context];
663 if (completer == null) { 669 if (completer == null) {
664 completer = new Completer(); 670 completer = new Completer();
665 contextAnalysisDoneCompleters[context] = completer; 671 contextAnalysisDoneCompleters[context] = completer;
666 } 672 }
667 return completer.future; 673 return completer.future;
668 } 674 }
669 675
670 /** 676 /**
671 * This method is called when analysis of the given [AnalysisContext] is 677 * This method is called when analysis of the given [AnalysisContext] is
672 * done. 678 * done.
673 */ 679 */
674 void sendContextAnalysisDoneNotifications(AnalysisContext context) { 680 void sendContextAnalysisDoneNotifications(AnalysisContext context) {
675 Completer completer = contextAnalysisDoneCompleters[context]; 681 Completer completer = contextAnalysisDoneCompleters.remove(context);
676 if (completer != null) { 682 if (completer != null) {
677 completer.complete(); 683 completer.complete();
678 } 684 }
679 } 685 }
680 686
681 /** 687 /**
688 * This method is called when analysis of the given [AnalysisContext] is
689 * cancelled.
690 */
691 void sendContextAnalysisCancelledNotifications(AnalysisContext context, String message) {
692 Completer completer = contextAnalysisDoneCompleters.remove(context);
693 if (completer != null) {
694 completer.completeError(message);
695 }
696 }
697
698 /**
682 * Return the [CompilationUnit] of the Dart file with the given [path]. 699 * Return the [CompilationUnit] of the Dart file with the given [path].
683 * Return `null` if the file is not a part of any context. 700 * Return `null` if the file is not a part of any context.
684 */ 701 */
685 CompilationUnit test_getResolvedCompilationUnit(String path) { 702 CompilationUnit test_getResolvedCompilationUnit(String path) {
686 // prepare AnalysisContext 703 // prepare AnalysisContext
687 AnalysisContext context = getAnalysisContext(path); 704 AnalysisContext context = getAnalysisContext(path);
688 if (context == null) { 705 if (context == null) {
689 return null; 706 return null;
690 } 707 }
691 // prepare sources 708 // prepare sources
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 /** 754 /**
738 * An enumeration of the services provided by the server domain. 755 * An enumeration of the services provided by the server domain.
739 */ 756 */
740 class ServerService extends Enum2<ServerService> { 757 class ServerService extends Enum2<ServerService> {
741 static const ServerService STATUS = const ServerService('STATUS', 0); 758 static const ServerService STATUS = const ServerService('STATUS', 0);
742 759
743 static const List<ServerService> VALUES = const [STATUS]; 760 static const List<ServerService> VALUES = const [STATUS];
744 761
745 const ServerService(String name, int ordinal) : super(name, ordinal); 762 const ServerService(String name, int ordinal) : super(name, ordinal);
746 } 763 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/domain_analysis.dart » ('j') | pkg/analysis_server/lib/src/domain_analysis.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698