Skip to content

Commit ba8593d

Browse files
committed
fixed key exceptions in finder, unused parameter in ModulesReferencedBy
1 parent 88a8413 commit ba8593d

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

Rubberduck.Parsing/Symbols/DeclarationFinder.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ public IEnumerable<Declaration> FindAllInterfaceImplementingMembers()
253253

254254
public Declaration FindParameter(Declaration procedure, string parameterName)
255255
{
256-
return _parametersByParent[procedure].SingleOrDefault(parameter => parameter.IdentifierName == parameterName);
256+
ConcurrentBag<Declaration> parameters;
257+
return _parametersByParent.TryGetValue(procedure, out parameters)
258+
? parameters.SingleOrDefault(parameter => parameter.IdentifierName == parameterName)
259+
: null;
257260
}
258261

259262
public IEnumerable<Declaration> FindMemberMatches(Declaration parent, string memberName)

Rubberduck.Parsing/VBA/ParseCoordinator.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
1818
using System.Runtime.InteropServices;
1919
using Rubberduck.VBEditor.Application;
20-
using Rubberduck.VBEditor.Extensions;
2120

2221
// ReSharper disable LoopCanBeConvertedToQuery
2322

@@ -75,8 +74,8 @@ public ParseCoordinator(
7574
// but the cancelees need to use their own token.
7675
private readonly List<CancellationTokenSource> _cancellationTokens = new List<CancellationTokenSource> { new CancellationTokenSource() };
7776

78-
private readonly Object _cancellationSyncObject = new Object();
79-
private readonly Object _parsingRunSyncObject = new Object();
77+
private readonly object _cancellationSyncObject = new object();
78+
private readonly object _parsingRunSyncObject = new object();
8079

8180
private void ReparseRequested(object sender, EventArgs e)
8281
{
@@ -89,7 +88,7 @@ private void ReparseRequested(object sender, EventArgs e)
8988

9089
if (!_isTestScope)
9190
{
92-
Task.Run(() => ParseAll(sender, token));
91+
Task.Run(() => ParseAll(sender, token), token);
9392
}
9493
else
9594
{
@@ -295,7 +294,7 @@ private void ClearModuleToModuleReferences(ICollection<QualifiedModuleName> toCl
295294
}
296295
}
297296

298-
//This doesn not live on the RubberduckParserState to keep concurrency haanlding out of it.
297+
//This does not live on the RubberduckParserState to keep concurrency haanlding out of it.
299298
public void RemoveAllReferencesBy(ICollection<QualifiedModuleName> referencesFromToRemove, ICollection<QualifiedModuleName> modulesNotNeedingReferenceRemoval, DeclarationFinder finder, CancellationToken token)
300299
{
301300
var referencedModulesNeedingReferenceRemoval = State.ModulesReferencedBy(referencesFromToRemove).Where(qmn => !modulesNotNeedingReferenceRemoval.Contains(qmn));
@@ -343,7 +342,7 @@ private void ParseComponents(ICollection<IVBComponent> components, CancellationT
343342
{
344343
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
345344
{
346-
throw exception.InnerException; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
345+
throw exception.InnerException ?? exception; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
347346
}
348347
State.SetStatusAndFireStateChanged(this, ParserState.Error);
349348
throw;
@@ -438,7 +437,7 @@ private void ResolveAllDeclarations(ICollection<IVBComponent> components, Cancel
438437
{
439438
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
440439
{
441-
throw exception.InnerException; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
440+
throw exception.InnerException ?? exception; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
442441
}
443442
State.SetStatusAndFireStateChanged(this, ParserState.ResolverError);
444443
throw;
@@ -537,7 +536,7 @@ private void ResolveAllReferences(ICollection<QualifiedModuleName> toResolve, Ca
537536
{
538537
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
539538
{
540-
throw exception.InnerException; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
539+
throw exception.InnerException ?? exception; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
541540
}
542541
State.SetStatusAndFireStateChanged(this, ParserState.ResolverError);
543542
throw;
@@ -611,9 +610,12 @@ private void ResolveReferences(DeclarationFinder finder, QualifiedModuleName qua
611610

612611
private void AddModuleToModuleReferences(DeclarationFinder finder, CancellationToken token)
613612
{
614-
var options = new ParallelOptions();
615-
options.CancellationToken = token;
616-
options.MaxDegreeOfParallelism = _maxDegreeOfReferenceResolverParallelism;
613+
var options = new ParallelOptions
614+
{
615+
CancellationToken = token,
616+
MaxDegreeOfParallelism = _maxDegreeOfReferenceResolverParallelism
617+
};
618+
617619
try
618620
{
619621
Parallel.For(0, State.ParseTrees.Count, options,
@@ -624,7 +626,7 @@ private void AddModuleToModuleReferences(DeclarationFinder finder, CancellationT
624626
{
625627
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
626628
{
627-
throw exception.InnerException; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
629+
throw exception.InnerException ?? exception; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
628630
}
629631
State.SetStatusAndFireStateChanged(this, ParserState.ResolverError);
630632
throw;
@@ -749,9 +751,9 @@ private void ParseAllInternal(object requestor, CancellationToken token)
749751
/// </summary>
750752
private bool CleanUpRemovedComponents(ICollection<IVBComponent> components, CancellationToken token)
751753
{
752-
var removedModuledecalrations = RemovedModuleDeclarations(components);
753-
var componentRemoved = removedModuledecalrations.Any();
754-
var removedModules = removedModuledecalrations.Select(declaration => declaration.QualifiedName.QualifiedModuleName).ToHashSet();
754+
var removedModuleDeclarations = RemovedModuleDeclarations(components).ToArray();
755+
var componentRemoved = removedModuleDeclarations.Any();
756+
var removedModules = removedModuleDeclarations.Select(declaration => declaration.QualifiedName.QualifiedModuleName).ToHashSet();
755757
if (removedModules.Any())
756758
{
757759
RemoveAllReferencesBy(removedModules, removedModules, State.DeclarationFinder, token);
@@ -865,7 +867,7 @@ private void SyncComReferences(IReadOnlyList<IVBProject> projects, CancellationT
865867
{
866868
if (exception.Flatten().InnerExceptions.All(ex => ex is OperationCanceledException))
867869
{
868-
throw exception.InnerException; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
870+
throw exception.InnerException ?? exception; //This eliminates the stack trace, but for the cancellation, this is irrelevant.
869871
}
870872
State.SetStatusAndFireStateChanged(this, ParserState.Error);
871873
throw;
@@ -952,7 +954,7 @@ private void LoadReference(IReference localReference, ConcurrentBag<IReference>
952954
}
953955
else
954956
{
955-
LoadReferenceByCOMReflection(localReference, comReflector);
957+
LoadReferenceFromTypeLibrary(localReference, comReflector);
956958
}
957959
}
958960
catch (Exception exception)
@@ -973,7 +975,7 @@ private void LoadReferenceByDeserialization(IReference localReference, Reference
973975
}
974976
}
975977

976-
private void LoadReferenceByCOMReflection(IReference localReference, ReferencedDeclarationsCollector comReflector)
978+
private void LoadReferenceFromTypeLibrary(IReference localReference, ReferencedDeclarationsCollector comReflector)
977979
{
978980
Logger.Trace(string.Format("COM reflecting reference '{0}'.", localReference.Name));
979981
var declarations = comReflector.LoadDeclarationsFromLibrary();

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,9 +1183,9 @@ public void ClearModuleToModuleReferencesFromModule(QualifiedModuleName referenc
11831183
return;
11841184
}
11851185

1186-
ModuleState referencedModuleState;
11871186
foreach (var referencedModule in referencingModuleState.HasReferenceToModule.Keys)
11881187
{
1188+
ModuleState referencedModuleState;
11891189
if (!_moduleStates.TryGetValue(referencedModule,out referencedModuleState))
11901190
{
11911191
continue;
@@ -1208,7 +1208,7 @@ public HashSet<QualifiedModuleName> ModulesReferencedBy(QualifiedModuleName refe
12081208
public HashSet<QualifiedModuleName> ModulesReferencedBy(IEnumerable<QualifiedModuleName> referencingModules)
12091209
{
12101210
var referencedModules = new HashSet<QualifiedModuleName>();
1211-
foreach (var referencingModule in referencedModules)
1211+
foreach (var referencingModule in referencingModules)
12121212
{
12131213
referencedModules.UnionWith(ModulesReferencedBy(referencingModule));
12141214
}

0 commit comments

Comments
 (0)