提交 2450428b 编写于 作者: D David Poeschl 提交者: Ivan Basov

Kinda working for regular parameter/argument lists

上级 98db4c25
......@@ -356,7 +356,11 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
isReducedExtensionMethod = true;
}
var newArguments = PermuteArgumentList(document, declarationSymbol, invocation.ArgumentList.Arguments, signaturePermutation, isReducedExtensionMethod);
SignatureChange signaturePermutationWithoutAddedParameters = signaturePermutation.WithoutAddedParameters();
var newArguments = PermuteArgumentList(document, declarationSymbol, invocation.ArgumentList.Arguments, signaturePermutationWithoutAddedParameters, isReducedExtensionMethod);
newArguments = AddNewArgumentsToList(document, declarationSymbol, newArguments, signaturePermutation, isReducedExtensionMethod);
return invocation.WithArgumentList(invocation.ArgumentList.WithArguments(newArguments).WithAdditionalAnnotations(changeSignatureFormattingAnnotation));
}
......@@ -411,6 +415,39 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
return null;
}
private SeparatedSyntaxList<ArgumentSyntax> AddNewArgumentsToList(Document document, ISymbol declarationSymbol, SeparatedSyntaxList<ArgumentSyntax> newArguments, SignatureChange signaturePermutation, bool isReducedExtensionMethod)
{
List<ArgumentSyntax> fullList = new List<ArgumentSyntax>();
var updatedParameters = signaturePermutation.UpdatedConfiguration.ToListOfParameters();
int indexInExistingList = 0;
bool seenNameEquals = false;
for (int i = 0; i < updatedParameters.Count; i++)
{
if (updatedParameters[i] is AddedParameter addedParameter)
{
fullList.Add(SyntaxFactory.Argument(
seenNameEquals ? SyntaxFactory.NameColon(addedParameter.Name) : default,
refKindKeyword: default,
expression: SyntaxFactory.ParseExpression(addedParameter.CallsiteValue)));
}
else
{
if (newArguments[indexInExistingList].NameColon != default)
{
seenNameEquals = true;
}
fullList.Add(newArguments[indexInExistingList++]);
}
}
return SyntaxFactory.SeparatedList(fullList);
}
private SeparatedSyntaxList<T> PermuteDeclaration<T>(SeparatedSyntaxList<T> list, SignatureChange updatedSignature) where T : SyntaxNode
{
var originalParameters = updatedSignature.OriginalConfiguration.ToListOfParameters();
......@@ -469,7 +506,7 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
return newArgument;
}
private static SeparatedSyntaxList<AttributeArgumentSyntax> PermuteAttributeArgumentList(
private SeparatedSyntaxList<AttributeArgumentSyntax> PermuteAttributeArgumentList(
Document document,
ISymbol declarationSymbol,
SeparatedSyntaxList<AttributeArgumentSyntax> arguments,
......@@ -485,7 +522,7 @@ private SyntaxNode GetNodeContainingTargetNode(SyntaxNode matchingNode)
return SyntaxFactory.SeparatedList(newArgumentsWithTrivia, GetSeparators(arguments, numSeparatorsToSkip));
}
private static SeparatedSyntaxList<ArgumentSyntax> PermuteArgumentList(
private SeparatedSyntaxList<ArgumentSyntax> PermuteArgumentList(
Document document,
ISymbol declarationSymbol,
SeparatedSyntaxList<ArgumentSyntax> arguments,
......@@ -705,5 +742,10 @@ protected override IEnumerable<AbstractFormattingRule> GetFormattingRules(Docume
{
return SpecializedCollections.SingletonEnumerable(new ChangeSignatureFormattingRule()).Concat(Formatter.GetDefaultFormattingRules(document));
}
protected override IUnifiedArgumentSyntax CreateRegularArgumentSyntax(string callsiteValue)
{
return UnifiedArgumentSyntax.Create(SyntaxFactory.Argument(SyntaxFactory.ParseExpression(callsiteValue)));
}
}
}
......@@ -46,6 +46,8 @@ internal abstract class AbstractChangeSignatureService : ILanguageService
SignatureChange signaturePermutation,
CancellationToken cancellationToken);
protected abstract IUnifiedArgumentSyntax CreateRegularArgumentSyntax(string callsiteValue);
protected abstract IEnumerable<AbstractFormattingRule> GetFormattingRules(Document document);
public async Task<ImmutableArray<ChangeSignatureCodeAction>> GetChangeSignatureCodeActionAsync(Document document, TextSpan span, CancellationToken cancellationToken)
......@@ -394,7 +396,7 @@ private bool TryGetNodeWithEditableSignatureOrAttributes(Location location, Solu
return nodeToUpdate != null;
}
protected static List<IUnifiedArgumentSyntax> PermuteArguments(
protected List<IUnifiedArgumentSyntax> PermuteArguments(
Document document,
ISymbol declarationSymbol,
List<IUnifiedArgumentSyntax> arguments,
......@@ -476,13 +478,13 @@ private bool TryGetNodeWithEditableSignatureOrAttributes(Location location, Solu
}
}
// 6. TODO MOVE AROUND. Add added arguments
// 6. TODO MOVE AROUND. Add added arguments (only at end for the moment)
var brandNewParameters = updatedSignature.UpdatedConfiguration.ToListOfParameters().Where(p => p is AddedParameter).Cast<AddedParameter>();
foreach (var brandNewParameter in brandNewParameters)
{
// newArguments.Add(new IUnifiedArgumentSyntax());
newArguments.Add(CreateRegularArgumentSyntax(brandNewParameter.CallsiteValue));
}
return newArguments;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.CodeAnalysis.ChangeSignature
{
......@@ -54,6 +56,11 @@ public static ParameterConfiguration Create(List<CoolParameter> parameters, bool
return new ParameterConfiguration(thisParameter, parametersWithoutDefaultValues, remainingReorderableParameters, paramsParameter, selectedIndex);
}
internal ParameterConfiguration WithoutAddedParameters()
{
return Create(ToListOfParameters().OfType<ExistingParameter>().ToList<CoolParameter>(), ThisParameter != null, selectedIndex: 0);
}
public List<CoolParameter> ToListOfParameters()
{
var list = new List<CoolParameter>();
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.Shared.Extensions;
......@@ -39,5 +40,10 @@ public SignatureChange(ParameterConfiguration originalConfiguration, ParameterCo
return _originalIndexToUpdatedIndexMap[parameterIndex];
}
internal SignatureChange WithoutAddedParameters()
{
return new SignatureChange(OriginalConfiguration, UpdatedConfiguration.WithoutAddedParameters());
}
}
}
......@@ -607,5 +607,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ChangeSignature
Return SpecializedCollections.SingletonEnumerable(Of AbstractFormattingRule)(New ChangeSignatureFormattingRule()).
Concat(Formatter.GetDefaultFormattingRules(document))
End Function
Protected Overrides Function CreateRegularArgumentSyntax(callsiteValue As String) As IUnifiedArgumentSyntax
Return UnifiedArgumentSyntax.Create(SyntaxFactory.SimpleArgument(SyntaxFactory.ParseExpression(callsiteValue)))
End Function
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册