Skip to content

Commit

Permalink
Fixed invalid TextRange exception
Browse files Browse the repository at this point in the history
  • Loading branch information
vladyslav-burylov committed Dec 6, 2020
1 parent c744ddc commit 254fd70
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace ReSharperPlugin.TestLinker2.UnitTesting
{
[PsiComponent]
[SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable",
Justification = "TypesChanged is disposed via ")]
Justification = "TypesChanged is disposed via Lifetime")]
internal class ChangedTypesProvider
{
// ReSharper disable once InconsistentNaming
Expand Down Expand Up @@ -100,12 +100,18 @@ private void Invalidate()
foreach (var changedRange in changes)
{
var sourceFile = changedRange.Key.ToSourceFile();
if (sourceFile == null)
{
continue;
}

var containedTypes = _myServices.Symbols.GetTypesAndNamespacesInFile(sourceFile)
.OfType<ITypeElement>().Where(x => x.IsValid());

var containedTypes = _myServices.Symbols.GetTypesAndNamespacesInFile(sourceFile!)
.OfType<ITypeElement>();
var changedTypes = containedTypes.Where(
x => x.GetDeclarationsIn(sourceFile).Any(y =>
changedRange.Value.ContainedIn(y.GetDocumentRange().TextRange)));
x => x.GetDeclarationsIn(sourceFile)
.Select(t => t.GetDocumentRange().TextRange).Where(t => t.IsValid)
.Any(t => changedRange.Value.ContainedIn(t)));

allChangedTypes.AddRange(changedTypes);
}
Expand All @@ -120,8 +126,8 @@ private void Invalidate()

private KeyValuePair<IProjectFile, TextRange>[] GetChanges()
{
// TODO: try-finally?
KeyValuePair<IProjectFile, TextRange>[] changes;

lock (_myChangedRanges)
{
changes = _myChangedRanges.Where(x => x.Key.IsValid() && x.Value.IsValid).ToArray();
Expand All @@ -136,7 +142,9 @@ private void ReAddChanges(KeyValuePair<IProjectFile, TextRange>[] changes)
lock (_myChangedRanges)
{
foreach (var pair in changes)
{
_myChangedRanges.AddOrUpdate(pair.Key, pair.Value, (file, range) => pair.Value.Join(range));
}
}
}
}
Expand Down

0 comments on commit 254fd70

Please sign in to comment.