Skip to content

Commit 20968e1

Browse files
committed
Merge branch 'next' into RecoveringMemberAttributes
# Conflicts: # Rubberduck.Resources/RubberduckUI.de.resx Also fixes the case of the license file reference in Rubberduck.Deployment.Build/RubberduckPreBuildTask.cs
2 parents 333c89a + f56d14a commit 20968e1

File tree

113 files changed

+8311
-1208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+8311
-1208
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ If you like this project and would like to thank its contributors, you are welco
1717
[masterBuildStatus]:https://ci.appveyor.com/api/projects/status/we3pdnkeebo4nlck/branch/master?svg=true
1818
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/Rubberduck-vba/rubberduck.svg)](http://isitmaintained.com/project/Rubberduck-vba/rubberduck "Average time to resolve an issue")
1919
[![Percentage of issues still open](http://isitmaintained.com/badge/open/Rubberduck-vba/rubberduck.svg)](http://isitmaintained.com/project/Rubberduck-vba/rubberduck "Percentage of issues still open")
20+
[![Chat on stackexchange](https://img.shields.io/badge/chat-on%20stackexchange-blue.svg)](https://chat.stackexchange.com/rooms/14929/vba-rubberducking)
21+
[![License](https://img.shields.io/github/license/rubberduck-vba/Rubberduck.svg)](https://github.com/rubberduck-vba/Rubberduck/blob/next/LICENSE)
2022

2123
> **[rubberduckvba.com](http://rubberduckvba.com)** [Wiki](https://github.com/rubberduck-vba/Rubberduck/wiki) [Rubberduck News](https://rubberduckvba.wordpress.com/)
2224
> devs@rubberduckvba.com

Rubberduck.CodeAnalysis/Inspections/Concrete/NonReturningFunctionInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
5151
private bool IsAssignedByRefArgument(Declaration enclosingProcedure, IdentifierReference reference)
5252
{
5353
var argExpression = reference.Context.GetAncestor<VBAParser.ArgumentExpressionContext>();
54-
var parameter = State.DeclarationFinder.FindParameterFromArgument(argExpression, enclosingProcedure);
54+
var parameter = State.DeclarationFinder.FindParameterOfNonDefaultMemberFromSimpleArgumentNotPassedByValExplicitly(argExpression, enclosingProcedure);
5555

5656
// note: not recursive, by design.
5757
return parameter != null

Rubberduck.CodeAnalysis/Inspections/Concrete/ParameterCanBeByValInspection.cs

Lines changed: 167 additions & 91 deletions
Large diffs are not rendered by default.

Rubberduck.CodeAnalysis/Inspections/Concrete/UnassignedVariableUsageInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
5454
private bool IsAssignedByRefArgument(Declaration enclosingProcedure, IdentifierReference reference)
5555
{
5656
var argExpression = reference.Context.GetAncestor<VBAParser.ArgumentExpressionContext>();
57-
var parameter = State.DeclarationFinder.FindParameterFromArgument(argExpression, enclosingProcedure);
57+
var parameter = State.DeclarationFinder.FindParameterOfNonDefaultMemberFromSimpleArgumentNotPassedByValExplicitly(argExpression, enclosingProcedure);
5858

5959
// note: not recursive, by design.
6060
return parameter != null

Rubberduck.CodeAnalysis/Inspections/Concrete/VariableNotAssignedInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
3737
private bool IsAssignedByRefArgument(Declaration enclosingProcedure, IdentifierReference reference)
3838
{
3939
var argExpression = reference.Context.GetAncestor<VBAParser.ArgumentExpressionContext>();
40-
var parameter = State.DeclarationFinder.FindParameterFromArgument(argExpression, enclosingProcedure);
40+
var parameter = State.DeclarationFinder.FindParameterOfNonDefaultMemberFromSimpleArgumentNotPassedByValExplicitly(argExpression, enclosingProcedure);
4141

4242
// note: not recursive, by design.
4343
return parameter != null

Rubberduck.Core/AddRemoveReferences/ReferenceModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public bool Matches(ReferenceInfo info)
183183
FullPath.Equals(info.FullPath, StringComparison.OrdinalIgnoreCase) ||
184184
FullPath32.Equals(info.FullPath, StringComparison.OrdinalIgnoreCase) ||
185185
FullPath64.Equals(info.FullPath, StringComparison.OrdinalIgnoreCase) ||
186-
Guid.Equals(info.Guid);
186+
!Guid.Equals(Guid.Empty) && Guid.Equals(info.Guid);
187187
}
188188

189189
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")

Rubberduck.Core/CodeAnalysis/CodeMetrics/CodeMetricsViewModel.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,37 @@ private void OnStateChanged(object sender, ParserStateEventArgs e)
5454
Unparsed = false;
5555
IsBusy = _state.Status != ParserState.Pending && _state.Status <= ParserState.ResolvedDeclarations;
5656

57-
if (e.State != ParserState.ResolvedDeclarations)
57+
if (e.State == ParserState.ResolvedDeclarations)
5858
{
59-
return;
59+
Synchronize(_state.DeclarationFinder.AllUserDeclarations);
6060
}
61-
62-
Synchronize(_state.DeclarationFinder.AllUserDeclarations.ToList());
6361
}
6462

65-
private void Synchronize(List<Declaration> declarations)
63+
private void Synchronize(IEnumerable<Declaration> declarations)
6664
{
6765
var metricResults = _analyst.GetMetrics(_state);
6866
_resultsByDeclaration = metricResults.GroupBy(r => r.Declaration).ToDictionary(g => g.Key, g => g.ToList());
6967

7068
_uiDispatcher.Invoke(() =>
7169
{
70+
var updates = declarations.ToList();
7271
var existing = Projects.OfType<CodeExplorerProjectViewModel>().ToList();
7372

7473
foreach (var project in existing)
7574
{
76-
project.Synchronize(declarations);
75+
project.Synchronize(ref updates);
7776
if (project.Declaration is null)
7877
{
7978
Projects.Remove(project);
8079
}
8180
}
8281

83-
var adding = declarations.OfType<ProjectDeclaration>().ToList();
82+
var adding = updates.OfType<ProjectDeclaration>().ToList();
8483

8584
foreach (var project in adding)
8685
{
87-
var model = new CodeExplorerProjectViewModel(project, declarations.Where(proj => proj.ProjectId.Equals(project.ProjectId)).ToList(), _state, _vbe, false);
86+
var model = new CodeExplorerProjectViewModel(project, ref updates, _state, _vbe, false);
8887
Projects.Add(model);
89-
model.IsExpanded = true;
9088
}
9189
});
9290
}

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerComponentViewModel.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public sealed class CodeExplorerComponentViewModel : CodeExplorerItemViewModel
3030

3131
private readonly IVBE _vbe;
3232

33-
public CodeExplorerComponentViewModel(ICodeExplorerNode parent, Declaration declaration, IEnumerable<Declaration> declarations, IVBE vbe)
33+
public CodeExplorerComponentViewModel(ICodeExplorerNode parent, Declaration declaration, ref List<Declaration> declarations, IVBE vbe)
3434
: base(parent, declaration)
3535
{
3636
_vbe = vbe;
3737
SetName();
38-
AddNewChildren(declarations.ToList());
38+
AddNewChildren(ref declarations);
3939
}
4040

4141
private string _name;
@@ -54,9 +54,9 @@ public CodeExplorerComponentViewModel(ICodeExplorerNode parent, Declaration decl
5454
public bool IsTestModule => Declaration.DeclarationType == DeclarationType.ProceduralModule
5555
&& Declaration.Annotations.Any(annotation => annotation.AnnotationType == AnnotationType.TestModule);
5656

57-
public override void Synchronize(List<Declaration> updated)
57+
public override void Synchronize(ref List<Declaration> updated)
5858
{
59-
base.Synchronize(updated);
59+
base.Synchronize(ref updated);
6060
if (Declaration is null)
6161
{
6262
return;
@@ -66,18 +66,23 @@ public override void Synchronize(List<Declaration> updated)
6666
SetName();
6767
}
6868

69-
protected override void AddNewChildren(List<Declaration> updated)
69+
protected override void AddNewChildren(ref List<Declaration> updated)
7070
{
7171
if (updated is null)
7272
{
7373
return;
7474
}
7575

76-
AddChildren(updated.GroupBy(item => item.Scope).SelectMany(grouping =>
77-
grouping.Where(item =>
78-
item.ParentDeclaration != null && item.ParentScope == Declaration.Scope &&
79-
MemberTypes.Contains(item.DeclarationType))
80-
.Select(item => new CodeExplorerMemberViewModel(this, item, grouping))));
76+
var children = updated.Where(declaration =>
77+
!ReferenceEquals(Declaration, declaration) &&
78+
declaration.QualifiedModuleName.Equals(Declaration?.QualifiedModuleName)).ToList();
79+
80+
updated = updated.Except(children.Concat(new [] { Declaration })).ToList();
81+
82+
foreach (var member in children.Where(declaration => MemberTypes.Contains(declaration.DeclarationType)).ToList())
83+
{
84+
AddChild(new CodeExplorerMemberViewModel(this, member, ref children));
85+
}
8186
}
8287

8388
private void SetName()
@@ -96,8 +101,7 @@ private void SetName()
96101
switch (qualifiedModuleName.ComponentType)
97102
{
98103
case ComponentType.Document:
99-
100-
using (var app = _vbe.HostApplication())
104+
using (var app = _vbe?.HostApplication())
101105
{
102106
var parenthesized = app?.GetDocument(qualifiedModuleName)?.DocumentName ?? string.Empty;
103107
_name = string.IsNullOrEmpty(parenthesized) ? _name : $"{_name} ({parenthesized})";

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerCustomFolderViewModel.cs

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Rubberduck.Navigation.CodeExplorer
1010
{
11-
[DebuggerDisplay("{Name}")]
11+
[DebuggerDisplay("{" + nameof(Name) + "}")]
1212
public sealed class CodeExplorerCustomFolderViewModel : CodeExplorerItemViewModel
1313
{
1414
private static readonly DeclarationType[] ComponentTypes =
@@ -26,14 +26,14 @@ public CodeExplorerCustomFolderViewModel(
2626
string name,
2727
string fullPath,
2828
IVBE vbe,
29-
IEnumerable<Declaration> declarations) : base(parent, parent?.Declaration)
29+
ref List<Declaration> declarations) : base(parent, parent?.Declaration)
3030
{
3131
_vbe = vbe;
3232
FolderDepth = parent is CodeExplorerCustomFolderViewModel folder ? folder.FolderDepth + 1 : 1;
3333
FullPath = fullPath?.Trim('"') ?? string.Empty;
3434
Name = name.Replace("\"", string.Empty);
3535

36-
AddNewChildren(declarations.ToList());
36+
AddNewChildren(ref declarations);
3737
}
3838

3939
public override string Name { get; }
@@ -61,86 +61,78 @@ public override bool IsErrorState
6161

6262
public override Comparer<ICodeExplorerNode> SortComparer => CodeExplorerItemComparer.Name;
6363

64-
public override bool Filtered => false;
65-
66-
protected override void AddNewChildren(List<Declaration> declarations)
64+
protected override void AddNewChildren(ref List<Declaration> declarations)
6765
{
68-
var children = declarations.Where(declaration => declaration.IsInSubFolder(FullPath)).ToList();
66+
var children = declarations.Where(declaration => declaration.IsInFolderOrSubFolder(FullPath)).ToList();
67+
declarations = declarations.Except(children).ToList();
68+
69+
var subFolders = children.Where(declaration => declaration.IsInSubFolder(FullPath)).ToList();
6970

70-
foreach (var folder in children.GroupBy(declaration => declaration.CustomFolder.SubFolderRoot(FullPath)))
71+
foreach (var folder in subFolders.GroupBy(declaration => declaration.CustomFolder.SubFolderRoot(FullPath)))
7172
{
72-
AddChild(new CodeExplorerCustomFolderViewModel(this, folder.Key, $"{FullPath}.{folder.Key}", _vbe, folder));
73-
foreach (var declaration in folder)
74-
{
75-
declarations.Remove(declaration);
76-
}
73+
var contents = folder.ToList();
74+
AddChild(new CodeExplorerCustomFolderViewModel(this, folder.Key, $"{FullPath}.{folder.Key}", _vbe, ref contents));
7775
}
7876

79-
foreach (var declaration in declarations.Where(child => child.IsInFolder(FullPath)).GroupBy(item => item.ComponentName))
77+
children = children.Except(subFolders).ToList();
78+
79+
foreach (var declaration in children.Where(child => child.IsInFolder(FullPath)).GroupBy(item => item.ComponentName))
8080
{
8181
var moduleName = declaration.Key;
82-
var parent = declarations.SingleOrDefault(item =>
82+
var parent = children.SingleOrDefault(item =>
8383
ComponentTypes.Contains(item.DeclarationType) && item.ComponentName == moduleName);
8484

8585
if (parent is null)
8686
{
8787
continue;
8888
}
8989

90-
var members = declarations.Where(item =>
91-
!ComponentTypes.Contains(item.DeclarationType) && item.ComponentName == moduleName);
90+
var members = children.Where(item =>
91+
!ComponentTypes.Contains(item.DeclarationType) && item.ComponentName == moduleName).ToList();
9292

93-
AddChild(new CodeExplorerComponentViewModel(this, parent, members, _vbe));
94-
declarations.Remove(parent);
93+
AddChild(new CodeExplorerComponentViewModel(this, parent, ref members, _vbe));
9594
}
9695
}
9796

98-
public override void Synchronize(List<Declaration> updated)
97+
public override void Synchronize(ref List<Declaration> updated)
9998
{
100-
SynchronizeChildren(updated);
99+
SynchronizeChildren(ref updated);
101100
}
102101

103-
protected override void SynchronizeChildren(List<Declaration> updated)
102+
protected override void SynchronizeChildren(ref List<Declaration> updated)
104103
{
105-
var declarations = updated.Where(declaration => declaration.IsInFolderOrSubFolder(FullPath)).ToList();
106-
107-
if (!declarations.Any())
104+
var children = updated.Where(declaration => declaration.IsInFolderOrSubFolder(FullPath)).ToList();
105+
updated = updated.Except(children).ToList();
106+
107+
if (!children.Any())
108108
{
109109
Declaration = null;
110110
return;
111111
}
112112

113-
var synchronizing = declarations.ToList();
113+
var subFolders = children.Where(declaration => declaration.IsInSubFolder(FullPath)).ToList();
114+
children = children.Except(subFolders).ToList();
114115

115116
foreach (var subfolder in Children.OfType<CodeExplorerCustomFolderViewModel>().ToList())
116117
{
117-
subfolder.SynchronizeChildren(declarations);
118+
subfolder.SynchronizeChildren(ref subFolders);
118119
if (subfolder.Declaration is null)
119120
{
120121
RemoveChild(subfolder);
121-
continue;
122-
}
123-
124-
var synchronized = synchronizing.Where(child => !declarations.Contains(child)).ToList();
125-
foreach (var declaration in synchronized)
126-
{
127-
updated.Remove(declaration);
128122
}
129123
}
130124

131125
foreach (var child in Children.OfType<CodeExplorerComponentViewModel>().ToList())
132126
{
133-
child.Synchronize(updated);
127+
child.Synchronize(ref children);
134128
if (child.Declaration is null)
135129
{
136130
RemoveChild(child);
137-
continue;
138131
}
139-
140-
updated.Remove(child.Declaration);
141132
}
142133

143-
AddNewChildren(updated);
134+
children = children.Concat(subFolders).ToList();
135+
AddNewChildren(ref children);
144136
}
145137
}
146138
}

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerItemViewModel.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ public override bool IsErrorState
3434
}
3535
}
3636

37-
public virtual void Synchronize(List<Declaration> updated)
37+
public virtual void Synchronize(ref List<Declaration> updated)
3838
{
3939
if (Declaration is null)
4040
{
4141
return;
4242
}
4343

44-
var matching = updated.FirstOrDefault(decl => Declaration.DeclarationType == decl?.DeclarationType && Declaration.QualifiedName.Equals(decl?.QualifiedName));
44+
var matching = updated.FirstOrDefault(decl =>
45+
Declaration.DeclarationType == decl?.DeclarationType &&
46+
Declaration.QualifiedName.Equals(decl.QualifiedName));
4547

4648
if (matching is null)
4749
{
@@ -51,14 +53,14 @@ public virtual void Synchronize(List<Declaration> updated)
5153

5254
Declaration = matching;
5355
updated.Remove(matching);
54-
SynchronizeChildren(updated);
56+
SynchronizeChildren(ref updated);
5557
}
5658

57-
protected virtual void SynchronizeChildren(List<Declaration> updated)
59+
protected virtual void SynchronizeChildren(ref List<Declaration> updated)
5860
{
5961
foreach (var child in Children.OfType<CodeExplorerItemViewModel>().ToList())
6062
{
61-
child.Synchronize(updated);
63+
child.Synchronize(ref updated);
6264
if (child.Declaration is null)
6365
{
6466
RemoveChild(child);
@@ -68,9 +70,9 @@ protected virtual void SynchronizeChildren(List<Declaration> updated)
6870
updated.Remove(child.Declaration);
6971
}
7072

71-
AddNewChildren(updated);
73+
AddNewChildren(ref updated);
7274
}
7375

74-
protected abstract void AddNewChildren(List<Declaration> updated);
76+
protected abstract void AddNewChildren(ref List<Declaration> updated);
7577
}
7678
}

0 commit comments

Comments
 (0)