Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: pkg/analyzer_plugin/lib/plugin/navigation_mixin.dart

Issue 2970203002: Remove references to AnalysisDriver from the plugin mixin classes (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 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 18 * mixing in [NavigationMixin]. This implements the creation of the navigation
19 * request based on the assumption that the driver being created is an 19 * request based on the assumption that the driver being created is an
20 * [AnalysisDriver]. 20 * [AnalysisDriver].
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, 29 AnalysisGetNavigationParams parameters) async {
30 covariant AnalysisDriver driver) async { 30 String path = parameters.file;
31 ResolveResult result = await driver.getResult(parameters.file); 31 AnalysisDriver driver = driverForPath(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);
32 return new DartNavigationRequestImpl( 38 return new DartNavigationRequestImpl(
33 resourceProvider, parameters.offset, parameters.length, result); 39 resourceProvider, parameters.offset, parameters.length, result);
34 } 40 }
35 } 41 }
36 42
37 /** 43 /**
38 * A mixin that can be used when creating a subclass of [ServerPlugin] to 44 * A mixin that can be used when creating a subclass of [ServerPlugin] to
39 * provide most of the implementation for handling navigation requests. 45 * provide most of the implementation for handling navigation requests.
40 * 46 *
41 * Clients may not extend or implement this class, but are allowed to use it as 47 * Clients may not extend or implement this class, but are allowed to use it as
42 * a mix-in when creating a subclass of [ServerPlugin]. 48 * a mix-in when creating a subclass of [ServerPlugin].
43 */ 49 */
44 abstract class NavigationMixin implements ServerPlugin { 50 abstract class NavigationMixin implements ServerPlugin {
45 /** 51 /**
46 * Return a list containing the navigation contributors that should be used to 52 * Return a list containing the navigation contributors that should be used to
47 * create navigation information when used in the context of the given 53 * create navigation information for the file with the given [path]
48 * analysis [driver].
49 */ 54 */
50 List<NavigationContributor> getNavigationContributors( 55 List<NavigationContributor> getNavigationContributors(String path);
51 covariant AnalysisDriverGeneric driver);
52 56
53 /** 57 /**
54 * Return the navigation request that should be passes to the contributors 58 * Return the navigation request that should be passes to the contributors
55 * returned from [getNavigationContributors]. 59 * returned from [getNavigationContributors].
56 */ 60 */
57 Future<NavigationRequest> getNavigationRequest( 61 Future<NavigationRequest> getNavigationRequest(
58 AnalysisGetNavigationParams parameters, 62 AnalysisGetNavigationParams parameters);
59 covariant AnalysisDriverGeneric driver);
60 63
61 @override 64 @override
62 Future<AnalysisGetNavigationResult> handleAnalysisGetNavigation( 65 Future<AnalysisGetNavigationResult> handleAnalysisGetNavigation(
63 AnalysisGetNavigationParams parameters) async { 66 AnalysisGetNavigationParams parameters) async {
64 String path = parameters.file; 67 String path = parameters.file;
65 ContextRoot contextRoot = contextRootContaining(path); 68 NavigationRequest request = await getNavigationRequest(parameters);
66 if (contextRoot == null) {
67 // Return an error from the request.
68 throw new RequestFailure(
69 RequestErrorFactory.pluginError('Failed to analyze $path', null));
70 }
71 AnalysisDriverGeneric driver = driverMap[contextRoot];
72 NavigationRequest request = await getNavigationRequest(parameters, driver);
73 NavigationGenerator generator = 69 NavigationGenerator generator =
74 new NavigationGenerator(getNavigationContributors(driver)); 70 new NavigationGenerator(getNavigationContributors(path));
75 GeneratorResult result = 71 GeneratorResult result =
76 await generator.generateNavigationResponse(request); 72 await generator.generateNavigationResponse(request);
77 result.sendNotifications(channel); 73 result.sendNotifications(channel);
78 return result.result; 74 return result.result;
79 } 75 }
80 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698