Skip to content

Commit 93f99f4

Browse files
committed
Defer reference usage determination until parser is ready.
1 parent 408959e commit 93f99f4

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,28 @@ private void HandleStateChanged(object sender, ParserStateEventArgs e)
318318
Projects = new ObservableCollection<CodeExplorerItemViewModel>();
319319
}
320320

321+
if (e.State == ParserState.Ready)
322+
{
323+
// Finished up resolving references, so we can now update the reference nodes.
324+
var referenceFolders = Projects.SelectMany(node => node.Items.OfType<CodeExplorerReferenceFolderViewModel>());
325+
foreach (var library in referenceFolders.SelectMany(folder => folder.Items).OfType<CodeExplorerReferenceViewModel>())
326+
{
327+
var reference = library.Reference;
328+
if (reference == null)
329+
{
330+
continue;
331+
}
332+
333+
reference.IsUsed = reference.IsBuiltIn ||
334+
_state.DeclarationFinder.IsReferenceUsedInProject(
335+
library.Parent?.Declaration as ProjectDeclaration,
336+
reference.ToReferenceInfo());
337+
library.IsDimmed = !reference.IsUsed;
338+
}
339+
340+
return;
341+
}
342+
321343
IsBusy = _state.Status != ParserState.Pending && _state.Status <= ParserState.ResolvedDeclarations;
322344

323345
if (e.State != ParserState.ResolvedDeclarations)

Rubberduck.Core/UI/AddRemoveReferences/AddRemoveReferencesPresenterFactory.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ public AddRemoveReferencesPresenter Create(ProjectDeclaration project)
8787
foreach (var reference in references)
8888
{
8989
var guid = Guid.TryParse(reference.Guid, out var result) ? result : Guid.Empty;
90+
91+
// This avoids collisions when the parse actually succeeds, but the result is empty.
92+
if (guid.Equals(Guid.Empty))
93+
{
94+
guid = new Guid(priority, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
95+
}
96+
9097
var libraryId = new RegisteredLibraryKey(guid, reference.Major, reference.Minor);
9198

9299
// TODO: If for some reason the VBA reference is broken, we could technically use this to repair it. Just a thought...

Rubberduck.Core/UI/CodeExplorer/Commands/CodeExplorerFindAllReferencesCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected override void OnExecute(object parameter)
4141
{
4242
return;
4343
}
44-
_finder.FindAllReferences(node.Declaration, model.ToReferenceInfo());
44+
_finder.FindAllReferences(node.Parent.Declaration, model.ToReferenceInfo());
4545
return;
4646
}
4747

0 commit comments

Comments
 (0)