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

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

Issue 2877653002: Remove unused analysisContext from completion request and contributors (Closed)
Patch Set: address comments 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 | « no previous file | pkg/analysis_server/lib/src/provisional/completion/completion_core.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/protocol/protocol.dart'; 9 import 'package:analysis_server/protocol/protocol.dart';
10 import 'package:analysis_server/protocol/protocol_generated.dart'; 10 import 'package:analysis_server/protocol/protocol_generated.dart';
11 import 'package:analysis_server/src/analysis_server.dart'; 11 import 'package:analysis_server/src/analysis_server.dart';
12 import 'package:analysis_server/src/constants.dart'; 12 import 'package:analysis_server/src/constants.dart';
13 import 'package:analysis_server/src/domain_abstract.dart'; 13 import 'package:analysis_server/src/domain_abstract.dart';
14 import 'package:analysis_server/src/plugin/plugin_manager.dart'; 14 import 'package:analysis_server/src/plugin/plugin_manager.dart';
15 import 'package:analysis_server/src/plugin/result_converter.dart'; 15 import 'package:analysis_server/src/plugin/result_converter.dart';
16 import 'package:analysis_server/src/provisional/completion/completion_core.dart' ; 16 import 'package:analysis_server/src/provisional/completion/completion_core.dart' ;
17 import 'package:analysis_server/src/services/completion/completion_core.dart'; 17 import 'package:analysis_server/src/services/completion/completion_core.dart';
18 import 'package:analysis_server/src/services/completion/completion_performance.d art'; 18 import 'package:analysis_server/src/services/completion/completion_performance.d art';
19 import 'package:analyzer/src/dart/analysis/driver.dart'; 19 import 'package:analyzer/src/dart/analysis/driver.dart';
20 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult;
21 import 'package:analyzer/src/generated/source.dart'; 20 import 'package:analyzer/src/generated/source.dart';
22 import 'package:analyzer/src/source/source_resource.dart'; 21 import 'package:analyzer/src/source/source_resource.dart';
23 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin; 22 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
24 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; 23 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin;
25 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; 24 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
26 25
27 /** 26 /**
28 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler] 27 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler]
29 * that handles requests in the completion domain. 28 * that handles requests in the completion domain.
30 */ 29 */
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 /** 162 /**
164 * Process a `completion.getSuggestions` request. 163 * Process a `completion.getSuggestions` request.
165 */ 164 */
166 Future<Null> processRequest(Request request) async { 165 Future<Null> processRequest(Request request) async {
167 performance = new CompletionPerformance(); 166 performance = new CompletionPerformance();
168 167
169 // extract and validate params 168 // extract and validate params
170 CompletionGetSuggestionsParams params = 169 CompletionGetSuggestionsParams params =
171 new CompletionGetSuggestionsParams.fromRequest(request); 170 new CompletionGetSuggestionsParams.fromRequest(request);
172 171
173 AnalysisResult result; 172 AnalysisResult result = await server.getAnalysisResult(params.file);
174 AnalysisContext context;
175 Source source;
176 if (server.options.enableNewAnalysisDriver) {
177 result = await server.getAnalysisResult(params.file);
178 173
179 if (result == null || !result.exists) { 174 if (result == null || !result.exists) {
180 if (server.onNoAnalysisCompletion != null) { 175 if (server.onNoAnalysisCompletion != null) {
181 String completionId = (_nextCompletionId++).toString(); 176 String completionId = (_nextCompletionId++).toString();
182 await server.onNoAnalysisCompletion( 177 await server.onNoAnalysisCompletion(
183 request, this, params, performance, completionId); 178 request, this, params, performance, completionId);
184 return;
185 } else {
186 server.sendResponse(new Response.unknownSource(request));
187 return;
188 }
189 }
190
191 if (params.offset < 0 || params.offset > result.content.length) {
192 server.sendResponse(new Response.invalidParameter(
193 request,
194 'params.offset',
195 'Expected offset between 0 and source length inclusive,'
196 ' but found ${params.offset}'));
197 return; 179 return;
198 } 180 } else {
199
200 source = new FileSource(
201 server.resourceProvider.getFile(result.path), result.uri);
202 } else {
203 ContextSourcePair contextSource =
204 server.getContextSourcePair(params.file);
205
206 context = contextSource.context;
207 source = contextSource.source;
208 if (context == null || !context.exists(source)) {
209 server.sendResponse(new Response.unknownSource(request)); 181 server.sendResponse(new Response.unknownSource(request));
210 return; 182 return;
211 } 183 }
212
213 TimestampedData<String> contents = context.getContents(source);
214 if (params.offset < 0 || params.offset > contents.data.length) {
215 server.sendResponse(new Response.invalidParameter(
216 request,
217 'params.offset',
218 'Expected offset between 0 and source length inclusive,'
219 ' but found ${params.offset}'));
220 return;
221 }
222 } 184 }
223 185
224 recordRequest(performance, context, source, params.offset); 186 if (params.offset < 0 || params.offset > result.content.length) {
187 server.sendResponse(new Response.invalidParameter(
188 request,
189 'params.offset',
190 'Expected offset between 0 and source length inclusive,'
191 ' but found ${params.offset}'));
192 return;
193 }
194
195 Source source =
196 server.resourceProvider.getFile(result.path).createSource(result.uri);
197
198 recordRequest(performance, source, result.content, params.offset);
225 199
226 CompletionRequestImpl completionRequest = new CompletionRequestImpl( 200 CompletionRequestImpl completionRequest = new CompletionRequestImpl(
227 result, 201 result,
228 context,
229 server.resourceProvider, 202 server.resourceProvider,
230 source, 203 source,
231 params.offset, 204 params.offset,
232 performance, 205 performance,
233 server.ideOptions); 206 server.ideOptions);
234 207
235 String completionId = (_nextCompletionId++).toString(); 208 String completionId = (_nextCompletionId++).toString();
236 209
237 setNewRequest(completionRequest); 210 setNewRequest(completionRequest);
238 211
(...skipping 16 matching lines...) Expand all
255 performance.complete(); 228 performance.complete();
256 }).whenComplete(() { 229 }).whenComplete(() {
257 ifMatchesRequestClear(completionRequest); 230 ifMatchesRequestClear(completionRequest);
258 }); 231 });
259 } 232 }
260 233
261 /** 234 /**
262 * If tracking code completion performance over time, then 235 * If tracking code completion performance over time, then
263 * record addition information about the request in the performance record. 236 * record addition information about the request in the performance record.
264 */ 237 */
265 void recordRequest(CompletionPerformance performance, AnalysisContext context, 238 void recordRequest(CompletionPerformance performance, Source source,
266 Source source, int offset) { 239 String content, int offset) {
267 performance.source = source; 240 performance.source = source;
268 if (performanceListMaxLength == 0 || context == null || source == null) { 241 if (performanceListMaxLength == 0 || source == null) {
269 return; 242 return;
270 } 243 }
271 TimestampedData<String> data = context.getContents(source); 244 performance.setContentsAndOffset(content, offset);
272 if (data == null) {
273 return;
274 }
275 performance.setContentsAndOffset(data.data, offset);
276 while (performanceList.length >= performanceListMaxLength) { 245 while (performanceList.length >= performanceListMaxLength) {
277 performanceList.removeAt(0); 246 performanceList.removeAt(0);
278 } 247 }
279 performanceList.add(performance); 248 performanceList.add(performance);
280 } 249 }
281 250
282 /** 251 /**
283 * Send completion notification results. 252 * Send completion notification results.
284 */ 253 */
285 void sendCompletionNotification(String completionId, int replacementOffset, 254 void sendCompletionNotification(String completionId, int replacementOffset,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 final int replacementOffset; 294 final int replacementOffset;
326 295
327 /** 296 /**
328 * The suggested completions. 297 * The suggested completions.
329 */ 298 */
330 final List<CompletionSuggestion> suggestions; 299 final List<CompletionSuggestion> suggestions;
331 300
332 CompletionResult( 301 CompletionResult(
333 this.replacementOffset, this.replacementLength, this.suggestions); 302 this.replacementOffset, this.replacementLength, this.suggestions);
334 } 303 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/provisional/completion/completion_core.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698