| 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 10 matching lines...) Expand all Loading... |
| 21 * | 21 * |
| 22 * Clients may not extend or implement this class, but are allowed to use it as | 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 | 23 * a mix-in when creating a subclass of [ServerPlugin] that also uses |
| 24 * [NavigationMixin] as a mix-in. | 24 * [NavigationMixin] as a mix-in. |
| 25 */ | 25 */ |
| 26 abstract class DartNavigationMixin implements NavigationMixin { | 26 abstract class DartNavigationMixin implements NavigationMixin { |
| 27 @override | 27 @override |
| 28 Future<NavigationRequest> getNavigationRequest( | 28 Future<NavigationRequest> getNavigationRequest( |
| 29 AnalysisGetNavigationParams parameters) async { | 29 AnalysisGetNavigationParams parameters) async { |
| 30 String path = parameters.file; | 30 String path = parameters.file; |
| 31 AnalysisDriver driver = driverForPath(path); | 31 ResolveResult result = await getResolveResult(path); |
| 32 if (driver == null) { | |
| 33 // Return an error from the request. | |
| 34 throw new RequestFailure( | |
| 35 RequestErrorFactory.pluginError('Failed to analyze $path', null)); | |
| 36 } | |
| 37 ResolveResult result = await driver.getResult(path); | |
| 38 return new DartNavigationRequestImpl( | 32 return new DartNavigationRequestImpl( |
| 39 resourceProvider, parameters.offset, parameters.length, result); | 33 resourceProvider, parameters.offset, parameters.length, result); |
| 40 } | 34 } |
| 41 } | 35 } |
| 42 | 36 |
| 43 /** | 37 /** |
| 44 * 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 |
| 45 * provide most of the implementation for handling navigation requests. | 39 * provide most of the implementation for handling navigation requests. |
| 46 * | 40 * |
| 47 * 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 |
| 48 * a mix-in when creating a subclass of [ServerPlugin]. | 42 * a mix-in when creating a subclass of [ServerPlugin]. |
| 49 */ | 43 */ |
| 50 abstract class NavigationMixin implements ServerPlugin { | 44 abstract class NavigationMixin implements ServerPlugin { |
| 51 /** | 45 /** |
| 52 * 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 |
| 53 * create navigation information for the file with the given [path] | 47 * create navigation information for the file with the given [path] |
| 54 */ | 48 */ |
| 55 List<NavigationContributor> getNavigationContributors(String path); | 49 List<NavigationContributor> getNavigationContributors(String path); |
| 56 | 50 |
| 57 /** | 51 /** |
| 58 * Return the navigation request that should be passes to the contributors | 52 * Return the navigation request that should be passes to the contributors |
| 59 * returned from [getNavigationContributors]. | 53 * returned from [getNavigationContributors]. |
| 54 * |
| 55 * Throw a [RequestFailure] if the request could not be created. |
| 60 */ | 56 */ |
| 61 Future<NavigationRequest> getNavigationRequest( | 57 Future<NavigationRequest> getNavigationRequest( |
| 62 AnalysisGetNavigationParams parameters); | 58 AnalysisGetNavigationParams parameters); |
| 63 | 59 |
| 64 @override | 60 @override |
| 65 Future<AnalysisGetNavigationResult> handleAnalysisGetNavigation( | 61 Future<AnalysisGetNavigationResult> handleAnalysisGetNavigation( |
| 66 AnalysisGetNavigationParams parameters) async { | 62 AnalysisGetNavigationParams parameters) async { |
| 67 String path = parameters.file; | 63 String path = parameters.file; |
| 68 NavigationRequest request = await getNavigationRequest(parameters); | 64 NavigationRequest request = await getNavigationRequest(parameters); |
| 69 NavigationGenerator generator = | 65 NavigationGenerator generator = |
| 70 new NavigationGenerator(getNavigationContributors(path)); | 66 new NavigationGenerator(getNavigationContributors(path)); |
| 71 GeneratorResult result = | 67 GeneratorResult result = |
| 72 await generator.generateNavigationResponse(request); | 68 await generator.generateNavigationResponse(request); |
| 73 result.sendNotifications(channel); | 69 result.sendNotifications(channel); |
| 74 return result.result; | 70 return result.result; |
| 75 } | 71 } |
| 76 } | 72 } |
| OLD | NEW |