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

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

Issue 3008433002: Unify lots of copied code in one utility method (Closed)
Patch Set: Created 3 years, 4 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';
(...skipping 12 matching lines...) Expand all
23 abstract class CompletionMixin implements ServerPlugin { 23 abstract class CompletionMixin implements ServerPlugin {
24 /** 24 /**
25 * Return a list containing the completion contributors that should be used to 25 * Return a list containing the completion contributors that should be used to
26 * create completion suggestions for the file with the given [path]. 26 * create completion suggestions for the file with the given [path].
27 */ 27 */
28 List<CompletionContributor> getCompletionContributors(String path); 28 List<CompletionContributor> getCompletionContributors(String path);
29 29
30 /** 30 /**
31 * Return the completion request that should be passes to the contributors 31 * Return the completion request that should be passes to the contributors
32 * returned from [getCompletionContributors]. 32 * returned from [getCompletionContributors].
33 *
34 * Throw a [RequestFailure] if the request could not be created.
33 */ 35 */
34 Future<CompletionRequest> getCompletionRequest( 36 Future<CompletionRequest> getCompletionRequest(
35 CompletionGetSuggestionsParams parameters); 37 CompletionGetSuggestionsParams parameters);
36 38
37 @override 39 @override
38 Future<CompletionGetSuggestionsResult> handleCompletionGetSuggestions( 40 Future<CompletionGetSuggestionsResult> handleCompletionGetSuggestions(
39 CompletionGetSuggestionsParams parameters) async { 41 CompletionGetSuggestionsParams parameters) async {
40 String path = parameters.file; 42 String path = parameters.file;
41 CompletionRequest request = await getCompletionRequest(parameters); 43 CompletionRequest request = await getCompletionRequest(parameters);
42 CompletionGenerator generator = 44 CompletionGenerator generator =
(...skipping 13 matching lines...) Expand all
56 * 58 *
57 * Clients may not extend or implement this class, but are allowed to use it as 59 * Clients may not extend or implement this class, but are allowed to use it as
58 * a mix-in when creating a subclass of [ServerPlugin] that also uses 60 * a mix-in when creating a subclass of [ServerPlugin] that also uses
59 * [CompletionMixin] as a mix-in. 61 * [CompletionMixin] as a mix-in.
60 */ 62 */
61 abstract class DartCompletionMixin implements CompletionMixin { 63 abstract class DartCompletionMixin implements CompletionMixin {
62 @override 64 @override
63 Future<CompletionRequest> getCompletionRequest( 65 Future<CompletionRequest> getCompletionRequest(
64 CompletionGetSuggestionsParams parameters) async { 66 CompletionGetSuggestionsParams parameters) async {
65 String path = parameters.file; 67 String path = parameters.file;
66 AnalysisDriver driver = driverForPath(path); 68 ResolveResult result = await getResolveResult(parameters.file);
67 if (driver == null) {
68 // Return an error from the request.
69 throw new RequestFailure(
70 RequestErrorFactory.pluginError('Failed to analyze $path', null));
71 }
72 ResolveResult result = await driver.getResult(parameters.file);
73 return new DartCompletionRequestImpl( 69 return new DartCompletionRequestImpl(
74 resourceProvider, parameters.offset, result); 70 resourceProvider, parameters.offset, result);
75 } 71 }
76 } 72 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/lib/plugin/assist_mixin.dart ('k') | pkg/analyzer_plugin/lib/plugin/fix_mixin.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698