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

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

Issue 1531353002: report invalid param if offset is out of bounds (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart_completion_manager.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 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 performance.complete('priorityChanged caching: $success'); 174 performance.complete('priorityChanged caching: $success');
175 }); 175 });
176 } 176 }
177 } 177 }
178 178
179 /** 179 /**
180 * Process a `completion.getSuggestions` request. 180 * Process a `completion.getSuggestions` request.
181 */ 181 */
182 Response processRequest(Request request, [CompletionManager manager]) { 182 Response processRequest(Request request, [CompletionManager manager]) {
183 performance = new CompletionPerformance(); 183 performance = new CompletionPerformance();
184 // extract params 184
185 // extract and validate params
185 CompletionGetSuggestionsParams params = 186 CompletionGetSuggestionsParams params =
186 new CompletionGetSuggestionsParams.fromRequest(request); 187 new CompletionGetSuggestionsParams.fromRequest(request);
187 // schedule completion analysis
188 String completionId = (_nextCompletionId++).toString();
189 ContextSourcePair contextSource = server.getContextSourcePair(params.file); 188 ContextSourcePair contextSource = server.getContextSourcePair(params.file);
190 AnalysisContext context = contextSource.context; 189 AnalysisContext context = contextSource.context;
191 Source source = contextSource.source; 190 Source source = contextSource.source;
192 if (context == null || !context.exists(source)) { 191 if (context == null || !context.exists(source)) {
193 return new Response.unknownSource(request); 192 return new Response.unknownSource(request);
194 } 193 }
194 TimestampedData<String> contents = context.getContents(source);
195 if (params.offset < 0 || params.offset > contents.data.length) {
196 return new Response.invalidParameter(
197 request,
198 'params.offset',
199 'Expected offset between 0 and source length inclusive,'
200 ' but found ${params.offset}');
201 }
202
203 // schedule completion analysis
195 recordRequest(performance, context, source, params.offset); 204 recordRequest(performance, context, source, params.offset);
196 if (manager == null) { 205 if (manager == null) {
197 manager = completionManagerFor(context, source); 206 manager = completionManagerFor(context, source);
198 } 207 }
199 CompletionRequest completionRequest = new CompletionRequestImpl(context, 208 CompletionRequest completionRequest = new CompletionRequestImpl(context,
200 server.resourceProvider, server.searchEngine, source, params.offset); 209 server.resourceProvider, server.searchEngine, source, params.offset);
201 int notificationCount = 0; 210 int notificationCount = 0;
211 String completionId = (_nextCompletionId++).toString();
202 manager.results(completionRequest).listen((CompletionResult result) { 212 manager.results(completionRequest).listen((CompletionResult result) {
203 ++notificationCount; 213 ++notificationCount;
204 bool isLast = result is CompletionResultImpl ? result.isLast : true; 214 bool isLast = result is CompletionResultImpl ? result.isLast : true;
205 performance.logElapseTime("notification $notificationCount send", () { 215 performance.logElapseTime("notification $notificationCount send", () {
206 sendCompletionNotification(completionId, result.replacementOffset, 216 sendCompletionNotification(completionId, result.replacementOffset,
207 result.replacementLength, result.suggestions, isLast); 217 result.replacementLength, result.suggestions, isLast);
208 }); 218 });
209 if (notificationCount == 1) { 219 if (notificationCount == 1) {
210 performance.logFirstNotificationComplete('notification 1 complete'); 220 performance.logFirstNotificationComplete('notification 1 complete');
211 performance.suggestionCountFirst = result.suggestions.length; 221 performance.suggestionCountFirst = result.suggestions.length;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (_sourcesChangedSubscription != null) { 296 if (_sourcesChangedSubscription != null) {
287 _sourcesChangedSubscription.cancel(); 297 _sourcesChangedSubscription.cancel();
288 _sourcesChangedSubscription = null; 298 _sourcesChangedSubscription = null;
289 } 299 }
290 if (_manager != null) { 300 if (_manager != null) {
291 _manager.dispose(); 301 _manager.dispose();
292 _manager = null; 302 _manager = null;
293 } 303 }
294 } 304 }
295 } 305 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698