Skip to content

Commit d372794

Browse files
committed
Wire up inspection result invalidation in the InspectionResultsViewModel
The invalidation is currently only used if the inspections do not get run; running the inspections overwrites the collection anyway. Moreover, currently all results get invalidated unconditionally.
1 parent bade5bc commit d372794

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Rubberduck.Core/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
using Rubberduck.Parsing.Inspections.Abstract;
1515
using Rubberduck.Parsing.UIContext;
1616
using Rubberduck.Parsing.VBA;
17+
using Rubberduck.Parsing.VBA.Extensions;
1718
using Rubberduck.Settings;
1819
using Rubberduck.UI.Command;
19-
using Rubberduck.UI.Controls;
2020
using Rubberduck.UI.Settings;
21+
using Rubberduck.VBEditor;
2122

2223
namespace Rubberduck.UI.Inspections
2324
{
@@ -383,6 +384,12 @@ private void HandleStateChanged(object sender, ParserStateEventArgs e)
383384
{
384385
RefreshInspections(e.Token);
385386
}
387+
else
388+
{
389+
//Todo: Find a way to get the actually modified modules in here.
390+
var modifiedModules = _state.DeclarationFinder.AllModules.ToHashSet();
391+
InvalidateStaleInspectionResults(modifiedModules);
392+
}
386393
}
387394

388395
private async void RefreshInspections(CancellationToken token)
@@ -442,6 +449,18 @@ private async void RefreshInspections(CancellationToken token)
442449
LogManager.GetCurrentClassLogger().Trace("Inspections loaded in {0}ms", stopwatch.ElapsedMilliseconds);
443450
}
444451

452+
private void InvalidateStaleInspectionResults(ICollection<QualifiedModuleName> modifiedModules)
453+
{
454+
var staleResults = Results.Where(result => result.ChangesInvalidateResult(modifiedModules)).ToList();
455+
_uiDispatcher.Invoke(() =>
456+
{
457+
foreach (var staleResult in staleResults)
458+
{
459+
Results.Remove(staleResult);
460+
}
461+
});
462+
}
463+
445464
private void ExecuteQuickFixCommand(object parameter)
446465
{
447466
var quickFix = parameter as IQuickFix;

0 commit comments

Comments
 (0)