| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 import 'dart:async'; |
| 6 |
| 7 import 'package:analyzer/dart/analysis/results.dart'; |
| 8 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 9 import 'package:analyzer_plugin/plugin/plugin.dart'; |
| 10 import 'package:analyzer_plugin/protocol/protocol.dart'; |
| 11 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
| 12 import 'package:analyzer_plugin/src/utilities/completion/completion_core.dart'; |
| 13 import 'package:analyzer_plugin/utilities/completion/completion_core.dart'; |
| 14 import 'package:analyzer_plugin/utilities/generator.dart'; |
| 15 |
| 16 /** |
| 17 * A mixin that can be used when creating a subclass of [ServerPlugin] to |
| 18 * provide most of the implementation for handling code completion requests. |
| 19 * |
| 20 * Clients may not extend or implement this class, but are allowed to use it as |
| 21 * a mix-in when creating a subclass of [ServerPlugin]. |
| 22 */ |
| 23 abstract class CompletionMixin implements ServerPlugin { |
| 24 /** |
| 25 * Return a list containing the completion contributors that should be used to |
| 26 * create completion suggestions when used in the context of the given |
| 27 * analysis [driver]. |
| 28 */ |
| 29 List<CompletionContributor> getCompletionContributors( |
| 30 covariant AnalysisDriverGeneric driver); |
| 31 |
| 32 /** |
| 33 * Return the result of using the given analysis [driver] to produce a fully |
| 34 * resolved AST for the file with the given [path]. |
| 35 */ |
| 36 Future<ResolveResult> getResolveResultForCompletion( |
| 37 covariant AnalysisDriverGeneric driver, String path); |
| 38 |
| 39 @override |
| 40 Future<CompletionGetSuggestionsResult> handleCompletionGetSuggestions( |
| 41 CompletionGetSuggestionsParams parameters) async { |
| 42 String path = parameters.file; |
| 43 ContextRoot contextRoot = contextRootContaining(path); |
| 44 if (contextRoot == null) { |
| 45 // Return an error from the request. |
| 46 throw new RequestFailure( |
| 47 RequestErrorFactory.pluginError('Failed to analyze $path', null)); |
| 48 } |
| 49 AnalysisDriverGeneric driver = driverMap[contextRoot]; |
| 50 ResolveResult analysisResult = |
| 51 await getResolveResultForCompletion(driver, path); |
| 52 CompletionRequestImpl request = new CompletionRequestImpl( |
| 53 resourceProvider, analysisResult, parameters.offset); |
| 54 CompletionGenerator generator = |
| 55 new CompletionGenerator(getCompletionContributors(driver)); |
| 56 GeneratorResult result = |
| 57 await generator.generateCompletionResponse(request); |
| 58 result.sendNotifications(channel); |
| 59 return result.result; |
| 60 } |
| 61 } |
| OLD | NEW |