Skip to content

Commit 42eb405

Browse files
committed
Remove untracked (non-node) references from list.
1 parent 94abffc commit 42eb405

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public class CodeExplorerProjectViewModel : CodeExplorerItemViewModel
2222

2323
private readonly IVBE _vbe;
2424

25-
public CodeExplorerProjectViewModel(Declaration declaration, IEnumerable<Declaration> declarations, RubberduckParserState state, IVBE vbe, bool references = true) : base(null, declaration)
25+
public CodeExplorerProjectViewModel(Declaration project, List<Declaration> declarations, RubberduckParserState state, IVBE vbe, bool references = true) : base(null, project)
2626
{
2727
State = state;
2828
_vbe = vbe;
2929
ShowReferences = references;
3030

3131
SetName();
32-
AddNewChildren(declarations.ToList());
32+
AddNewChildren(ExtractTrackedDeclarationsForProject(project, declarations));
3333
IsExpanded = true;
3434
}
3535

@@ -75,7 +75,7 @@ public override void Synchronize(List<Declaration> updated)
7575

7676
Declaration = match;
7777
updated.Remove(Declaration);
78-
var children = updated.Where(declaration => declaration.ProjectId.Equals(Declaration.ProjectId)).ToList();
78+
var children = ExtractTrackedDeclarationsForProject(Declaration, updated);
7979
updated.RemoveAll(declaration => declaration.ProjectId.Equals(Declaration.ProjectId));
8080

8181
// Reference synchronization is deferred to AddNewChildren for 2 reasons. First, it doesn't make sense to sling around a List of
@@ -129,7 +129,7 @@ private void SynchronizeReferences()
129129

130130
foreach (var type in types)
131131
{
132-
AddChild(new CodeExplorerReferenceFolderViewModel(this, State.DeclarationFinder, type.ToList(), type.Key));
132+
AddChild(new CodeExplorerReferenceFolderViewModel(this, State?.DeclarationFinder, type.ToList(), type.Key));
133133
}
134134
}
135135

@@ -170,5 +170,35 @@ private void SetName()
170170

171171
OnNameChanged();
172172
}
173+
174+
private static readonly List<DeclarationType> UntrackedTypes = new List<DeclarationType>
175+
{
176+
DeclarationType.Parameter,
177+
DeclarationType.LineLabel,
178+
DeclarationType.UnresolvedMember,
179+
DeclarationType.BracketedExpression,
180+
DeclarationType.ComAlias
181+
};
182+
183+
private static readonly List<DeclarationType> ModuleRestrictedTypes = new List<DeclarationType>
184+
{
185+
DeclarationType.Variable,
186+
DeclarationType.Control,
187+
DeclarationType.Constant
188+
};
189+
190+
public static List<Declaration> ExtractTrackedDeclarationsForProject(Declaration project, List<Declaration> declarations)
191+
{
192+
var owned = declarations.Where(declaration => declaration.ProjectId.Equals(project.ProjectId)).ToList();
193+
194+
foreach (var declaration in owned)
195+
{
196+
declarations.Remove(declaration);
197+
}
198+
199+
return owned.Where(declaration => !UntrackedTypes.Contains(declaration.DeclarationType) &&
200+
!ModuleRestrictedTypes.Contains(declaration.DeclarationType) ||
201+
declaration.ParentDeclaration.DeclarationType.HasFlag(DeclarationType.Module)).ToList();
202+
}
173203
}
174204
}

0 commit comments

Comments
 (0)