| OLD | NEW |
| 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/source_io.dart'; | |
| 14 | 13 |
| 15 /** | 14 /** |
| 16 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler] | 15 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler] |
| 17 * that handles requests in the search domain. | 16 * that handles requests in the search domain. |
| 18 */ | 17 */ |
| 19 class CompletionDomainHandler implements RequestHandler { | 18 class CompletionDomainHandler implements RequestHandler { |
| 20 /** | 19 /** |
| 21 * The analysis server that is using this handler to process requests. | 20 * The analysis server that is using this handler to process requests. |
| 22 */ | 21 */ |
| 23 final AnalysisServer server; | 22 final AnalysisServer server; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 47 | 46 |
| 48 /** | 47 /** |
| 49 * Process a `completion.getSuggestions` request. | 48 * Process a `completion.getSuggestions` request. |
| 50 */ | 49 */ |
| 51 Response processRequest(Request request) { | 50 Response processRequest(Request request) { |
| 52 // extract param | 51 // extract param |
| 53 String file = request.getRequiredParameter(FILE).asString(); | 52 String file = request.getRequiredParameter(FILE).asString(); |
| 54 int offset = request.getRequiredParameter(OFFSET).asInt(); | 53 int offset = request.getRequiredParameter(OFFSET).asInt(); |
| 55 // schedule completion analysis | 54 // schedule completion analysis |
| 56 String completionId = (_nextCompletionId++).toString(); | 55 String completionId = (_nextCompletionId++).toString(); |
| 57 Source source = server.getSource(file); | |
| 58 CompletionManager.create( | 56 CompletionManager.create( |
| 59 source, | 57 server.getAnalysisContext(file), |
| 58 server.getSource(file), |
| 60 offset, | 59 offset, |
| 61 server.searchEngine).results().listen((CompletionResult result) { | 60 server.searchEngine).results().listen((CompletionResult result) { |
| 62 sendCompletionNotification( | 61 sendCompletionNotification( |
| 63 completionId, | 62 completionId, |
| 64 result.replacementOffset, | 63 result.replacementOffset, |
| 65 result.replacementLength, | 64 result.replacementLength, |
| 66 result.suggestions, | 65 result.suggestions, |
| 67 result.last); | 66 result.last); |
| 68 }); | 67 }); |
| 69 // initial response without results | 68 // initial response without results |
| 70 return new Response(request.id)..setResult(ID, completionId); | 69 return new Response(request.id)..setResult(ID, completionId); |
| 71 } | 70 } |
| 72 | 71 |
| 73 /** | 72 /** |
| 74 * Send completion notification results. | 73 * Send completion notification results. |
| 75 */ | 74 */ |
| 76 void sendCompletionNotification(String completionId, int replacementOffset, | 75 void sendCompletionNotification(String completionId, int replacementOffset, |
| 77 int replacementLength, Iterable<CompletionSuggestion> results, bool isLast
) { | 76 int replacementLength, Iterable<CompletionSuggestion> results, bool isLast
) { |
| 78 Notification notification = new Notification(COMPLETION_RESULTS); | 77 Notification notification = new Notification(COMPLETION_RESULTS); |
| 79 notification.setParameter(ID, completionId); | 78 notification.setParameter(ID, completionId); |
| 80 notification.setParameter(REPLACEMENT_OFFSET, replacementOffset); | 79 notification.setParameter(REPLACEMENT_OFFSET, replacementOffset); |
| 81 notification.setParameter(REPLACEMENT_LENGTH, replacementLength); | 80 notification.setParameter(REPLACEMENT_LENGTH, replacementLength); |
| 82 notification.setParameter(RESULTS, results); | 81 notification.setParameter(RESULTS, results); |
| 83 notification.setParameter(LAST, isLast); | 82 notification.setParameter(LAST, isLast); |
| 84 server.sendNotification(notification); | 83 server.sendNotification(notification); |
| 85 } | 84 } |
| 86 } | 85 } |
| OLD | NEW |