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

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

Issue 436263002: incremental progress reworking code completion manager / computers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments Created 6 years, 4 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/domain_completion_test.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 'package:analysis_server/src/analysis_server.dart'; 7 import 'package:analysis_server/src/analysis_server.dart';
8 import 'package:analysis_server/src/constants.dart'; 8 import 'package:analysis_server/src/constants.dart';
9 import 'package:analysis_server/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:analysis_services/completion/completion_computer.dart'; 10 import 'package:analysis_services/completion/completion_computer.dart';
11 import 'package:analysis_services/completion/completion_suggestion.dart'; 11 import 'package:analysis_services/completion/completion_suggestion.dart';
12 import 'package:analysis_services/constants.dart'; 12 import 'package:analysis_services/constants.dart';
13 import 'package:analyzer/src/generated/java_io.dart';
14 import 'package:analyzer/src/generated/source_io.dart'; 13 import 'package:analyzer/src/generated/source_io.dart';
15 14
16 /** 15 /**
17 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler] 16 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler]
18 * that handles requests in the search domain. 17 * that handles requests in the search domain.
19 */ 18 */
20 class CompletionDomainHandler implements RequestHandler { 19 class CompletionDomainHandler implements RequestHandler {
21 /** 20 /**
22 * The analysis server that is using this handler to process requests. 21 * The analysis server that is using this handler to process requests.
23 */ 22 */
(...skipping 25 matching lines...) Expand all
49 /** 48 /**
50 * Process a `completion.getSuggestions` request. 49 * Process a `completion.getSuggestions` request.
51 */ 50 */
52 Response processRequest(Request request) { 51 Response processRequest(Request request) {
53 // extract param 52 // extract param
54 String file = request.getRequiredParameter(FILE).asString(); 53 String file = request.getRequiredParameter(FILE).asString();
55 int offset = request.getRequiredParameter(OFFSET).asInt(); 54 int offset = request.getRequiredParameter(OFFSET).asInt();
56 // schedule completion analysis 55 // schedule completion analysis
57 String completionId = (_nextCompletionId++).toString(); 56 String completionId = (_nextCompletionId++).toString();
58 Source source = server.getSource(file); 57 Source source = server.getSource(file);
59 CompletionManager manager = 58 CompletionManager.create(
60 CompletionManager.create(source, offset, server.searchEngine); 59 source,
61 manager.generate().then((List<CompletionComputer> computers) { 60 offset,
62 int count = computers.length; 61 server.searchEngine).results().listen((CompletionResult result) {
63 List<CompletionSuggestion> results = new List<CompletionSuggestion>(); 62 sendCompletionNotification(
64 computers.forEach((CompletionComputer c) { 63 completionId,
65 c.compute().then((List<CompletionSuggestion> partialResults) { 64 result.replacementOffset,
66 // send aggregate results as we compute them 65 result.replacementLength,
67 results.addAll(partialResults); 66 result.suggestions,
68 sendCompletionNotification( 67 result.last);
69 manager.replacementOffset,
70 manager.replacementLength,
71 completionId,
72 --count == 0,
73 results);
74 });
75 });
76 }); 68 });
77 // initial response without results 69 // initial response without results
78 return new Response(request.id)..setResult(ID, completionId); 70 return new Response(request.id)..setResult(ID, completionId);
79 } 71 }
80 72
81 /** 73 /**
82 * Send completion notification results. 74 * Send completion notification results.
83 */ 75 */
84 void sendCompletionNotification(int replacementOffset, int replacementLength, 76 void sendCompletionNotification(String completionId, int replacementOffset,
85 String completionId, bool isLast, Iterable<CompletionSuggestion> results) { 77 int replacementLength, Iterable<CompletionSuggestion> results, bool isLast ) {
86 Notification notification = new Notification(COMPLETION_RESULTS); 78 Notification notification = new Notification(COMPLETION_RESULTS);
87 notification.setParameter(ID, completionId); 79 notification.setParameter(ID, completionId);
88 notification.setParameter(REPLACEMENT_OFFSET, replacementOffset); 80 notification.setParameter(REPLACEMENT_OFFSET, replacementOffset);
89 notification.setParameter(REPLACEMENT_LENGTH, replacementLength); 81 notification.setParameter(REPLACEMENT_LENGTH, replacementLength);
90 notification.setParameter(RESULTS, results); 82 notification.setParameter(RESULTS, results);
91 notification.setParameter(LAST, isLast); 83 notification.setParameter(LAST, isLast);
92 server.sendNotification(notification); 84 server.sendNotification(notification);
93 } 85 }
94 } 86 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/domain_completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698