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

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

Issue 2835053005: Add stopgap for angular autocompletion. (Closed)
Patch Set: fix format Created 3 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
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | no next file » | 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 domain.completion; 5 library domain.completion;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; 9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:analysis_server/src/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 String contributorTag = 'computeSuggestions - ${contributor.runtimeType}'; 84 String contributorTag = 'computeSuggestions - ${contributor.runtimeType}';
85 performance.logStartTime(contributorTag); 85 performance.logStartTime(contributorTag);
86 try { 86 try {
87 suggestions.addAll(await contributor.computeSuggestions(request)); 87 suggestions.addAll(await contributor.computeSuggestions(request));
88 } on AbortCompletion { 88 } on AbortCompletion {
89 suggestions.clear(); 89 suggestions.clear();
90 break; 90 break;
91 } 91 }
92 performance.logElapseTime(contributorTag); 92 performance.logElapseTime(contributorTag);
93 } 93 }
94
95 performance.logElapseTime(COMPUTE_SUGGESTIONS_TAG); 94 performance.logElapseTime(COMPUTE_SUGGESTIONS_TAG);
96 95
97 // TODO (danrubel) if request is obsolete 96 // TODO (danrubel) if request is obsolete
98 // (processAnalysisRequest returns false) 97 // (processAnalysisRequest returns false)
99 // then send empty results 98 // then send empty results
100 99
101 return new CompletionResult( 100 return new CompletionResult(
102 request.replacementOffset, request.replacementLength, suggestions); 101 request.replacementOffset, request.replacementLength, suggestions);
103 } 102 }
104 103
(...skipping 27 matching lines...) Expand all
132 CompletionGetSuggestionsParams params = 131 CompletionGetSuggestionsParams params =
133 new CompletionGetSuggestionsParams.fromRequest(request); 132 new CompletionGetSuggestionsParams.fromRequest(request);
134 133
135 AnalysisResult result; 134 AnalysisResult result;
136 AnalysisContext context; 135 AnalysisContext context;
137 Source source; 136 Source source;
138 if (server.options.enableNewAnalysisDriver) { 137 if (server.options.enableNewAnalysisDriver) {
139 result = await server.getAnalysisResult(params.file); 138 result = await server.getAnalysisResult(params.file);
140 139
141 if (result == null || !result.exists) { 140 if (result == null || !result.exists) {
142 server.sendResponse(new Response.unknownSource(request)); 141 if (server.onNoAnalysisCompletion != null) {
143 return; 142 String completionId = (_nextCompletionId++).toString();
143 await server.onNoAnalysisCompletion(
144 request, this, params, performance, completionId);
145 return;
146 } else {
147 server.sendResponse(new Response.unknownSource(request));
148 return;
149 }
144 } 150 }
145 151
146 if (params.offset < 0 || params.offset > result.content.length) { 152 if (params.offset < 0 || params.offset > result.content.length) {
147 server.sendResponse(new Response.invalidParameter( 153 server.sendResponse(new Response.invalidParameter(
148 request, 154 request,
149 'params.offset', 155 'params.offset',
150 'Expected offset between 0 and source length inclusive,' 156 'Expected offset between 0 and source length inclusive,'
151 ' but found ${params.offset}')); 157 ' but found ${params.offset}'));
152 return; 158 return;
153 } 159 }
(...skipping 26 matching lines...) Expand all
180 186
181 CompletionRequestImpl completionRequest = new CompletionRequestImpl( 187 CompletionRequestImpl completionRequest = new CompletionRequestImpl(
182 result, 188 result,
183 context, 189 context,
184 server.resourceProvider, 190 server.resourceProvider,
185 server.searchEngine, 191 server.searchEngine,
186 source, 192 source,
187 params.offset, 193 params.offset,
188 performance, 194 performance,
189 server.ideOptions); 195 server.ideOptions);
196
190 String completionId = (_nextCompletionId++).toString(); 197 String completionId = (_nextCompletionId++).toString();
191 198
192 _abortCurrentRequest(); 199 setNewRequest(completionRequest);
193 _currentRequest = completionRequest;
194 200
195 // initial response without results 201 // initial response without results
196 server.sendResponse(new CompletionGetSuggestionsResult(completionId) 202 server.sendResponse(new CompletionGetSuggestionsResult(completionId)
197 .toResponse(request.id)); 203 .toResponse(request.id));
198 204
199 // Compute suggestions in the background 205 // Compute suggestions in the background
200 computeSuggestions(completionRequest).then((CompletionResult result) { 206 computeSuggestions(completionRequest).then((CompletionResult result) {
201 const SEND_NOTIFICATION_TAG = 'send notification'; 207 const SEND_NOTIFICATION_TAG = 'send notification';
202 performance.logStartTime(SEND_NOTIFICATION_TAG); 208 performance.logStartTime(SEND_NOTIFICATION_TAG);
203 sendCompletionNotification(completionId, result.replacementOffset, 209 sendCompletionNotification(completionId, result.replacementOffset,
204 result.replacementLength, result.suggestions); 210 result.replacementLength, result.suggestions);
205 performance.logElapseTime(SEND_NOTIFICATION_TAG); 211 performance.logElapseTime(SEND_NOTIFICATION_TAG);
206
207 performance.notificationCount = 1; 212 performance.notificationCount = 1;
208 performance.logFirstNotificationComplete('notification 1 complete'); 213 performance.logFirstNotificationComplete('notification 1 complete');
209 performance.suggestionCountFirst = result.suggestions.length; 214 performance.suggestionCountFirst = result.suggestions.length;
210 performance.suggestionCountLast = result.suggestions.length; 215 performance.suggestionCountLast = result.suggestions.length;
211 performance.complete(); 216 performance.complete();
212 }).whenComplete(() { 217 }).whenComplete(() {
213 if (_currentRequest == completionRequest) { 218 ifMatchesRequestClear(completionRequest);
214 _currentRequest = null;
215 }
216 }); 219 });
217 } 220 }
218 221
222 void setNewRequest(CompletionRequest completionRequest) {
223 _abortCurrentRequest();
224 _currentRequest = completionRequest;
225 }
226
227 void ifMatchesRequestClear(CompletionRequest completionRequest) {
228 if (_currentRequest == completionRequest) {
229 _currentRequest = null;
230 }
231 }
232
219 /** 233 /**
220 * If tracking code completion performance over time, then 234 * If tracking code completion performance over time, then
221 * record addition information about the request in the performance record. 235 * record addition information about the request in the performance record.
222 */ 236 */
223 void recordRequest(CompletionPerformance performance, AnalysisContext context, 237 void recordRequest(CompletionPerformance performance, AnalysisContext context,
224 Source source, int offset) { 238 Source source, int offset) {
225 performance.source = source; 239 performance.source = source;
226 if (performanceListMaxLength == 0 || context == null || source == null) { 240 if (performanceListMaxLength == 0 || context == null || source == null) {
227 return; 241 return;
228 } 242 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 final int replacementOffset; 292 final int replacementOffset;
279 293
280 /** 294 /**
281 * The suggested completions. 295 * The suggested completions.
282 */ 296 */
283 final List<CompletionSuggestion> suggestions; 297 final List<CompletionSuggestion> suggestions;
284 298
285 CompletionResult( 299 CompletionResult(
286 this.replacementOffset, this.replacementLength, this.suggestions); 300 this.replacementOffset, this.replacementLength, this.suggestions);
287 } 301 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/analysis_server.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698