@@ -61,23 +61,27 @@ public async Task<IEnumerable<IInspectionResult>> FindIssuesAsync(RubberduckPars
61
61
{
62
62
return new IInspectionResult [ ] { } ;
63
63
}
64
+ token . ThrowIfCancellationRequested ( ) ;
64
65
65
66
state . OnStatusMessageUpdate ( RubberduckUI . CodeInspections_Inspecting ) ;
66
67
var allIssues = new ConcurrentBag < IInspectionResult > ( ) ;
68
+ token . ThrowIfCancellationRequested ( ) ;
67
69
68
70
var config = _configService . LoadConfiguration ( ) ;
69
71
UpdateInspectionSeverity ( config ) ;
72
+ token . ThrowIfCancellationRequested ( ) ;
70
73
71
74
var parseTreeInspections = _inspections
72
75
. Where ( inspection => inspection . Severity != CodeInspectionSeverity . DoNotShow )
73
76
. OfType < IParseTreeInspection > ( )
74
77
. ToArray ( ) ;
78
+ token . ThrowIfCancellationRequested ( ) ;
75
79
76
- foreach ( var listener in parseTreeInspections . Select ( inspection => inspection . Listener ) )
80
+ foreach ( var listener in parseTreeInspections . Select ( inspection => inspection . Listener ) )
77
81
{
78
82
listener . ClearContexts ( ) ;
79
83
}
80
-
84
+
81
85
// Prepare ParseTreeWalker based inspections
82
86
var passes = Enum . GetValues ( typeof ( ParsePass ) ) . Cast < ParsePass > ( ) ;
83
87
foreach ( var parsePass in passes )
@@ -91,8 +95,10 @@ public async Task<IEnumerable<IInspectionResult>> FindIssuesAsync(RubberduckPars
91
95
LogManager . GetCurrentClassLogger ( ) . Warn ( e ) ;
92
96
}
93
97
}
98
+ token . ThrowIfCancellationRequested ( ) ;
94
99
95
100
var inspectionsToRun = _inspections . Where ( inspection => inspection . Severity != CodeInspectionSeverity . DoNotShow ) ;
101
+ token . ThrowIfCancellationRequested ( ) ;
96
102
97
103
try
98
104
{
@@ -102,13 +108,18 @@ public async Task<IEnumerable<IInspectionResult>> FindIssuesAsync(RubberduckPars
102
108
{
103
109
if ( exception . Flatten ( ) . InnerExceptions . All ( ex => ex is OperationCanceledException ) )
104
110
{
105
- LogManager . GetCurrentClassLogger ( ) . Debug ( "Inspections got canceled." ) ;
111
+ //This eliminates the stack trace, but for the cancellation, this is irrelevant.
112
+ throw exception . InnerException ?? exception ;
106
113
}
107
114
else
108
115
{
109
116
LogManager . GetCurrentClassLogger ( ) . Error ( exception ) ;
110
117
}
111
118
}
119
+ catch ( OperationCanceledException )
120
+ {
121
+ throw ;
122
+ }
112
123
catch ( Exception e )
113
124
{
114
125
LogManager . GetCurrentClassLogger ( ) . Error ( e ) ;
@@ -137,21 +148,27 @@ private static void RunInspectionsInParallel(IEnumerable<IInspection> inspection
137
148
138
149
Parallel . ForEach ( inspectionsToRun ,
139
150
options ,
140
- inspection => RunInspection ( inspection , allIssues )
151
+ inspection => RunInspection ( inspection , allIssues , token )
141
152
) ;
142
153
}
143
154
144
- private static void RunInspection ( IInspection inspection , ConcurrentBag < IInspectionResult > allIssues )
155
+ private static void RunInspection ( IInspection inspection , ConcurrentBag < IInspectionResult > allIssues , CancellationToken token )
145
156
{
146
157
try
147
158
{
148
159
var inspectionResults = inspection . GetInspectionResults ( ) ;
149
160
161
+ token . ThrowIfCancellationRequested ( ) ;
162
+
150
163
foreach ( var inspectionResult in inspectionResults )
151
164
{
152
165
allIssues . Add ( inspectionResult ) ;
153
166
}
154
167
}
168
+ catch ( OperationCanceledException )
169
+ {
170
+ throw ;
171
+ }
155
172
catch ( Exception e )
156
173
{
157
174
LogManager . GetCurrentClassLogger ( ) . Warn ( e ) ;
0 commit comments