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

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

Issue 2953093002: Update the plugin API (Closed)
Patch Set: Update FixesRequest Created 3 years, 6 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 when used in the context of the given 26 * create completion suggestions when used in the context of the given
27 * analysis [driver]. 27 * analysis [driver].
28 */ 28 */
29 List<CompletionContributor> getCompletionContributors( 29 List<CompletionContributor> getCompletionContributors(
30 covariant AnalysisDriverGeneric driver); 30 covariant AnalysisDriverGeneric driver);
31 31
32 /** 32 /**
33 * Return the result of using the given analysis [driver] to produce a fully 33 * Return the completion request that should be passes to the contributors
34 * resolved AST for the file with the given [path]. 34 * returned from [getCompletionContributors].
35 */ 35 */
36 Future<ResolveResult> getResolveResultForCompletion( 36 Future<CompletionRequest> getCompletionRequest(
37 covariant AnalysisDriverGeneric driver, String path); 37 CompletionGetSuggestionsParams parameters,
38 covariant AnalysisDriverGeneric driver);
38 39
39 @override 40 @override
40 Future<CompletionGetSuggestionsResult> handleCompletionGetSuggestions( 41 Future<CompletionGetSuggestionsResult> handleCompletionGetSuggestions(
41 CompletionGetSuggestionsParams parameters) async { 42 CompletionGetSuggestionsParams parameters) async {
42 String path = parameters.file; 43 String path = parameters.file;
43 ContextRoot contextRoot = contextRootContaining(path); 44 ContextRoot contextRoot = contextRootContaining(path);
44 if (contextRoot == null) { 45 if (contextRoot == null) {
45 // Return an error from the request. 46 // Return an error from the request.
46 throw new RequestFailure( 47 throw new RequestFailure(
47 RequestErrorFactory.pluginError('Failed to analyze $path', null)); 48 RequestErrorFactory.pluginError('Failed to analyze $path', null));
48 } 49 }
49 AnalysisDriverGeneric driver = driverMap[contextRoot]; 50 AnalysisDriverGeneric driver = driverMap[contextRoot];
50 ResolveResult analysisResult = 51 CompletionRequest request = await getCompletionRequest(parameters, driver);
51 await getResolveResultForCompletion(driver, path);
52 CompletionRequestImpl request = new CompletionRequestImpl(
53 resourceProvider, analysisResult, parameters.offset);
54 CompletionGenerator generator = 52 CompletionGenerator generator =
55 new CompletionGenerator(getCompletionContributors(driver)); 53 new CompletionGenerator(getCompletionContributors(driver));
56 GeneratorResult result = 54 GeneratorResult result =
57 await generator.generateCompletionResponse(request); 55 await generator.generateCompletionResponse(request);
58 result.sendNotifications(channel); 56 result.sendNotifications(channel);
59 return result.result; 57 return result.result;
60 } 58 }
61 } 59 }
60
61 /**
62 * A mixin that can be used when creating a subclass of [ServerPlugin] and
63 * mixing in [CompletionMixin]. This implements the creation of the completion
64 * request based on the assumption that the driver being created is an
65 * [AnalysisDriver].
66 *
67 * Clients may not extend or implement this class, but are allowed to use it as
68 * a mix-in when creating a subclass of [ServerPlugin] that also uses
69 * [CompletionMixin] as a mix-in.
70 */
71 abstract class DartCompletionMixin implements CompletionMixin {
72 @override
73 Future<CompletionRequest> getCompletionRequest(
74 CompletionGetSuggestionsParams parameters,
75 covariant AnalysisDriver driver) async {
76 ResolveResult result = await driver.getResult(parameters.file);
77 return new DartCompletionRequestImpl(
78 resourceProvider, parameters.offset, result);
79 }
80 }
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