未验证 提交 bb77bfdf 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #31801 from sharwell/format-documents

Format documents in solution
......@@ -133,7 +133,7 @@ internal partial class Binder
{
constraints |= TypeParameterConstraintKind.NotNullableReferenceType;
}
else
else
{
constraints |= TypeParameterConstraintKind.ReferenceType;
}
......
......@@ -3412,7 +3412,7 @@ private bool HasTopLevelNullabilityConversion(TypeSymbolWithAnnotations source,
if (isLiftedConversion)
{
operandType = TypeSymbolWithAnnotations.Create(
methodReturnType.IsValueType && !methodReturnType.IsNullableType() ?
methodReturnType.IsValueType && !methodReturnType.IsNullableType() ?
compilation.GetSpecialType(SpecialType.System_Nullable_T).Construct(ImmutableArray.Create(methodReturnType)) :
methodReturnType.TypeSymbol,
methodReturnType.NullableAnnotation.IsAnyNullable() || operandAnnotation.IsAnyNullable() ?
......
......@@ -14,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.ExtractInterface
internal class ExtractInterfaceCommandHandler : AbstractExtractInterfaceCommandHandler
{
[ImportingConstructor]
public ExtractInterfaceCommandHandler(IThreadingContext threadingContext)
public ExtractInterfaceCommandHandler(IThreadingContext threadingContext)
: base(threadingContext)
{
}
......
......@@ -224,7 +224,7 @@ private async Task<(SyntaxNode root, SyntaxNode rewrittenRoot, TextSpan spanToFo
}
return newToken;
},
},
trivia: null,
computeReplacementTrivia: null);
......
......@@ -141,7 +141,7 @@ private async Task<WrappingGroup> GetUnwrapGroupAsync()
// MethodName(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j)
unwrapActions.Add(await GetUnwrapAllCodeActionAsync(parentTitle, WrappingStyle.UnwrapFirst_IndentRest).ConfigureAwait(false));
// MethodName(
// int a, int b, int c, int d, int e, int f, int g, int h, int i, int j)
unwrapActions.Add(await GetUnwrapAllCodeActionAsync(parentTitle, WrappingStyle.WrapFirst_IndentRest).ConfigureAwait(false));
......@@ -157,7 +157,7 @@ private async Task<WrapItemsAction> GetUnwrapAllCodeActionAsync(string parentTit
var title = wrappingStyle == WrappingStyle.WrapFirst_IndentRest
? Wrapper.Unwrap_and_indent_all_items
: Wrapper.Unwrap_all_items;
return await TryCreateCodeActionAsync(edits, parentTitle, title).ConfigureAwait(false);
}
......
......@@ -201,8 +201,8 @@ protected override SyntaxList<MemberDeclarationSyntax> GetMemberDeclarationsInCo
/// namespace to global namespace (i.e. remove the namespace declaration).
/// </summary>
protected override CompilationUnitSyntax ChangeNamespaceDeclaration(
CompilationUnitSyntax root,
ImmutableArray<string> declaredNamespaceParts,
CompilationUnitSyntax root,
ImmutableArray<string> declaredNamespaceParts,
ImmutableArray<string> targetNamespaceParts)
{
Debug.Assert(!declaredNamespaceParts.IsDefault && !targetNamespaceParts.IsDefault);
......@@ -225,7 +225,7 @@ protected override SyntaxList<MemberDeclarationSyntax> GetMemberDeclarationsInCo
// Change namespace name
return root.ReplaceNode(
namespaceDecl,
namespaceDecl,
namespaceDecl.WithName(
CreateNameSyntax(targetNamespaceParts, aliasQualifier: null, targetNamespaceParts.Length - 1)
.WithTriviaFrom(namespaceDecl.Name).WithAdditionalAnnotations(WarningAnnotation))
......@@ -349,7 +349,7 @@ protected override async Task<SyntaxNode> TryGetApplicableContainerFromSpanAsync
container = namespaceDecl;
}
var containsPartial =
var containsPartial =
await ContainsPartialTypeWithMultipleDeclarationsAsync(document, container, cancellationToken).ConfigureAwait(false);
if (containsPartial)
......
......@@ -70,9 +70,9 @@ internal override bool ShouldIncludeAccessibilityModifier(SyntaxNode typeNode)
}
protected override Task<Solution> UpdateMembersWithExplicitImplementationsAsync(
Solution unformattedSolution, IReadOnlyList<DocumentId> documentIds,
INamedTypeSymbol extractedInterface, INamedTypeSymbol typeToExtractFrom,
IEnumerable<ISymbol> includedMembers, Dictionary<ISymbol, SyntaxAnnotation> symbolToDeclarationMap,
Solution unformattedSolution, IReadOnlyList<DocumentId> documentIds,
INamedTypeSymbol extractedInterface, INamedTypeSymbol typeToExtractFrom,
IEnumerable<ISymbol> includedMembers, Dictionary<ISymbol, SyntaxAnnotation> symbolToDeclarationMap,
CancellationToken cancellationToken)
{
// In C#, member implementations do not always need
......
......@@ -99,12 +99,12 @@ public override async Task<bool> CanChangeNamespaceAsync(Document document, Synt
public override async Task<Solution> ChangeNamespaceAsync(
Document document,
SyntaxNode container,
string targetNamespace,
string targetNamespace,
CancellationToken cancellationToken)
{
// Make sure given namespace name is valid, "" means global namespace.
var syntaxFacts = document.GetLanguageService<ISyntaxFactsService>();
if (targetNamespace == null
if (targetNamespace == null
|| (targetNamespace.Length > 0 && !targetNamespace.Split(s_dotSeparator).All(syntaxFacts.IsValidIdentifier)))
{
throw new ArgumentException(nameof(targetNamespace));
......@@ -357,7 +357,7 @@ private static SyntaxNode CreateImport(SyntaxGenerator syntaxGenerator, string n
}
return import;
}
}
/// <summary>
/// Try to change the namespace declaration in the document (specified by <paramref name="id"/> in <paramref name="solution"/>).
......@@ -365,10 +365,10 @@ private static SyntaxNode CreateImport(SyntaxGenerator syntaxGenerator, string n
/// the types declared in the changed namespace (not include the document contains the declaration itself).
/// </summary>
private async Task<(Solution, ImmutableArray<DocumentId>)> ChangeNamespaceInSingleDocumentAsync(
Solution solution,
DocumentId id,
string oldNamespace,
string newNamespace,
Solution solution,
DocumentId id,
string oldNamespace,
string newNamespace,
CancellationToken cancellationToken)
{
var document = solution.GetDocument(id);
......
......@@ -33,7 +33,7 @@ internal sealed class State
/// which will be used to change namespace.
/// </summary>
public SyntaxNode Container { get; }
/// <summary>
/// This is the new name we want to change the namespace to.
/// Empty string means global namespace, whereas null means change namespace action is not available.
......@@ -51,7 +51,7 @@ internal sealed class State
private State(
Document document,
SyntaxNode container,
string targetNamespace,
string targetNamespace,
string relativeDeclaredNamespace)
{
Document = document;
......@@ -138,8 +138,8 @@ internal sealed class State
// For example, if the default namespace is `Microsoft.CodeAnalysis`, and declared
// namespace is `System.Diagnostics`, it's very likely this document is an outlier
// in the project and user probably has some special rule for it.
var relativeNamespace = GetRelativeNamespace(defaultNamespace, declaredNamespace, syntaxFacts);
var relativeNamespace = GetRelativeNamespace(defaultNamespace, declaredNamespace, syntaxFacts);
return new State(document, applicableNode, targetNamespace, relativeNamespace);
}
......
......@@ -47,7 +47,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
// No change namespace action if we can't construct a valid namespace from rootnamespace and folder names.
if (state.TargetNamespace != null)
{
{
// This code action tries to change the name of the namespace declaration to
// match the folder hierarchy of the document. The new namespace is constructed
// by concatenating the default namespace of the project and all the folders in
......@@ -65,9 +65,9 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var service = document.GetLanguageService<IChangeNamespaceService>();
var solutionChangeAction = new ChangeNamespaceCodeAction(
state.TargetNamespace.Length == 0
state.TargetNamespace.Length == 0
? FeaturesResources.Change_to_global_namespace
: string.Format(FeaturesResources.Change_namespace_to_0, state.TargetNamespace),
: string.Format(FeaturesResources.Change_namespace_to_0, state.TargetNamespace),
token => service.ChangeNamespaceAsync(document, state.Container, state.TargetNamespace, token));
context.RegisterRefactoring(solutionChangeAction);
......@@ -90,7 +90,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
private class ChangeNamespaceCodeAction : SolutionChangeAction
{
public ChangeNamespaceCodeAction(string title, Func<CancellationToken, Task<Solution>> createChangedSolution) :
public ChangeNamespaceCodeAction(string title, Func<CancellationToken, Task<Solution>> createChangedSolution) :
base(title, createChangedSolution)
{
}
......
......@@ -9,9 +9,9 @@ internal abstract partial class AbstractExtractInterfaceService
private readonly struct SymbolMapping
{
public SymbolMapping(
Dictionary<ISymbol, SyntaxAnnotation> symbolToDeclarationAnnotationMap,
Solution annotatedSolution,
List<DocumentId> documentIds,
Dictionary<ISymbol, SyntaxAnnotation> symbolToDeclarationAnnotationMap,
Solution annotatedSolution,
List<DocumentId> documentIds,
SyntaxAnnotation typeNodeAnnotation)
{
SymbolToDeclarationAnnotationMap = symbolToDeclarationAnnotationMap;
......
......@@ -129,8 +129,8 @@ public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
}
public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
ExtractInterfaceTypeAnalysisResult refactoringResult,
ExtractInterfaceOptionsResult extractInterfaceOptions,
ExtractInterfaceTypeAnalysisResult refactoringResult,
ExtractInterfaceOptionsResult extractInterfaceOptions,
CancellationToken cancellationToken)
{
var solution = refactoringResult.DocumentToExtractFrom.Project.Solution;
......@@ -202,7 +202,7 @@ public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
var completedSolution = await GetFormattedSolutionAsync(
completedUnformattedSolution,
symbolMapping.DocumentIds.Concat(unformattedInterfaceDocument.Id),
symbolMapping.DocumentIds.Concat(unformattedInterfaceDocument.Id),
cancellationToken).ConfigureAwait(false);
return new ExtractInterfaceResult(
......@@ -249,8 +249,8 @@ public async Task<ExtractInterfaceResult> ExtractInterfaceFromAnalyzedTypeAsync(
extractInterfaceOptions.IncludedMembers, symbolMapping.SymbolToDeclarationAnnotationMap, cancellationToken).ConfigureAwait(false);
var completedSolution = await GetFormattedSolutionAsync(
unformattedSolutionWithUpdatedType,
symbolMapping.DocumentIds.Concat(refactoringResult.DocumentToExtractFrom.Id),
unformattedSolutionWithUpdatedType,
symbolMapping.DocumentIds.Concat(refactoringResult.DocumentToExtractFrom.Id),
cancellationToken).ConfigureAwait(false);
return new ExtractInterfaceResult(
......@@ -366,8 +366,8 @@ private async Task<Solution> GetFormattedSolutionAsync(Solution unformattedSolut
cancellationToken: cancellationToken).ConfigureAwait(false);
var simplifiedDocument = await Simplifier.ReduceAsync(
formattedDocument,
Simplifier.Annotation,
formattedDocument,
Simplifier.Annotation,
cancellationToken: cancellationToken).ConfigureAwait(false);
formattedSolution = simplifiedDocument.Project.Solution;
......
......@@ -257,7 +257,7 @@ private static ExpressionSyntax GenerateSingleLiteralExpression(ITypeSymbol type
return result;
}
}
var negative = isNegative(value);
var nonNegativeValue = negative
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册