OLD | NEW |
1 # Providing Quick Fixes | 1 # Providing Quick Fixes |
2 | 2 |
3 A quick fix is used by clients to provide a set of possible changes to code that | 3 A quick fix is used by clients to provide a set of possible changes to code that |
4 are based on diagnostics reported against the code. Quick fixes are intended to | 4 are based on diagnostics reported against the code. Quick fixes are intended to |
5 help users resolve the issue being reported. | 5 help users resolve the issue being reported. |
6 | 6 |
7 If your plugin generates any diagnostics then you should consider providing | 7 If your plugin generates any diagnostics then you should consider providing |
8 support for automatically fixing those diagnostics. There is often more than one | 8 support for automatically fixing those diagnostics. There is often more than one |
9 potential way of fixing a given problem, so it is possible for your plugin to | 9 potential way of fixing a given problem, so it is possible for your plugin to |
10 provide multiple fixes for a single problem. | 10 provide multiple fixes for a single problem. |
(...skipping 30 matching lines...) Expand all Loading... |
41 and `DartFixesMixin` (from `package:analyzer_plugin/plugin/fix_mixin.dart`) to | 41 and `DartFixesMixin` (from `package:analyzer_plugin/plugin/fix_mixin.dart`) to |
42 the list of mixins for your subclass of `ServerPlugin`. This will leave you with | 42 the list of mixins for your subclass of `ServerPlugin`. This will leave you with |
43 one abstract method that you need to implement: `getFixContributors`. That | 43 one abstract method that you need to implement: `getFixContributors`. That |
44 method is responsible for returning a list of `FixContributor`s. It is the fix | 44 method is responsible for returning a list of `FixContributor`s. It is the fix |
45 contributors that produce the actual fixes. (Most plugins will only need a | 45 contributors that produce the actual fixes. (Most plugins will only need a |
46 single fix contributor.) | 46 single fix contributor.) |
47 | 47 |
48 To write a fix contributor, create a class that implements `FixContributor`. The | 48 To write a fix contributor, create a class that implements `FixContributor`. The |
49 interface defines a single method named `computeFixes`. The method has two | 49 interface defines a single method named `computeFixes`. The method has two |
50 arguments: a `FixesRequest` that describes the errors that should be fixed and a | 50 arguments: a `FixesRequest` that describes the errors that should be fixed and a |
51 `FixCollector` through which fixes are to be added. (If you use the mixins above | 51 `FixCollector` through which fixes are to be added. |
52 then the list of errors available through the request object will only include | 52 |
53 the errors for which fixes should be returned.) | 53 If you mix in the class `DartFixesMixin`, then the list of errors available |
| 54 through the request object will only include the errors for which fixes should |
| 55 be returned and the request will be an instance of `DartFixesRequest`, which |
| 56 also has analysis results. |
54 | 57 |
55 The class `FixContributorMixin` defines a simple implementation of this method | 58 The class `FixContributorMixin` defines a simple implementation of this method |
56 that captures the two arguments in fields, iterates through the errors, and | 59 that captures the two arguments in fields, iterates through the errors, and |
57 invokes a method named `computeFixesForError` for each of the errors for which | 60 invokes a method named `computeFixesForError` for each of the errors for which |
58 fixes are to be computed. | 61 fixes are to be computed. |
59 | 62 |
60 ## Example | 63 ## Example |
61 | 64 |
62 Start by creating a class that implements `FixContributor` and that mixes in the | 65 Start by creating a class that implements `FixContributor` and that mixes in the |
63 class `FixContributorMixin`, then implement the method `computeFixesForError`. | 66 class `FixContributorMixin`, then implement the method `computeFixesForError`. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 115 |
113 @override | 116 @override |
114 List<FixContributor> getFixContributors( | 117 List<FixContributor> getFixContributors( |
115 AnalysisDriverGeneric driver) { | 118 AnalysisDriverGeneric driver) { |
116 return <FixContributor>[new MyFixContributor()]; | 119 return <FixContributor>[new MyFixContributor()]; |
117 } | 120 } |
118 } | 121 } |
119 ``` | 122 ``` |
120 | 123 |
121 [creatingEdits]: creating_edits.md | 124 [creatingEdits]: creating_edits.md |
OLD | NEW |