提交 15b00bf6 编写于 作者: C Cyrus Najmabadi

Use deconstruction

上级 57944d5b
......@@ -50,23 +50,23 @@ public async Task<Document> CleanupAsync(Document document, ImmutableArray<TextS
Debug.Assert(syntaxFactsService != null);
// We need to track spans between cleaners. Annotate the tree with the provided spans.
var newNodeAndAnnotations = AnnotateNodeForTextSpans(syntaxFactsService, root, normalizedSpan, cancellationToken);
var (newNode, annotations) = AnnotateNodeForTextSpans(syntaxFactsService, root, normalizedSpan, cancellationToken);
// If it urns out we don't need to annotate anything since all spans are merged to one span that covers the whole node...
if (newNodeAndAnnotations.newNode == null)
if (newNode == null)
{
// ... then we are cleaning up the whole document, so there is no need to do expansive span tracking between cleaners.
return await IterateAllCodeCleanupProvidersAsync(document, document, n => ImmutableArray.Create(n.FullSpan), codeCleaners, cancellationToken).ConfigureAwait(false);
}
// Replace the initial node and document with the annotated node.
var annotatedRoot = newNodeAndAnnotations.newNode;
var annotatedRoot = newNode;
var annotatedDocument = document.WithSyntaxRoot(annotatedRoot);
// Run the actual cleanup.
return await IterateAllCodeCleanupProvidersAsync(
document, annotatedDocument,
r => GetTextSpansFromAnnotation(r, newNodeAndAnnotations.annotations, cancellationToken),
r => GetTextSpansFromAnnotation(r, annotations, cancellationToken),
codeCleaners, cancellationToken).ConfigureAwait(false);
}
}
......@@ -95,22 +95,22 @@ public async Task<SyntaxNode> CleanupAsync(SyntaxNode root, ImmutableArray<TextS
Debug.Assert(syntaxFactsService != null);
// We need to track spans between cleaners. Annotate the tree with the provided spans.
var newNodeAndAnnotations = AnnotateNodeForTextSpans(syntaxFactsService, root, normalizedSpan, cancellationToken);
var (newNode, annotations) = AnnotateNodeForTextSpans(syntaxFactsService, root, normalizedSpan, cancellationToken);
// If it urns out we don't need to annotate anything since all spans are merged to one span that covers the whole node...
if (newNodeAndAnnotations.newNode == null)
if (newNode == null)
{
// ... then we are cleaning up the whole document, so there is no need to do expansive span tracking between cleaners.
return await IterateAllCodeCleanupProvidersAsync(root, root, n => ImmutableArray.Create(n.FullSpan), workspace, codeCleaners, cancellationToken).ConfigureAwait(false);
}
// Replace the initial node and document with the annotated node.
var annotatedRoot = newNodeAndAnnotations.newNode;
var annotatedRoot = newNode;
// Run the actual cleanup.
return await IterateAllCodeCleanupProvidersAsync(
root, annotatedRoot,
r => GetTextSpansFromAnnotation(r, newNodeAndAnnotations.annotations, cancellationToken),
r => GetTextSpansFromAnnotation(r, annotations, cancellationToken),
workspace, codeCleaners, cancellationToken).ConfigureAwait(false);
}
}
......@@ -123,12 +123,12 @@ public async Task<SyntaxNode> CleanupAsync(SyntaxNode root, ImmutableArray<TextS
// Now try to retrieve the text span from the annotations injected into the node.
var builder = ArrayBuilder<TextSpan>.GetInstance();
foreach (var annotationPair in annotations)
foreach (var (previousAnnotation, nextAnnotation) in annotations)
{
cancellationToken.ThrowIfCancellationRequested();
var previousMarkerAnnotation = annotationPair.previousAnnotation;
var nextMarkerAnnotation = annotationPair.nextAnnotation;
var previousMarkerAnnotation = previousAnnotation;
var nextMarkerAnnotation = nextAnnotation;
var previousTokenMarker = SpanMarker.FromAnnotation(previousMarkerAnnotation);
var nextTokenMarker = SpanMarker.FromAnnotation(nextMarkerAnnotation);
......
......@@ -256,11 +256,11 @@ public virtual string GetFixAllTitle(FixAllState fixAllState)
// For each changed document, also keep track of the associated code action that
// produced it.
var getChangedDocumentsTasks = new List<Task>();
foreach (var diagnosticAndCodeAction in diagnosticsAndCodeActions)
foreach (var (diagnostic, action) in diagnosticsAndCodeActions)
{
getChangedDocumentsTasks.Add(GetChangedDocumentsAsync(
oldSolution, documentIdToChangedDocuments,
diagnosticAndCodeAction.action, cancellationToken));
action, cancellationToken));
}
await Task.WhenAll(getChangedDocumentsTasks).ConfigureAwait(false);
......
......@@ -158,10 +158,10 @@ private IFieldSymbol GetZeroField(List<(IFieldSymbol field, ulong value)> allFie
{
for (var i = allFieldsAndValues.Count - 1; i >= 0; i--)
{
var tuple = allFieldsAndValues[i];
if (tuple.value == 0)
var (field, value) = allFieldsAndValues[i];
if (value == 0)
{
return tuple.field;
return field;
}
}
......
......@@ -94,11 +94,11 @@ public FormattingContext(AbstractFormatEngine engine, TokenStream tokenStream, s
}
var initialContextFinder = new InitialContextFinder(_tokenStream, formattingRules, rootNode);
var results = initialContextFinder.Do(startToken, endToken);
var (indentOperations, suppressOperations) = initialContextFinder.Do(startToken, endToken);
if (results.indentOperations != null)
if (indentOperations != null)
{
var indentationOperations = results.indentOperations;
var indentationOperations = indentOperations;
var initialOperation = indentationOperations[0];
var baseIndentationFinder = new BottomUpBaseIndentationFinder(
......@@ -119,7 +119,7 @@ public FormattingContext(AbstractFormatEngine engine, TokenStream tokenStream, s
_initialIndentBlockOperations = indentationOperations;
}
results.suppressOperations?.Do(o => this.AddInitialSuppressOperation(o));
suppressOperations?.Do(o => this.AddInitialSuppressOperation(o));
}
public void AddIndentBlockOperations(
......
......@@ -162,10 +162,10 @@ public bool IsOnSingleLine(SyntaxNode node, bool fullSpan)
{
while (stack.Count > 0)
{
var current = stack.Pop();
var currentNodeOrToken = current.nodeOrToken;
var currentLeading = current.leading;
var currentTrailing = current.trailing;
var (nodeOrToken, leading, trailing) = stack.Pop();
var currentNodeOrToken = nodeOrToken;
var currentLeading = leading;
var currentTrailing = trailing;
if (currentNodeOrToken.IsToken)
{
......
......@@ -318,12 +318,12 @@ private async Task DebugVerifyNoErrorsAsync(ConflictResolution conflictResolutio
var syntaxRoot = await newDocument.GetSyntaxRootAsync(_cancellationToken).ConfigureAwait(false);
var nodesOrTokensWithConflictCheckAnnotations = GetNodesOrTokensToCheckForConflicts(documentId, syntaxRoot);
foreach (var nodeOrToken in nodesOrTokensWithConflictCheckAnnotations)
foreach (var (syntax, annotation) in nodesOrTokensWithConflictCheckAnnotations)
{
if (nodeOrToken.annotation.IsRenameLocation)
if (annotation.IsRenameLocation)
{
conflictResolution.AddRelatedLocation(new RelatedLocation(
nodeOrToken.annotation.OriginalSpan, documentId, RelatedLocationType.UnresolvedConflict));
annotation.OriginalSpan, documentId, RelatedLocationType.UnresolvedConflict));
}
}
}
......@@ -351,10 +351,10 @@ private async Task DebugVerifyNoErrorsAsync(ConflictResolution conflictResolutio
.Where(t => t.DocumentId == documentId)
.Select(t => t.OriginalIdentifierSpan).ToSet();
foreach (var nodeAndAnnotation in nodesOrTokensWithConflictCheckAnnotations)
foreach (var (syntax, annotation) in nodesOrTokensWithConflictCheckAnnotations)
{
var tokenOrNode = nodeAndAnnotation.syntax;
var conflictAnnotation = nodeAndAnnotation.annotation;
var tokenOrNode = syntax;
var conflictAnnotation = annotation;
reverseMappedLocations[tokenOrNode.GetLocation()] = baseSyntaxTree.GetLocation(conflictAnnotation.OriginalSpan);
var originalLocation = conflictAnnotation.OriginalSpan;
IEnumerable<ISymbol> newReferencedSymbols = null;
......@@ -434,10 +434,10 @@ private async Task DebugVerifyNoErrorsAsync(ConflictResolution conflictResolutio
var baseSyntaxTree = await baseDocument.GetSyntaxTreeAsync(_cancellationToken).ConfigureAwait(false);
var nodesOrTokensWithConflictCheckAnnotations = GetNodesOrTokensToCheckForConflicts(unprocessedDocumentIdWithPotentialDeclarationConflicts, syntaxRoot);
foreach (var nodeAndAnnotation in nodesOrTokensWithConflictCheckAnnotations)
foreach (var (syntax, annotation) in nodesOrTokensWithConflictCheckAnnotations)
{
var tokenOrNode = nodeAndAnnotation.syntax;
var conflictAnnotation = nodeAndAnnotation.annotation;
var tokenOrNode = syntax;
var conflictAnnotation = annotation;
reverseMappedLocations[tokenOrNode.GetLocation()] = baseSyntaxTree.GetLocation(conflictAnnotation.OriginalSpan);
}
}
......
......@@ -79,9 +79,9 @@ internal int GetAdjustedPosition(int startingPosition, DocumentId documentId)
SpecializedCollections.EmptyEnumerable<(TextSpan oldSpan, TextSpan newSpan)>();
var adjustedStartingPosition = startingPosition;
foreach (var textSpanPair in documentReplacementSpans)
foreach (var (oldSpan, newSpan) in documentReplacementSpans)
{
adjustedStartingPosition += textSpanPair.newSpan.Length - textSpanPair.oldSpan.Length;
adjustedStartingPosition += newSpan.Length - oldSpan.Length;
}
var documentComplexifiedSpans = _documentToComplexifiedSpansMap.ContainsKey(documentId)
......@@ -98,17 +98,17 @@ internal int GetAdjustedPosition(int startingPosition, DocumentId documentId)
}
else
{
foreach (var modifiedSpan in c.ModifiedSubSpans.OrderByDescending(t => t.oldSpan.Start))
foreach (var (oldSpan, newSpan) in c.ModifiedSubSpans.OrderByDescending(t => t.oldSpan.Start))
{
if (!appliedTextSpans.Any(s => s.Contains(modifiedSpan.oldSpan)))
if (!appliedTextSpans.Any(s => s.Contains(oldSpan)))
{
if (startingPosition == modifiedSpan.oldSpan.Start)
if (startingPosition == oldSpan.Start)
{
return startingPosition + modifiedSpan.newSpan.Start - modifiedSpan.oldSpan.Start;
return startingPosition + newSpan.Start - oldSpan.Start;
}
else if (startingPosition > modifiedSpan.oldSpan.Start)
else if (startingPosition > oldSpan.Start)
{
return startingPosition + modifiedSpan.newSpan.End - modifiedSpan.oldSpan.End;
return startingPosition + newSpan.End - oldSpan.End;
}
}
}
......@@ -251,9 +251,9 @@ internal async Task<Solution> SimplifyAsync(Solution solution, IEnumerable<Docum
var result = new Dictionary<TextSpan, TextSpan>();
if (_documentToModifiedSpansMap.TryGetValue(documentId, out var modifiedSpans))
{
foreach (var pair in modifiedSpans)
foreach (var (oldSpan, newSpan) in modifiedSpans)
{
result[pair.oldSpan] = pair.newSpan;
result[oldSpan] = newSpan;
}
}
......@@ -261,9 +261,9 @@ internal async Task<Solution> SimplifyAsync(Solution solution, IEnumerable<Docum
{
foreach (var complexifiedSpan in complexifiedSpans)
{
foreach (var pair in complexifiedSpan.ModifiedSubSpans)
foreach (var (oldSpan, newSpan) in complexifiedSpan.ModifiedSubSpans)
{
result[pair.oldSpan] = pair.newSpan;
result[oldSpan] = newSpan;
}
}
}
......
......@@ -297,11 +297,11 @@ public IEnumerator<T> GetEnumerator()
candidates.Push((root, firstTime: true));
while (candidates.Count != 0)
{
var currentTuple = candidates.Pop();
var currentNode = currentTuple.node;
var (node, firstTime) = candidates.Pop();
var currentNode = node;
if (currentNode != null)
{
if (currentTuple.firstTime)
if (firstTime)
{
// First time seeing this node. Mark that we've been seen and recurse
// down the left side. The next time we see this node we'll yield it
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册