public CSharpSyntaxFormattingOptions( LineFormattingOptions lineFormatting, bool separateImportDirectiveGroups, SpacePlacement spacing, BinaryOperatorSpacingOptions spacingAroundBinaryOperator, NewLinePlacement newLines, LabelPositionOptions labelPositioning, IndentationPlacement indentation, bool wrappingKeepStatementsOnSingleLine, bool wrappingPreserveSingleLine) : base(lineFormatting, separateImportDirectiveGroups) { Spacing = spacing; SpacingAroundBinaryOperator = spacingAroundBinaryOperator; NewLines = newLines; LabelPositioning = labelPositioning; Indentation = indentation; WrappingKeepStatementsOnSingleLine = wrappingKeepStatementsOnSingleLine; WrappingPreserveSingleLine = wrappingPreserveSingleLine; }
private static string GetReplacementText( ITextView textView, LineFormattingOptions options, ITextSnapshotLine triviaLine, SyntaxTrivia trivia, int position) { // We're inside a comment. Instead of inserting just a newline here, insert // 1. a newline // 2. spaces up to the indentation of the current comment // 3. the comment prefix (extended out for repeated chars). // Then, depending on if the current comment starts with whitespace or not, we will insert those same spaces // to match. var commentStartColumn = triviaLine.GetColumnFromLineOffset(trivia.SpanStart - triviaLine.Start, textView.Options); var prefix = GetCommentPrefix(triviaLine.Snapshot, trivia, position); var replacementText = options.NewLine + commentStartColumn.CreateIndentationString(options.UseTabs, options.TabSize) + prefix + GetWhitespaceAfterCommentPrefix(trivia, triviaLine, prefix, position); return(replacementText); }
internal static async ValueTask <(SyntaxFormattingOptions?Syntax, LineFormattingOptions Line)> GetOptionsAsync(Document document, OptionSet?optionSet, CancellationToken cancellationToken) { var optionService = document.Project.Solution.Workspace.Services.GetRequiredService <IOptionService>(); var configOptionSet = (optionSet ?? await document.GetOptionsAsync(cancellationToken).ConfigureAwait(false)).AsAnalyzerConfigOptions(optionService, document.Project.Language); LineFormattingOptions lineFormattingOptions; SyntaxFormattingOptions?syntaxFormattingOptions; var syntaxFormattingService = document.GetLanguageService <ISyntaxFormattingService>(); if (syntaxFormattingService != null) { syntaxFormattingOptions = syntaxFormattingService.GetFormattingOptions(configOptionSet, fallbackOptions: null); lineFormattingOptions = syntaxFormattingOptions.LineFormatting; } else { syntaxFormattingOptions = null; lineFormattingOptions = LineFormattingOptions.Create(configOptionSet, fallbackOptions: null); } return(syntaxFormattingOptions, lineFormattingOptions); }
public Task <Document> FormatAsync(Document document, IEnumerable <TextSpan>?spans, LineFormattingOptions lineFormattingOptions, SyntaxFormattingOptions?syntaxFormattingOptions, CancellationToken cancellationToken) => Task.FromResult(document.WithText(SourceText.From($"Formatted with options: {lineFormattingOptions.ToString().Replace("\r", "\\r").Replace("\n", "\\n")}")));
public static Task <LineFormattingOptions> GetLineFormattingOptionsAsync(this Document document, IGlobalOptionService globalOptions, CancellationToken cancellationToken) => LineFormattingOptions.FromDocumentAsync(document, globalOptions.GetLineFormattingOptions(document.Project.Language), cancellationToken);
public VirtualTreePoint?GetEndPoint(SyntaxNode node, LineFormattingOptions options, EnvDTE.vsCMPart?part) { var text = node.SyntaxTree.GetText(); return(GetEndPoint(text, options, node, part ?? DefaultPart)); }
protected abstract VirtualTreePoint?GetEndPoint(SourceText text, LineFormattingOptions options, SyntaxNode node, EnvDTE.vsCMPart part);
public static DocumentationCommentOptions GetDocumentationCommentOptions(this IGlobalOptionService globalOptions, LineFormattingOptions lineFormatting, string language) => new()
public Task <Document> FormatAsync(Document document, IEnumerable <TextSpan>?spans, LineFormattingOptions lineFormattingOptions, SyntaxFormattingOptions?syntaxFormattingOptions, CancellationToken cancellationToken) { Contract.ThrowIfNull(syntaxFormattingOptions); return(Formatter.FormatAsync(document, spans, syntaxFormattingOptions, rules: null, cancellationToken)); }