OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 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 | 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:analyzer/dart/analysis/results.dart'; | 7 import 'package:analyzer/dart/analysis/results.dart'; |
8 import 'package:analyzer/src/dart/analysis/driver.dart'; | 8 import 'package:analyzer/src/dart/analysis/driver.dart'; |
9 import 'package:analyzer_plugin/plugin/plugin.dart'; | 9 import 'package:analyzer_plugin/plugin/plugin.dart'; |
10 import 'package:analyzer_plugin/protocol/protocol.dart'; | 10 import 'package:analyzer_plugin/protocol/protocol.dart'; |
(...skipping 11 matching lines...) Expand all Loading... |
22 */ | 22 */ |
23 abstract class AssistsMixin implements ServerPlugin { | 23 abstract class AssistsMixin implements ServerPlugin { |
24 /** | 24 /** |
25 * Return a list containing the assist contributors that should be used to | 25 * Return a list containing the assist contributors that should be used to |
26 * create assists when used in the context of the given analysis [driver]. | 26 * create assists when used in the context of the given analysis [driver]. |
27 */ | 27 */ |
28 List<AssistContributor> getAssistContributors( | 28 List<AssistContributor> getAssistContributors( |
29 covariant AnalysisDriverGeneric driver); | 29 covariant AnalysisDriverGeneric driver); |
30 | 30 |
31 /** | 31 /** |
32 * Return the result of using the given analysis [driver] to produce a fully | 32 * Return the assist request that should be passes to the contributors |
33 * resolved AST for the file with the given [path]. | 33 * returned from [getAssistContributors]. |
34 */ | 34 */ |
35 Future<ResolveResult> getResolveResultForAssists( | 35 Future<AssistRequest> getAssistRequest( |
36 covariant AnalysisDriverGeneric driver, String path); | 36 EditGetAssistsParams parameters, covariant AnalysisDriverGeneric driver); |
37 | 37 |
38 @override | 38 @override |
39 Future<EditGetAssistsResult> handleEditGetAssists( | 39 Future<EditGetAssistsResult> handleEditGetAssists( |
40 EditGetAssistsParams parameters) async { | 40 EditGetAssistsParams parameters) async { |
41 String path = parameters.file; | 41 String path = parameters.file; |
42 ContextRoot contextRoot = contextRootContaining(path); | 42 ContextRoot contextRoot = contextRootContaining(path); |
43 if (contextRoot == null) { | 43 if (contextRoot == null) { |
44 // Return an error from the request. | 44 // Return an error from the request. |
45 throw new RequestFailure( | 45 throw new RequestFailure( |
46 RequestErrorFactory.pluginError('Failed to analyze $path', null)); | 46 RequestErrorFactory.pluginError('Failed to analyze $path', null)); |
47 } | 47 } |
48 AnalysisDriverGeneric driver = driverMap[contextRoot]; | 48 AnalysisDriverGeneric driver = driverMap[contextRoot]; |
49 ResolveResult analysisResult = | 49 AssistRequest request = await getAssistRequest(parameters, driver); |
50 await getResolveResultForAssists(driver, path); | |
51 AssistRequestImpl request = new AssistRequestImpl( | |
52 resourceProvider, parameters.offset, parameters.length, analysisResult); | |
53 AssistGenerator generator = | 50 AssistGenerator generator = |
54 new AssistGenerator(getAssistContributors(driver)); | 51 new AssistGenerator(getAssistContributors(driver)); |
55 GeneratorResult result = await generator.generateAssistsResponse(request); | 52 GeneratorResult result = await generator.generateAssistsResponse(request); |
56 result.sendNotifications(channel); | 53 result.sendNotifications(channel); |
57 return result.result; | 54 return result.result; |
58 } | 55 } |
59 } | 56 } |
| 57 |
| 58 /** |
| 59 * A mixin that can be used when creating a subclass of [ServerPlugin] and |
| 60 * mixing in [AssistsMixin]. This implements the creation of the assists request |
| 61 * based on the assumption that the driver being created is an [AnalysisDriver]. |
| 62 * |
| 63 * Clients may not extend or implement this class, but are allowed to use it as |
| 64 * a mix-in when creating a subclass of [ServerPlugin] that also uses |
| 65 * [AssistsMixin] as a mix-in. |
| 66 */ |
| 67 abstract class DartAssistsMixin implements AssistsMixin { |
| 68 @override |
| 69 Future<AssistRequest> getAssistRequest( |
| 70 EditGetAssistsParams parameters, covariant AnalysisDriver driver) async { |
| 71 ResolveResult result = await driver.getResult(parameters.file); |
| 72 return new DartAssistRequestImpl( |
| 73 resourceProvider, parameters.offset, parameters.length, result); |
| 74 } |
| 75 } |
OLD | NEW |