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

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

Issue 2953093002: Update the plugin API (Closed)
Patch Set: 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';
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/fixes/fixes.dart'; 12 import 'package:analyzer_plugin/src/utilities/fixes/fixes.dart';
13 import 'package:analyzer_plugin/utilities/fixes/fixes.dart'; 13 import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
14 import 'package:analyzer_plugin/utilities/generator.dart'; 14 import 'package:analyzer_plugin/utilities/generator.dart';
15 15
16 /** 16 /**
17 * A mixin that can be used when creating a subclass of [ServerPlugin] and
18 * mixing in [FixesMixin]. This implements the creation of the fixes request
19 * based on the assumption that the driver being created is an [AnalysisDriver].
20 *
21 * Clients may not extend or implement this class, but are allowed to use it as
22 * a mix-in when creating a subclass of [ServerPlugin] that also uses
23 * [FixesMixin] as a mix-in.
24 */
25 abstract class DartFixesMixin implements FixesMixin {
26 @override
27 Future<FixesRequest> getFixesRequest(
28 EditGetFixesParams parameters, covariant AnalysisDriver driver) async {
29 ResolveResult analysisResult = await driver.getResult(parameters.file);
30 return new FixesRequestImpl(
31 resourceProvider, parameters.offset, analysisResult);
32 }
33 }
34
35 /**
17 * A mixin that can be used when creating a subclass of [ServerPlugin] to 36 * A mixin that can be used when creating a subclass of [ServerPlugin] to
18 * provide most of the implementation for handling fix requests. 37 * provide most of the implementation for handling fix requests.
19 * 38 *
20 * Clients may not extend or implement this class, but are allowed to use it as 39 * Clients may not extend or implement this class, but are allowed to use it as
21 * a mix-in when creating a subclass of [ServerPlugin]. 40 * a mix-in when creating a subclass of [ServerPlugin].
22 */ 41 */
23 abstract class FixesMixin implements ServerPlugin { 42 abstract class FixesMixin implements ServerPlugin {
24 /** 43 /**
25 * Return a list containing the fix contributors that should be used to create 44 * Return a list containing the fix contributors that should be used to create
26 * fixes when used in the context of the given analysis [driver]. 45 * fixes when used in the context of the given analysis [driver].
27 */ 46 */
28 List<FixContributor> getFixContributors( 47 List<FixContributor> getFixContributors(
29 covariant AnalysisDriverGeneric driver); 48 covariant AnalysisDriverGeneric driver);
30 49
31 /** 50 /**
32 * Return the result of using the given analysis [driver] to produce a fully 51 * Return the fixes request that should be passes to the contributors
33 * resolved AST for the file with the given [path]. 52 * returned from [getFixContributors].
34 */ 53 */
35 Future<ResolveResult> getResolveResultForFixes( 54 Future<FixesRequest> getFixesRequest(
36 covariant AnalysisDriverGeneric driver, String path); 55 EditGetFixesParams parameters, covariant AnalysisDriverGeneric driver);
37 56
38 @override 57 @override
39 Future<EditGetFixesResult> handleEditGetFixes( 58 Future<EditGetFixesResult> handleEditGetFixes(
40 EditGetFixesParams parameters) async { 59 EditGetFixesParams parameters) async {
41 String path = parameters.file; 60 String path = parameters.file;
42 ContextRoot contextRoot = contextRootContaining(path); 61 ContextRoot contextRoot = contextRootContaining(path);
43 if (contextRoot == null) { 62 if (contextRoot == null) {
44 // Return an error from the request. 63 // Return an error from the request.
45 throw new RequestFailure( 64 throw new RequestFailure(
46 RequestErrorFactory.pluginError('Failed to analyze $path', null)); 65 RequestErrorFactory.pluginError('Failed to analyze $path', null));
47 } 66 }
48 AnalysisDriverGeneric driver = driverMap[contextRoot]; 67 AnalysisDriverGeneric driver = driverMap[contextRoot];
49 ResolveResult analysisResult = await getResolveResultForFixes(driver, path); 68 FixesRequest request = await getFixesRequest(parameters, driver);
50 FixesRequestImpl request = new FixesRequestImpl(
51 resourceProvider, parameters.offset, analysisResult);
52 FixGenerator generator = new FixGenerator(getFixContributors(driver)); 69 FixGenerator generator = new FixGenerator(getFixContributors(driver));
53 GeneratorResult result = await generator.generateFixesResponse(request); 70 GeneratorResult result = await generator.generateFixesResponse(request);
54 result.sendNotifications(channel); 71 result.sendNotifications(channel);
55 return result.result; 72 return result.result;
56 } 73 }
57 } 74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698