@@ -53,9 +53,10 @@ public IEnumerable<IQuickFix> QuickFixes(IInspectionResult result)
53
53
. OrderBy ( fix => fix . SupportedInspections . Count ) ; // most specific fixes first; keeps "ignore once" last
54
54
}
55
55
56
- private bool CanFix ( IQuickFix fix , IInspectionResult result )
56
+ public bool CanFix ( IQuickFix fix , IInspectionResult result )
57
57
{
58
- return QuickFixes ( result ) . Contains ( fix ) ;
58
+ return fix . SupportedInspections . Contains ( result . Inspection . GetType ( ) )
59
+ && ! result . DisabledQuickFixes . Contains ( fix . GetType ( ) . Name ) ;
59
60
}
60
61
61
62
public void Fix ( IQuickFix fix , IInspectionResult result )
@@ -77,40 +78,17 @@ public void Fix(IQuickFix fix, IInspectionResult result)
77
78
Apply ( rewriteSession ) ;
78
79
}
79
80
80
- private void Apply ( IExecutableRewriteSession rewriteSession )
81
- {
82
- if ( ! rewriteSession . TryRewrite ( ) )
83
- {
84
- _failureNotifier . NotifyQuickFixExecutionFailure ( rewriteSession . Status ) ;
85
- }
86
- }
87
-
88
- private IExecutableRewriteSession RewriteSession ( CodeKind targetCodeKind )
89
- {
90
- switch ( targetCodeKind )
91
- {
92
- case CodeKind . CodePaneCode :
93
- return _rewritingManager . CheckOutCodePaneSession ( ) ;
94
- case CodeKind . AttributesCode :
95
- return _rewritingManager . CheckOutAttributesSession ( ) ;
96
- default :
97
- throw new NotSupportedException ( nameof ( targetCodeKind ) ) ;
98
- }
99
- }
100
-
101
- public void FixInProcedure ( IQuickFix fix , QualifiedMemberName ? qualifiedMember , Type inspectionType , IEnumerable < IInspectionResult > results )
81
+ public void Fix ( IQuickFix fix , IEnumerable < IInspectionResult > resultsToFix )
102
82
{
103
- Debug . Assert ( qualifiedMember . HasValue , "Null qualified member." ) ;
83
+ var results = resultsToFix . ToList ( ) ;
104
84
105
- var filteredResults = results . Where ( result => result . Inspection . GetType ( ) == inspectionType && result . QualifiedMemberName == qualifiedMember ) . ToList ( ) ;
106
-
107
- if ( ! filteredResults . Any ( ) )
85
+ if ( ! results . Any ( ) )
108
86
{
109
87
return ;
110
88
}
111
89
112
90
var rewriteSession = RewriteSession ( fix . TargetCodeKind ) ;
113
- foreach ( var result in filteredResults )
91
+ foreach ( var result in results )
114
92
{
115
93
if ( ! CanFix ( fix , result ) )
116
94
{
@@ -122,70 +100,63 @@ public void FixInProcedure(IQuickFix fix, QualifiedMemberName? qualifiedMember,
122
100
Apply ( rewriteSession ) ;
123
101
}
124
102
125
- public void FixInModule ( IQuickFix fix , QualifiedSelection selection , Type inspectionType , IEnumerable < IInspectionResult > results )
103
+ private void Apply ( IExecutableRewriteSession rewriteSession )
126
104
{
127
- var filteredResults = results . Where ( result => result . Inspection . GetType ( ) == inspectionType && result . QualifiedSelection . QualifiedName == selection . QualifiedName ) . ToList ( ) ;
128
-
129
- if ( ! filteredResults . Any ( ) )
105
+ if ( ! rewriteSession . TryRewrite ( ) )
130
106
{
131
- return ;
107
+ _failureNotifier . NotifyQuickFixExecutionFailure ( rewriteSession . Status ) ;
132
108
}
109
+ }
133
110
134
- var rewriteSession = RewriteSession ( fix . TargetCodeKind ) ;
135
- foreach ( var result in filteredResults )
111
+ private IExecutableRewriteSession RewriteSession ( CodeKind targetCodeKind )
112
+ {
113
+ switch ( targetCodeKind )
136
114
{
137
- if ( ! CanFix ( fix , result ) )
138
- {
139
- continue ;
140
- }
141
-
142
- fix . Fix ( result , rewriteSession ) ;
115
+ case CodeKind . CodePaneCode :
116
+ return _rewritingManager . CheckOutCodePaneSession ( ) ;
117
+ case CodeKind . AttributesCode :
118
+ return _rewritingManager . CheckOutAttributesSession ( ) ;
119
+ default :
120
+ throw new NotSupportedException ( nameof ( targetCodeKind ) ) ;
143
121
}
144
- Apply ( rewriteSession ) ;
145
122
}
146
123
147
- public void FixInProject ( IQuickFix fix , QualifiedSelection selection , Type inspectionType , IEnumerable < IInspectionResult > results )
124
+ public void FixInProcedure ( IQuickFix fix , QualifiedMemberName ? qualifiedMember , Type inspectionType , IEnumerable < IInspectionResult > allResults )
148
125
{
149
- var filteredResults = results . Where ( result => result . Inspection . GetType ( ) == inspectionType && result . QualifiedSelection . QualifiedName . ProjectId == selection . QualifiedName . ProjectId ) . ToList ( ) ;
126
+ Debug . Assert ( qualifiedMember . HasValue , "Null qualified member." ) ;
150
127
151
- if ( ! filteredResults . Any ( ) )
152
- {
153
- return ;
154
- }
128
+ var filteredResults = allResults
129
+ . Where ( result => result . Inspection . GetType ( ) == inspectionType
130
+ && result . QualifiedMemberName == qualifiedMember ) ;
155
131
156
- var rewriteSession = RewriteSession ( fix . TargetCodeKind ) ;
157
- foreach ( var result in filteredResults )
158
- {
159
- if ( ! CanFix ( fix , result ) )
160
- {
161
- continue ;
162
- }
132
+ Fix ( fix , filteredResults ) ;
133
+ }
163
134
164
- fix . Fix ( result , rewriteSession ) ;
165
- }
166
- Apply ( rewriteSession ) ;
135
+ public void FixInModule ( IQuickFix fix , QualifiedSelection selection , Type inspectionType , IEnumerable < IInspectionResult > allResults )
136
+ {
137
+ var filteredResults = allResults
138
+ . Where ( result => result . Inspection . GetType ( ) == inspectionType
139
+ && result . QualifiedSelection . QualifiedName == selection . QualifiedName ) ;
140
+
141
+ Fix ( fix , filteredResults ) ;
167
142
}
168
143
169
- public void FixAll ( IQuickFix fix , Type inspectionType , IEnumerable < IInspectionResult > results )
144
+ public void FixInProject ( IQuickFix fix , QualifiedSelection selection , Type inspectionType , IEnumerable < IInspectionResult > allResults )
170
145
{
171
- var filteredResults = results . Where ( result => result . Inspection . GetType ( ) == inspectionType ) . ToArray ( ) ;
146
+ var filteredResults = allResults
147
+ . Where ( result => result . Inspection . GetType ( ) == inspectionType
148
+ && result . QualifiedSelection . QualifiedName . ProjectId == selection . QualifiedName . ProjectId )
149
+ . ToList ( ) ;
172
150
173
- if ( ! filteredResults . Any ( ) )
174
- {
175
- return ;
176
- }
151
+ Fix ( fix , filteredResults ) ;
152
+ }
177
153
178
- var rewriteSession = RewriteSession ( fix . TargetCodeKind ) ;
179
- foreach ( var result in filteredResults )
180
- {
181
- if ( ! CanFix ( fix , result ) )
182
- {
183
- continue ;
184
- }
154
+ public void FixAll ( IQuickFix fix , Type inspectionType , IEnumerable < IInspectionResult > allResults )
155
+ {
156
+ var filteredResults = allResults
157
+ . Where ( result => result . Inspection . GetType ( ) == inspectionType ) ;
185
158
186
- fix . Fix ( result , rewriteSession ) ;
187
- }
188
- Apply ( rewriteSession ) ;
159
+ Fix ( fix , filteredResults ) ;
189
160
}
190
161
191
162
public bool HasQuickFixes ( IInspectionResult inspectionResult )
0 commit comments