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

Side by Side Diff: pkg/analysis_server/test/services/completion/completion_computer_test.dart

Issue 800723002: Allow completions to wait for analysis without requiring a busy wait loop. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 test.services.completion.suggestion; 5 library test.services.completion.suggestion;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_server/src/services/completion/completion_manager.dart' ; 10 import 'package:analysis_server/src/services/completion/completion_manager.dart' ;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 class DartCompletionManagerTest extends AbstractSingleUnitTest { 43 class DartCompletionManagerTest extends AbstractSingleUnitTest {
44 Index index; 44 Index index;
45 SearchEngineImpl searchEngine; 45 SearchEngineImpl searchEngine;
46 Source source; 46 Source source;
47 CompletionPerformance perf; 47 CompletionPerformance perf;
48 DartCompletionManager manager; 48 DartCompletionManager manager;
49 MockCompletionComputer computer1; 49 MockCompletionComputer computer1;
50 MockCompletionComputer computer2; 50 MockCompletionComputer computer2;
51 CompletionSuggestion suggestion1; 51 CompletionSuggestion suggestion1;
52 CompletionSuggestion suggestion2; 52 CompletionSuggestion suggestion2;
53 bool _continuePerformingAnalysis = true;
53 54
54 void resolveLibrary() { 55 void resolveLibrary() {
55 context.resolveCompilationUnit( 56 context.resolveCompilationUnit(
56 source, 57 source,
57 context.computeLibraryElement(source)); 58 context.computeLibraryElement(source));
58 } 59 }
59 60
60 @override 61 @override
61 void setUp() { 62 void setUp() {
62 super.setUp(); 63 super.setUp();
(...skipping 11 matching lines...) Expand all
74 false, 75 false,
75 false); 76 false);
76 suggestion2 = new CompletionSuggestion( 77 suggestion2 = new CompletionSuggestion(
77 CompletionSuggestionKind.IDENTIFIER, 78 CompletionSuggestionKind.IDENTIFIER,
78 CompletionRelevance.DEFAULT, 79 CompletionRelevance.DEFAULT,
79 "suggestion2", 80 "suggestion2",
80 2, 81 2,
81 2, 82 2,
82 false, 83 false,
83 false); 84 false);
85 new Future(_performAnalysis);
86 }
87
88 @override
89 void tearDown() {
90 _continuePerformingAnalysis = false;
84 } 91 }
85 92
86 test_compute_fastAndFull() { 93 test_compute_fastAndFull() {
87 computer1 = new MockCompletionComputer(suggestion1, null); 94 computer1 = new MockCompletionComputer(suggestion1, null);
88 computer2 = new MockCompletionComputer(null, suggestion2); 95 computer2 = new MockCompletionComputer(null, suggestion2);
89 manager.computers = [computer1, computer2]; 96 manager.computers = [computer1, computer2];
90 int count = 0; 97 int count = 0;
91 bool done = false; 98 bool done = false;
92 CompletionRequest completionRequest = new CompletionRequest(0, perf); 99 CompletionRequest completionRequest = new CompletionRequest(0, perf);
93 manager.results(completionRequest).listen((CompletionResult r) { 100 manager.results(completionRequest).listen((CompletionResult r) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 fail('unexpected'); 148 fail('unexpected');
142 } 149 }
143 }, onDone: () { 150 }, onDone: () {
144 done = true; 151 done = true;
145 expect(count, equals(1)); 152 expect(count, equals(1));
146 }); 153 });
147 return pumpEventQueue().then((_) { 154 return pumpEventQueue().then((_) {
148 expect(done, isTrue); 155 expect(done, isTrue);
149 }); 156 });
150 } 157 }
158
159 void _performAnalysis() {
160 if (!_continuePerformingAnalysis) {
161 return;
162 }
163 context.performAnalysisTask();
164 new Future(_performAnalysis);
165 }
151 } 166 }
152 167
153 class MockCompletionComputer extends DartCompletionComputer { 168 class MockCompletionComputer extends DartCompletionComputer {
154 final CompletionSuggestion fastSuggestion; 169 final CompletionSuggestion fastSuggestion;
155 final CompletionSuggestion fullSuggestion; 170 final CompletionSuggestion fullSuggestion;
156 int fastCount = 0; 171 int fastCount = 0;
157 int fullCount = 0; 172 int fullCount = 0;
158 DartCompletionRequest request; 173 DartCompletionRequest request;
159 174
160 MockCompletionComputer(this.fastSuggestion, this.fullSuggestion); 175 MockCompletionComputer(this.fastSuggestion, this.fullSuggestion);
(...skipping 26 matching lines...) Expand all
187 @override 202 @override
188 Future<bool> computeFull(DartCompletionRequest request) { 203 Future<bool> computeFull(DartCompletionRequest request) {
189 this.request = request; 204 this.request = request;
190 fullCount++; 205 fullCount++;
191 if (fullSuggestion != null) { 206 if (fullSuggestion != null) {
192 request.suggestions.add(fullSuggestion); 207 request.suggestions.add(fullSuggestion);
193 } 208 }
194 return new Future.value(fullSuggestion != null); 209 return new Future.value(fullSuggestion != null);
195 } 210 }
196 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698