| 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'; |
| 11 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; | 11 import 'package:analyzer_plugin/protocol/protocol_generated.dart'; |
| 12 import 'package:analyzer_plugin/src/utilities/navigation/navigation.dart'; | 12 import 'package:analyzer_plugin/src/utilities/navigation/navigation.dart'; |
| 13 import 'package:analyzer_plugin/utilities/generator.dart'; | 13 import 'package:analyzer_plugin/utilities/generator.dart'; |
| 14 import 'package:analyzer_plugin/utilities/navigation/navigation.dart'; | 14 import 'package:analyzer_plugin/utilities/navigation/navigation.dart'; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * A mixin that can be used when creating a subclass of [ServerPlugin] and |
| 18 * mixing in [NavigationMixin]. This implements the creation of the navigation |
| 19 * request based on the assumption that the driver being created is an |
| 20 * [AnalysisDriver]. |
| 21 * |
| 22 * Clients may not extend or implement this class, but are allowed to use it as |
| 23 * a mix-in when creating a subclass of [ServerPlugin] that also uses |
| 24 * [NavigationMixin] as a mix-in. |
| 25 */ |
| 26 abstract class DartNavigationMixin implements NavigationMixin { |
| 27 @override |
| 28 Future<NavigationRequest> getNavigationRequest( |
| 29 AnalysisGetNavigationParams parameters, |
| 30 covariant AnalysisDriver driver) async { |
| 31 ResolveResult result = await driver.getResult(parameters.file); |
| 32 return new DartNavigationRequestImpl( |
| 33 resourceProvider, parameters.offset, parameters.length, result); |
| 34 } |
| 35 } |
| 36 |
| 37 /** |
| 17 * A mixin that can be used when creating a subclass of [ServerPlugin] to | 38 * A mixin that can be used when creating a subclass of [ServerPlugin] to |
| 18 * provide most of the implementation for handling navigation requests. | 39 * provide most of the implementation for handling navigation requests. |
| 19 * | 40 * |
| 20 * Clients may not extend or implement this class, but are allowed to use it as | 41 * 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]. | 42 * a mix-in when creating a subclass of [ServerPlugin]. |
| 22 */ | 43 */ |
| 23 abstract class NavigationMixin implements ServerPlugin { | 44 abstract class NavigationMixin implements ServerPlugin { |
| 24 /** | 45 /** |
| 25 * Return a list containing the navigation contributors that should be used to | 46 * Return a list containing the navigation contributors that should be used to |
| 26 * create navigation information when used in the context of the given | 47 * create navigation information when used in the context of the given |
| 27 * analysis [driver]. | 48 * analysis [driver]. |
| 28 */ | 49 */ |
| 29 List<NavigationContributor> getNavigationContributors( | 50 List<NavigationContributor> getNavigationContributors( |
| 30 covariant AnalysisDriverGeneric driver); | 51 covariant AnalysisDriverGeneric driver); |
| 31 | 52 |
| 32 /** | 53 /** |
| 33 * Return the result of using the given analysis [driver] to produce a fully | 54 * Return the navigation request that should be passes to the contributors |
| 34 * resolved AST for the file with the given [path]. | 55 * returned from [getNavigationContributors]. |
| 35 */ | 56 */ |
| 36 Future<ResolveResult> getResolveResultForNavigation( | 57 Future<NavigationRequest> getNavigationRequest( |
| 37 covariant AnalysisDriverGeneric driver, String path); | 58 AnalysisGetNavigationParams parameters, |
| 59 covariant AnalysisDriverGeneric driver); |
| 38 | 60 |
| 39 @override | 61 @override |
| 40 Future<AnalysisGetNavigationResult> handleAnalysisGetNavigation( | 62 Future<AnalysisGetNavigationResult> handleAnalysisGetNavigation( |
| 41 AnalysisGetNavigationParams parameters) async { | 63 AnalysisGetNavigationParams parameters) async { |
| 42 String path = parameters.file; | 64 String path = parameters.file; |
| 43 ContextRoot contextRoot = contextRootContaining(path); | 65 ContextRoot contextRoot = contextRootContaining(path); |
| 44 if (contextRoot == null) { | 66 if (contextRoot == null) { |
| 45 // Return an error from the request. | 67 // Return an error from the request. |
| 46 throw new RequestFailure( | 68 throw new RequestFailure( |
| 47 RequestErrorFactory.pluginError('Failed to analyze $path', null)); | 69 RequestErrorFactory.pluginError('Failed to analyze $path', null)); |
| 48 } | 70 } |
| 49 AnalysisDriverGeneric driver = driverMap[contextRoot]; | 71 AnalysisDriverGeneric driver = driverMap[contextRoot]; |
| 50 ResolveResult analysisResult = | 72 NavigationRequest request = await getNavigationRequest(parameters, driver); |
| 51 await getResolveResultForNavigation(driver, path); | |
| 52 NavigationRequestImpl request = new NavigationRequestImpl( | |
| 53 resourceProvider, parameters.offset, parameters.length, analysisResult); | |
| 54 NavigationGenerator generator = | 73 NavigationGenerator generator = |
| 55 new NavigationGenerator(getNavigationContributors(driver)); | 74 new NavigationGenerator(getNavigationContributors(driver)); |
| 56 GeneratorResult result = | 75 GeneratorResult result = |
| 57 await generator.generateNavigationResponse(request); | 76 await generator.generateNavigationResponse(request); |
| 58 result.sendNotifications(channel); | 77 result.sendNotifications(channel); |
| 59 return result.result; | 78 return result.result; |
| 60 } | 79 } |
| 61 } | 80 } |
| OLD | NEW |