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 * [KytheMixin] as a mix-in. | 24 * [KytheMixin] as a mix-in. |
25 */ | 25 */ |
26 abstract class DartEntryMixin implements EntryMixin { | 26 abstract class DartEntryMixin implements EntryMixin { |
27 @override | 27 @override |
28 Future<EntryRequest> getEntryRequest( | 28 Future<EntryRequest> getEntryRequest( |
29 KytheGetKytheEntriesParams parameters) async { | 29 KytheGetKytheEntriesParams 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 DartEntryRequestImpl(resourceProvider, result); | 32 return new DartEntryRequestImpl(resourceProvider, result); |
39 } | 33 } |
40 } | 34 } |
41 | 35 |
42 /** | 36 /** |
43 * A mixin that can be used when creating a subclass of [ServerPlugin] to | 37 * A mixin that can be used when creating a subclass of [ServerPlugin] to |
44 * provide most of the implementation for handling kythe.getEntries requests. | 38 * provide most of the implementation for handling kythe.getEntries requests. |
45 * | 39 * |
46 * Clients may not extend or implement this class, but are allowed to use it as | 40 * Clients may not extend or implement this class, but are allowed to use it as |
47 * a mix-in when creating a subclass of [ServerPlugin]. | 41 * a mix-in when creating a subclass of [ServerPlugin]. |
48 */ | 42 */ |
49 abstract class EntryMixin implements ServerPlugin { | 43 abstract class EntryMixin implements ServerPlugin { |
50 /** | 44 /** |
51 * Return a list containing the entry contributors that should be used to | 45 * Return a list containing the entry contributors that should be used to |
52 * create entries for the file with the given [path] | 46 * create entries for the file with the given [path] |
53 */ | 47 */ |
54 List<EntryContributor> getEntryContributors(String path); | 48 List<EntryContributor> getEntryContributors(String path); |
55 | 49 |
56 /** | 50 /** |
57 * Return the entries request that should be passes to the contributors | 51 * Return the entries request that should be passes to the contributors |
58 * returned from [getEntryContributors]. | 52 * returned from [getEntryContributors]. |
| 53 * |
| 54 * Throw a [RequestFailure] if the request could not be created. |
59 */ | 55 */ |
60 Future<EntryRequest> getEntryRequest(KytheGetKytheEntriesParams parameters); | 56 Future<EntryRequest> getEntryRequest(KytheGetKytheEntriesParams parameters); |
61 | 57 |
62 @override | 58 @override |
63 Future<KytheGetKytheEntriesResult> handleKytheGetKytheEntries( | 59 Future<KytheGetKytheEntriesResult> handleKytheGetKytheEntries( |
64 KytheGetKytheEntriesParams parameters) async { | 60 KytheGetKytheEntriesParams parameters) async { |
65 String path = parameters.file; | 61 String path = parameters.file; |
66 EntryRequest request = await getEntryRequest(parameters); | 62 EntryRequest request = await getEntryRequest(parameters); |
67 EntryGenerator generator = new EntryGenerator(getEntryContributors(path)); | 63 EntryGenerator generator = new EntryGenerator(getEntryContributors(path)); |
68 GeneratorResult result = | 64 GeneratorResult result = |
69 await generator.generateGetEntriesResponse(request); | 65 await generator.generateGetEntriesResponse(request); |
70 result.sendNotifications(channel); | 66 result.sendNotifications(channel); |
71 return result.result; | 67 return result.result; |
72 } | 68 } |
73 } | 69 } |
OLD | NEW |