提交 e8607c1d 编写于 作者: C Cyrus Najmabadi

Use deconstruction'

上级 a1cb7981
......@@ -51,8 +51,7 @@ public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSp
var snapshotSpan = new SnapshotSpan(textSnapshot, textSpan.Start, textSpan.Length);
var virtualSnapshotSpan = new VirtualSnapshotSpan(snapshotSpan);
VirtualSnapshotSpan surfaceBufferSpan;
if (!textView.TryGetSurfaceBufferSpan(virtualSnapshotSpan, out surfaceBufferSpan))
if (!textView.TryGetSurfaceBufferSpan(virtualSnapshotSpan, out var surfaceBufferSpan))
{
return false;
}
......
......@@ -121,12 +121,12 @@ private static int ComputeSymbolMatchPriority(ISymbol symbol)
var relatedDocumentIds = document.Project.Solution.GetRelatedDocumentIds(document.Id).Concat(document.Id);
var options = document.Project.Solution.Workspace.Options;
var totalSymbols = await base.GetPerContextSymbols(document, position, options, relatedDocumentIds, preselect: false, cancellationToken: cancellationToken).ConfigureAwait(false);
foreach (var info in totalSymbols)
foreach (var (documentId, syntaxContext, symbols) in totalSymbols)
{
var bestSymbols = info.symbols.Where(s => kind != null && s.Kind == kind && s.Name == name).ToImmutableArray();
var bestSymbols = symbols.Where(s => kind != null && s.Kind == kind && s.Name == name).ToImmutableArray();
if (bestSymbols.Any())
{
return await SymbolCompletionItem.GetDescriptionAsync(item, bestSymbols, document, info.syntaxContext.SemanticModel, cancellationToken).ConfigureAwait(false);
return await SymbolCompletionItem.GetDescriptionAsync(item, bestSymbols, document, syntaxContext.SemanticModel, cancellationToken).ConfigureAwait(false);
}
}
......
......@@ -407,12 +407,12 @@ private Task<SyntaxContext> GetOrCreateContext(Document document, int position,
{
var missingSymbols = new Dictionary<ISymbol, List<ProjectId>>(LinkedFilesSymbolEquivalenceComparer.Instance);
foreach (var linkedContextSymbolList in linkedContextSymbolLists)
foreach (var (documentId, syntaxContext, symbols) in linkedContextSymbolLists)
{
var symbolsMissingInLinkedContext = symbolToContext.Keys.Except(linkedContextSymbolList.symbols, LinkedFilesSymbolEquivalenceComparer.Instance);
var symbolsMissingInLinkedContext = symbolToContext.Keys.Except(symbols, LinkedFilesSymbolEquivalenceComparer.Instance);
foreach (var missingSymbol in symbolsMissingInLinkedContext)
{
missingSymbols.GetOrAdd(missingSymbol, m => new List<ProjectId>()).Add(linkedContextSymbolList.documentId.ProjectId);
missingSymbols.GetOrAdd(missingSymbol, m => new List<ProjectId>()).Add(documentId.ProjectId);
}
}
......
......@@ -29,8 +29,8 @@ private class GenerateConstructorCodeAction : CodeAction
protected override async Task<Document> GetChangedDocumentAsync(CancellationToken cancellationToken)
{
var result = await GetEditAsync(cancellationToken).ConfigureAwait(false);
return result.document;
var (document, _) = await GetEditAsync(cancellationToken).ConfigureAwait(false);
return document;
}
public async Task<(Document document, bool addedFields)> GetEditAsync(CancellationToken cancellationToken)
......
......@@ -224,11 +224,8 @@ public Task<Document> GetUpdatedDocumentAsync(CancellationToken cancellationToke
var implementedVisibleMembers = new List<ISymbol>();
var implementedMembers = ArrayBuilder<ISymbol>.GetInstance();
foreach (var tuple in unimplementedMembers)
foreach (var (_, unimplementedInterfaceMembers) in unimplementedMembers)
{
var interfaceType = tuple.type;
var unimplementedInterfaceMembers = tuple.members;
foreach (var unimplementedInterfaceMember in unimplementedInterfaceMembers)
{
var member = GenerateMember(
......
......@@ -363,30 +363,27 @@ private string GetDefinitionIssues(IEnumerable<ReferencedSymbol> getMethodRefere
var editor = new SyntaxEditor(root, updatedSolution.Workspace);
// First replace all the properties with the appropriate getters/setters.
foreach (var definition in currentDefinitions)
foreach (var (property, declaration) in currentDefinitions)
{
cancellationToken.ThrowIfCancellationRequested();
var propertyDefinition = definition.property;
var propertyDeclaration = definition.declaration;
var members = await service.GetReplacementMembersAsync(
updatedDocument,
propertyDefinition, propertyDeclaration,
definitionToBackingField.GetValueOrDefault(propertyDefinition),
property, declaration,
definitionToBackingField.GetValueOrDefault(property),
desiredGetMethodName, desiredSetMethodName,
cancellationToken).ConfigureAwait(false);
// Properly make the members fit within an interface if that's what
// we're generating into.
if (propertyDefinition.ContainingType.TypeKind == TypeKind.Interface)
if (property.ContainingType.TypeKind == TypeKind.Interface)
{
members = members.Select(editor.Generator.AsInterfaceMember)
.WhereNotNull()
.ToList();
}
var nodeToReplace = service.GetPropertyNodeToReplace(propertyDeclaration);
var nodeToReplace = service.GetPropertyNodeToReplace(declaration);
editor.InsertAfter(nodeToReplace, members);
editor.RemoveNode(nodeToReplace);
}
......
......@@ -68,8 +68,7 @@ public static ContainedDocument TryGetContainedDocument(DocumentId id)
return null;
}
ContainedDocument document;
s_containedDocuments.TryGetValue(id, out document);
s_containedDocuments.TryGetValue(id, out var document);
return document;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册