@@ -242,7 +242,7 @@ private void onCheckCurrentProjectRequested(object sender, EventArgs e)
242242 JoinableTaskFactory . Run ( async ( ) =>
243243 {
244244 await JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
245- await checkFirstActiveProjectAsync ( ) ;
245+ _ = checkFirstActiveProjectAsync ( ) ;
246246 } ) ;
247247 }
248248
@@ -251,16 +251,28 @@ private void onCheckAllProjectsRequested(object sender, EventArgs e)
251251 JoinableTaskFactory . Run ( async ( ) =>
252252 {
253253 await JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
254- await checkAllActiveProjectsAsync ( ) ;
254+
255+ Object [ ] activeProjects = await getActiveProjectsAsync ( ) ;
256+ if ( activeProjects != null )
257+ _ = checkProjectsAsync ( activeProjects ) ;
255258 } ) ;
256259 }
257260
258261 private void onCheckSelectionsRequested ( object sender , EventArgs e )
259262 {
260263 JoinableTaskFactory . Run ( async ( ) =>
261264 {
262- await JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
263- await checkSelectionsAsync ( ) ;
265+ List < ConfiguredFiles > configuredFilesList = await getActiveSelectionsAsync ( ) ;
266+
267+ await _instance . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
268+
269+ MainToolWindow . Instance . ContentsType = ICodeAnalyzer . AnalysisType . ProjectAnalysis ;
270+ MainToolWindow . Instance . showIfWindowNotCreated ( ) ;
271+
272+ if ( configuredFilesList . Count > 0 )
273+ {
274+ runAnalysis ( configuredFilesList , false ) ;
275+ }
264276 } ) ;
265277 }
266278
@@ -279,69 +291,64 @@ private void documentSavedSync(Document document)
279291 {
280292 JoinableTaskFactory . Run ( async ( ) =>
281293 {
282- await documentSavedAsync ( document ) ;
283- } ) ;
284- }
285-
286- private async Task documentSavedAsync ( Document document )
287- {
288- await JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
289-
290- if ( document == null || document . Language != "C/C++" )
291- return ;
294+ await JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
292295
293- if ( Settings . Default . CheckSavedFilesHasValue && Settings . Default . CheckSavedFiles == false )
294- return ;
296+ if ( document == null || document . Language != "C/C++" )
297+ return ;
295298
296- if ( document . ActiveWindow == null )
297- {
298- // We get here when new files are being created and added to the project and
299- // then trying to obtain document.ProjectItem yields an exception. Will just skip this.
300- return ;
301- }
302- try
303- {
304- var kind = document . ProjectItem . ContainingProject . Kind ;
305- if ( ! isVisualCppProject ( document . ProjectItem . ContainingProject . Kind ) )
306- {
299+ if ( Settings . Default . CheckSavedFilesHasValue && Settings . Default . CheckSavedFiles == false )
307300 return ;
308- }
309301
310- Configuration currentConfig = null ;
311- try { currentConfig = document . ProjectItem . ConfigurationManager . ActiveConfiguration ; }
312- catch ( Exception ) { currentConfig = null ; }
313- if ( currentConfig == null )
302+ if ( document . ActiveWindow == null )
314303 {
315- MessageBox . Show ( "Cannot perform check - no valid configuration selected" , "Cppcheck error" ) ;
304+ // We get here when new files are being created and added to the project and
305+ // then trying to obtain document.ProjectItem yields an exception. Will just skip this.
316306 return ;
317307 }
318-
319- dynamic project = document . ProjectItem . ContainingProject . Object ;
320- SourceFile sourceForAnalysis = await createSourceFileAsync ( document . FullName , currentConfig , project ) ;
321- if ( sourceForAnalysis == null )
322- return ;
323-
324- if ( ! Settings . Default . CheckSavedFilesHasValue )
308+ try
325309 {
326- askCheckSavedFiles ( ) ;
310+ var kind = document . ProjectItem . ContainingProject . Kind ;
311+ if ( ! isVisualCppProject ( document . ProjectItem . ContainingProject . Kind ) )
312+ {
313+ return ;
314+ }
327315
328- if ( ! Settings . Default . CheckSavedFiles )
316+ Configuration currentConfig = null ;
317+ try { currentConfig = document . ProjectItem . ConfigurationManager . ActiveConfiguration ; }
318+ catch ( Exception ) { currentConfig = null ; }
319+ if ( currentConfig == null )
320+ {
321+ MessageBox . Show ( "Cannot perform check - no valid configuration selected" , "Cppcheck error" ) ;
329322 return ;
330- }
323+ }
331324
332- MainToolWindow . Instance . showIfWindowNotCreated ( ) ;
333- MainToolWindow . Instance . ContentsType = ICodeAnalyzer . AnalysisType . DocumentSavedAnalysis ;
334- runSavedFileAnalysis ( sourceForAnalysis , currentConfig ) ;
335- }
336- catch ( Exception ex )
337- {
338- if ( _outputPane != null )
325+ dynamic project = document . ProjectItem . ContainingProject . Object ;
326+ SourceFile sourceForAnalysis = await createSourceFileAsync ( document . FullName , currentConfig , project ) ;
327+ if ( sourceForAnalysis == null )
328+ return ;
329+
330+ if ( ! Settings . Default . CheckSavedFilesHasValue )
331+ {
332+ askCheckSavedFiles ( ) ;
333+
334+ if ( ! Settings . Default . CheckSavedFiles )
335+ return ;
336+ }
337+
338+ MainToolWindow . Instance . showIfWindowNotCreated ( ) ;
339+ MainToolWindow . Instance . ContentsType = ICodeAnalyzer . AnalysisType . DocumentSavedAnalysis ;
340+ runSavedFileAnalysis ( sourceForAnalysis , currentConfig ) ;
341+ }
342+ catch ( Exception ex )
339343 {
340- _outputPane . Clear ( ) ;
341- addTextToOutputWindow ( "Exception occurred in cppcheck add-in: " + ex . Message ) ;
344+ if ( _outputPane != null )
345+ {
346+ _outputPane . Clear ( ) ;
347+ addTextToOutputWindow ( "Exception occurred in cppcheck add-in: " + ex . Message ) ;
348+ }
349+ DebugTracer . Trace ( ex ) ;
342350 }
343- DebugTracer . Trace ( ex ) ;
344- }
351+ } ) ;
345352 }
346353
347354 public static void askCheckSavedFiles ( )
@@ -522,30 +529,6 @@ private async Task checkFirstActiveProjectAsync()
522529 _ = checkProjectsAsync ( new Object [ 1 ] { activeProjects [ 0 ] } ) ;
523530 }
524531
525- private async Task checkAllActiveProjectsAsync ( )
526- {
527- await JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
528-
529- Object [ ] activeProjects = await getActiveProjectsAsync ( ) ;
530- if ( activeProjects != null )
531- _ = checkProjectsAsync ( activeProjects ) ;
532- }
533-
534- private async Task checkSelectionsAsync ( )
535- {
536- List < ConfiguredFiles > configuredFilesList = await getActiveSelectionsAsync ( ) ;
537-
538- await _instance . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
539-
540- MainToolWindow . Instance . ContentsType = ICodeAnalyzer . AnalysisType . ProjectAnalysis ;
541- MainToolWindow . Instance . showIfWindowNotCreated ( ) ;
542-
543- if ( configuredFilesList . Count > 0 )
544- {
545- runAnalysis ( configuredFilesList , false ) ;
546- }
547- }
548-
549532 private async Task < List < SourceFile > > getProjectFilesAsync ( Project p , Configuration currentConfig )
550533 {
551534 await JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
@@ -767,7 +750,11 @@ private async void checkProgressUpdated(object sender, ICodeAnalyzer.ProgressEve
767750 {
768751 await System . Threading . Tasks . Task . Delay ( 5000 ) ;
769752 await JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
770- statusBar . Progress ( false , label , 100 , 100 ) ;
753+ try
754+ {
755+ statusBar . Progress ( false , label , 100 , 100 ) ;
756+ }
757+ catch ( Exception ) { }
771758 } ) ;
772759 }
773760 }
0 commit comments