Skip to content

Commit 3f308b3

Browse files
committed
Build serializable tree after collection.
1 parent a2580e1 commit 3f308b3

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Rubberduck.Parsing/Symbols/AliasDeclarations.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class AliasDeclarations : ICustomDeclarationLoader
1414
private Declaration _fileSystemModule;
1515
private Declaration _interactionModule;
1616
private Declaration _stringsModule;
17-
17+
private Declaration _dateTimeModule;
1818

1919
public AliasDeclarations(RubberduckParserState state)
2020
{
@@ -79,6 +79,9 @@ private void UpdateAliasFunctionModulesFromReferencedProjects(RubberduckParserSt
7979

8080
_stringsModule = state.AllDeclarations.SingleOrDefault(
8181
item => item.IdentifierName == "Strings" && item.Scope == "VBE7.DLL;VBA.Strings");
82+
83+
_dateTimeModule = state.AllDeclarations.SingleOrDefault(
84+
item => item.IdentifierName == "DateTime" && item.Scope == "VBE7.DLL;VBA.DateTime");
8285
}
8386

8487

Rubberduck.Parsing/Symbols/SerializableDeclaration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class SerializableDeclarationTree
1414
public readonly SerializableDeclaration Node;
1515

1616
[DataMember(IsRequired = true)]
17-
public readonly IEnumerable<SerializableDeclarationTree> Children;
17+
public IEnumerable<SerializableDeclarationTree> Children;
1818

1919
public SerializableDeclarationTree(Declaration declaration)
2020
: this(new SerializableDeclaration(declaration)) { }

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,12 @@ private void SyncComReferences(IReadOnlyList<IVBProject> projects)
433433
try
434434
{
435435
var comReflector = new ReferencedDeclarationsCollector(State);
436-
SerializableDeclarationTree tree;
437-
var items = comReflector.GetDeclarationsForReference(localReference, out tree);
436+
437+
var items = comReflector.GetDeclarationsForReference(localReference);
438+
var root = items.SingleOrDefault(x => x.DeclarationType == DeclarationType.Project);
439+
var serialize = new List<Declaration>(items);
440+
var tree = GetSerializableTreeForDeclaration(root, serialize);
441+
438442
if (tree != null)
439443
{
440444
State.BuiltInDeclarationTrees.Add(tree);
@@ -486,6 +490,21 @@ private void SyncComReferences(IReadOnlyList<IVBProject> projects)
486490
}
487491
}
488492

493+
private SerializableDeclarationTree GetSerializableTreeForDeclaration(Declaration declaration, List<Declaration> declarations)
494+
{
495+
var output = new SerializableDeclarationTree(declaration);
496+
var children = new List<SerializableDeclarationTree>();
497+
var nodes = declarations.Where(x => x.ParentDeclaration.Equals(declaration)).ToList();
498+
declarations.RemoveAll(nodes.Contains);
499+
foreach (var item in nodes)
500+
{
501+
children.Add(GetSerializableTreeForDeclaration(item, declarations));
502+
}
503+
504+
output.Children = children;
505+
return output;
506+
}
507+
489508
private void UnloadComReference(IReference reference, IReadOnlyList<IVBProject> projects)
490509
{
491510
var referencedProjectId = GetReferenceProjectId(reference, projects);

0 commit comments

Comments
 (0)