|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System; |
| 6 | +using Microsoft.CodeAnalysis.CodeStyle; |
| 7 | +using Microsoft.CodeAnalysis.CSharp.Formatting; |
| 8 | + |
| 9 | +namespace Microsoft.CodeAnalysis.ExternalAccess.Razor.Features |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// Wrapper for CSharpSyntaxFormattingOptions for Razor external access. |
| 13 | + /// </summary> |
| 14 | + internal sealed record class RazorCSharpSyntaxFormattingOptions( |
| 15 | + RazorSpacePlacement Spacing, |
| 16 | + RazorBinaryOperatorSpacingOptions SpacingAroundBinaryOperator, |
| 17 | + RazorNewLinePlacement NewLines, |
| 18 | + RazorLabelPositionOptions LabelPositioning, |
| 19 | + RazorIndentationPlacement Indentation, |
| 20 | + bool WrappingKeepStatementsOnSingleLine, |
| 21 | + bool WrappingPreserveSingleLine, |
| 22 | + RazorNamespaceDeclarationPreference NamespaceDeclarations, |
| 23 | + bool PreferTopLevelStatements, |
| 24 | + int CollectionExpressionWrappingLength) |
| 25 | + { |
| 26 | + public static readonly RazorCSharpSyntaxFormattingOptions Default = new(); |
| 27 | + |
| 28 | + private RazorCSharpSyntaxFormattingOptions() |
| 29 | + : this(CSharpSyntaxFormattingOptions.Default) |
| 30 | + { |
| 31 | + } |
| 32 | + |
| 33 | + public RazorCSharpSyntaxFormattingOptions(CSharpSyntaxFormattingOptions options) |
| 34 | + : this( |
| 35 | + (RazorSpacePlacement)options.Spacing, |
| 36 | + (RazorBinaryOperatorSpacingOptions)options.SpacingAroundBinaryOperator, |
| 37 | + (RazorNewLinePlacement)options.NewLines, |
| 38 | + (RazorLabelPositionOptions)options.LabelPositioning, |
| 39 | + (RazorIndentationPlacement)options.Indentation, |
| 40 | + options.WrappingKeepStatementsOnSingleLine, |
| 41 | + options.WrappingPreserveSingleLine, |
| 42 | + (RazorNamespaceDeclarationPreference)options.NamespaceDeclarations.Value, |
| 43 | + options.PreferTopLevelStatements.Value, |
| 44 | + options.CollectionExpressionWrappingLength) |
| 45 | + { |
| 46 | + } |
| 47 | + |
| 48 | + public CSharpSyntaxFormattingOptions ToCSharpSyntaxFormattingOptions() |
| 49 | + => new() |
| 50 | + { |
| 51 | + Spacing = (SpacePlacement)Spacing, |
| 52 | + SpacingAroundBinaryOperator = (BinaryOperatorSpacingOptions)SpacingAroundBinaryOperator, |
| 53 | + NewLines = (NewLinePlacement)NewLines, |
| 54 | + LabelPositioning = (LabelPositionOptions)LabelPositioning, |
| 55 | + Indentation = (IndentationPlacement)Indentation, |
| 56 | + WrappingKeepStatementsOnSingleLine = WrappingKeepStatementsOnSingleLine, |
| 57 | + WrappingPreserveSingleLine = WrappingPreserveSingleLine, |
| 58 | + NamespaceDeclarations = new CodeStyleOption2<NamespaceDeclarationPreference>( |
| 59 | + (NamespaceDeclarationPreference)NamespaceDeclarations, |
| 60 | + CSharpSyntaxFormattingOptions.Default.NamespaceDeclarations.Notification), |
| 61 | + PreferTopLevelStatements = new CodeStyleOption2<bool>( |
| 62 | + PreferTopLevelStatements, |
| 63 | + CSharpSyntaxFormattingOptions.Default.PreferTopLevelStatements.Notification), |
| 64 | + CollectionExpressionWrappingLength = CollectionExpressionWrappingLength |
| 65 | + }; |
| 66 | + } |
| 67 | + |
| 68 | + [Flags] |
| 69 | + public enum RazorSpacePlacement |
| 70 | + { |
| 71 | + None = 0, |
| 72 | + IgnoreAroundVariableDeclaration = SpacePlacement.IgnoreAroundVariableDeclaration, |
| 73 | + AfterMethodDeclarationName = SpacePlacement.AfterMethodDeclarationName, |
| 74 | + BetweenEmptyMethodDeclarationParentheses = SpacePlacement.BetweenEmptyMethodDeclarationParentheses, |
| 75 | + WithinMethodDeclarationParenthesis = SpacePlacement.WithinMethodDeclarationParenthesis, |
| 76 | + AfterMethodCallName = SpacePlacement.AfterMethodCallName, |
| 77 | + BetweenEmptyMethodCallParentheses = SpacePlacement.BetweenEmptyMethodCallParentheses, |
| 78 | + WithinMethodCallParentheses = SpacePlacement.WithinMethodCallParentheses, |
| 79 | + AfterControlFlowStatementKeyword = SpacePlacement.AfterControlFlowStatementKeyword, |
| 80 | + WithinExpressionParentheses = SpacePlacement.WithinExpressionParentheses, |
| 81 | + WithinCastParentheses = SpacePlacement.WithinCastParentheses, |
| 82 | + BeforeSemicolonsInForStatement = SpacePlacement.BeforeSemicolonsInForStatement, |
| 83 | + AfterSemicolonsInForStatement = SpacePlacement.AfterSemicolonsInForStatement, |
| 84 | + WithinOtherParentheses = SpacePlacement.WithinOtherParentheses, |
| 85 | + AfterCast = SpacePlacement.AfterCast, |
| 86 | + BeforeOpenSquareBracket = SpacePlacement.BeforeOpenSquareBracket, |
| 87 | + BetweenEmptySquareBrackets = SpacePlacement.BetweenEmptySquareBrackets, |
| 88 | + WithinSquareBrackets = SpacePlacement.WithinSquareBrackets, |
| 89 | + AfterColonInBaseTypeDeclaration = SpacePlacement.AfterColonInBaseTypeDeclaration, |
| 90 | + BeforeColonInBaseTypeDeclaration = SpacePlacement.BeforeColonInBaseTypeDeclaration, |
| 91 | + AfterComma = SpacePlacement.AfterComma, |
| 92 | + BeforeComma = SpacePlacement.BeforeComma, |
| 93 | + AfterDot = SpacePlacement.AfterDot, |
| 94 | + BeforeDot = SpacePlacement.BeforeDot, |
| 95 | + } |
| 96 | + |
| 97 | + [Flags] |
| 98 | + public enum RazorNewLinePlacement |
| 99 | + { |
| 100 | + None = 0, |
| 101 | + BeforeMembersInObjectInitializers = NewLinePlacement.BeforeMembersInObjectInitializers, |
| 102 | + BeforeMembersInAnonymousTypes = NewLinePlacement.BeforeMembersInAnonymousTypes, |
| 103 | + BeforeElse = NewLinePlacement.BeforeElse, |
| 104 | + BeforeCatch = NewLinePlacement.BeforeCatch, |
| 105 | + BeforeFinally = NewLinePlacement.BeforeFinally, |
| 106 | + BeforeOpenBraceInTypes = NewLinePlacement.BeforeOpenBraceInTypes, |
| 107 | + BeforeOpenBraceInAnonymousTypes = NewLinePlacement.BeforeOpenBraceInAnonymousTypes, |
| 108 | + BeforeOpenBraceInObjectCollectionArrayInitializers = NewLinePlacement.BeforeOpenBraceInObjectCollectionArrayInitializers, |
| 109 | + BeforeOpenBraceInProperties = NewLinePlacement.BeforeOpenBraceInProperties, |
| 110 | + BeforeOpenBraceInMethods = NewLinePlacement.BeforeOpenBraceInMethods, |
| 111 | + BeforeOpenBraceInAccessors = NewLinePlacement.BeforeOpenBraceInAccessors, |
| 112 | + BeforeOpenBraceInAnonymousMethods = NewLinePlacement.BeforeOpenBraceInAnonymousMethods, |
| 113 | + BeforeOpenBraceInLambdaExpressionBody = NewLinePlacement.BeforeOpenBraceInLambdaExpressionBody, |
| 114 | + BeforeOpenBraceInControlBlocks = NewLinePlacement.BeforeOpenBraceInControlBlocks, |
| 115 | + BetweenQueryExpressionClauses = NewLinePlacement.BetweenQueryExpressionClauses, |
| 116 | + } |
| 117 | + |
| 118 | + [Flags] |
| 119 | + public enum RazorIndentationPlacement |
| 120 | + { |
| 121 | + None = 0, |
| 122 | + Braces = IndentationPlacement.Braces, |
| 123 | + BlockContents = IndentationPlacement.BlockContents, |
| 124 | + SwitchCaseContents = IndentationPlacement.SwitchCaseContents, |
| 125 | + SwitchCaseContentsWhenBlock = IndentationPlacement.SwitchCaseContentsWhenBlock, |
| 126 | + SwitchSection = IndentationPlacement.SwitchSection, |
| 127 | + } |
| 128 | + |
| 129 | + public enum RazorBinaryOperatorSpacingOptions |
| 130 | + { |
| 131 | + Single = BinaryOperatorSpacingOptions.Single, |
| 132 | + Ignore = BinaryOperatorSpacingOptions.Ignore, |
| 133 | + Remove = BinaryOperatorSpacingOptions.Remove, |
| 134 | + } |
| 135 | + |
| 136 | + public enum RazorLabelPositionOptions |
| 137 | + { |
| 138 | + LeftMost = LabelPositionOptions.LeftMost, |
| 139 | + OneLess = LabelPositionOptions.OneLess, |
| 140 | + NoIndent = LabelPositionOptions.NoIndent, |
| 141 | + } |
| 142 | + |
| 143 | + public enum RazorNamespaceDeclarationPreference |
| 144 | + { |
| 145 | + BlockScoped = NamespaceDeclarationPreference.BlockScoped, |
| 146 | + FileScoped = NamespaceDeclarationPreference.FileScoped, |
| 147 | + } |
| 148 | +} |
0 commit comments