diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/CSharpFormatEngine.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/CSharpFormatEngine.cs index 11c3eb47cef74..792e58bfdb761 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/CSharpFormatEngine.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/CSharpFormatEngine.cs @@ -29,7 +29,7 @@ public CSharpFormatEngine( internal override IHeaderFacts HeaderFacts => CSharpHeaderFacts.Instance; protected override AbstractTriviaDataFactory CreateTriviaFactory() - => new TriviaDataFactory(this.TreeData, this.Options); + => new TriviaDataFactory(this.TreeData, this.Options.LineFormatting); protected override AbstractFormattingResult CreateFormattingResult(TokenStream tokenStream) => new FormattingResult(this.TreeData, tokenStream, this.SpanToFormat); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/CSharpStructuredTriviaFormatEngine.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/CSharpStructuredTriviaFormatEngine.cs index 182588d383675..cec283c043333 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/CSharpStructuredTriviaFormatEngine.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/CSharpStructuredTriviaFormatEngine.cs @@ -43,7 +43,7 @@ private CSharpStructuredTriviaFormatEngine( internal override IHeaderFacts HeaderFacts => CSharpHeaderFacts.Instance; protected override AbstractTriviaDataFactory CreateTriviaFactory() - => new TriviaDataFactory(this.TreeData, this.Options); + => new TriviaDataFactory(this.TreeData, this.Options.LineFormatting); protected override FormattingContext CreateFormattingContext(TokenStream tokenStream, CancellationToken cancellationToken) => new(this, tokenStream); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.ComplexTrivia.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.ComplexTrivia.cs index 85172a3f82170..21c63a5e8f9a0 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.ComplexTrivia.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.ComplexTrivia.cs @@ -19,9 +19,9 @@ internal partial class TriviaDataFactory /// represents a general trivia between two tokens. slightly more expensive than others since it /// needs to calculate stuff unlike other cases /// - private class ComplexTrivia : AbstractComplexTrivia + private sealed class ComplexTrivia : AbstractComplexTrivia { - public ComplexTrivia(SyntaxFormattingOptions options, TreeData treeInfo, SyntaxToken token1, SyntaxToken token2) + public ComplexTrivia(LineFormattingOptions options, TreeData treeInfo, SyntaxToken token1, SyntaxToken token2) : base(options, treeInfo, token1, token2) { } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.FormattedComplexTrivia.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.FormattedComplexTrivia.cs index 4a525360d5b33..d62c4c9a6d9a4 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.FormattedComplexTrivia.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.FormattedComplexTrivia.cs @@ -13,7 +13,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Formatting; internal partial class TriviaDataFactory { - private class FormattedComplexTrivia : TriviaDataWithList + private sealed class FormattedComplexTrivia : TriviaDataWithList { private readonly CSharpTriviaFormatter _formatter; private readonly IList _textChanges; @@ -27,7 +27,7 @@ public FormattedComplexTrivia( int spaces, string originalString, CancellationToken cancellationToken) - : base(context.Options, LanguageNames.CSharp) + : base(context.Options.LineFormatting) { Contract.ThrowIfNull(context); Contract.ThrowIfNull(formattingRules); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.ModifiedComplexTrivia.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.ModifiedComplexTrivia.cs index 5bce6fbd0fd38..1db933c501f3b 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.ModifiedComplexTrivia.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.ModifiedComplexTrivia.cs @@ -14,12 +14,12 @@ namespace Microsoft.CodeAnalysis.CSharp.Formatting; internal partial class TriviaDataFactory { - private class ModifiedComplexTrivia : TriviaDataWithList + private sealed class ModifiedComplexTrivia : TriviaDataWithList { private readonly ComplexTrivia _original; - public ModifiedComplexTrivia(SyntaxFormattingOptions options, ComplexTrivia original, int lineBreaks, int space) - : base(options, original.Token1.Language) + public ModifiedComplexTrivia(LineFormattingOptions options, ComplexTrivia original, int lineBreaks, int space) + : base(options) { Contract.ThrowIfNull(original); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.cs index a7313cb07f61c..1ec647df3cd22 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/Engine/Trivia/TriviaDataFactory.cs @@ -18,7 +18,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Formatting; /// internal partial class TriviaDataFactory : AbstractTriviaDataFactory { - public TriviaDataFactory(TreeData treeInfo, SyntaxFormattingOptions options) + public TriviaDataFactory(TreeData treeInfo, LineFormattingOptions options) : base(treeInfo, options) { } @@ -118,7 +118,7 @@ private static bool ContainsOnlyWhitespace(Analyzer.AnalysisResult result) { // calculate actual space size from tab var spaces = CalculateSpaces(token1, token2); - return new ModifiedWhitespace(this.Options, result.LineBreaks, indentation: spaces, elastic: result.TreatAsElastic, language: LanguageNames.CSharp); + return new ModifiedWhitespace(this.Options, result.LineBreaks, indentation: spaces, elastic: result.TreatAsElastic); } // check whether we can cache trivia info for current indentation diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.AbstractComplexTrivia.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.AbstractComplexTrivia.cs index 8e14ebe0b9565..c081c5813c4b4 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.AbstractComplexTrivia.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.AbstractComplexTrivia.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Threading; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Shared.Utilities; using Roslyn.Utilities; @@ -21,8 +20,8 @@ protected abstract class AbstractComplexTrivia : TriviaDataWithList private readonly bool _treatAsElastic; - public AbstractComplexTrivia(SyntaxFormattingOptions options, TreeData treeInfo, SyntaxToken token1, SyntaxToken token2) - : base(options, token1.Language) + public AbstractComplexTrivia(LineFormattingOptions options, TreeData treeInfo, SyntaxToken token1, SyntaxToken token2) + : base(options) { Contract.ThrowIfNull(treeInfo); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.FormattedWhitespace.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.FormattedWhitespace.cs index 82ae7747c65b3..2e1c7f1a60ce4 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.FormattedWhitespace.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.FormattedWhitespace.cs @@ -13,12 +13,12 @@ namespace Microsoft.CodeAnalysis.Formatting; internal abstract partial class AbstractTriviaDataFactory { - protected class FormattedWhitespace : TriviaData + protected sealed class FormattedWhitespace : TriviaData { private readonly string _newString; - public FormattedWhitespace(SyntaxFormattingOptions options, int lineBreaks, int indentation, string language) - : base(options, language) + public FormattedWhitespace(LineFormattingOptions options, int lineBreaks, int indentation) + : base(options) { this.LineBreaks = Math.Max(0, lineBreaks); this.Spaces = Math.Max(0, indentation); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.ModifiedWhitespace.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.ModifiedWhitespace.cs index bca9cdecd1006..474e09b6a354d 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.ModifiedWhitespace.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.ModifiedWhitespace.cs @@ -11,18 +11,18 @@ namespace Microsoft.CodeAnalysis.Formatting; internal abstract partial class AbstractTriviaDataFactory { - protected class ModifiedWhitespace : Whitespace + protected sealed class ModifiedWhitespace : Whitespace { private readonly Whitespace? _original; - public ModifiedWhitespace(SyntaxFormattingOptions options, int lineBreaks, int indentation, bool elastic, string language) - : base(options, lineBreaks, indentation, elastic, language) + public ModifiedWhitespace(LineFormattingOptions options, int lineBreaks, int indentation, bool elastic) + : base(options, lineBreaks, indentation, elastic) { _original = null; } - public ModifiedWhitespace(SyntaxFormattingOptions options, Whitespace original, int lineBreaks, int indentation, bool elastic, string language) - : base(options, lineBreaks, indentation, elastic, language) + public ModifiedWhitespace(LineFormattingOptions options, Whitespace original, int lineBreaks, int indentation, bool elastic) + : base(options, lineBreaks, indentation, elastic) { Contract.ThrowIfNull(original); _original = original; @@ -83,7 +83,7 @@ public override void Format( CancellationToken cancellationToken, int tokenPairIndex = TokenPairIndexNotNeeded) { - formattingResultApplier(tokenPairIndex, context.TokenStream, new FormattedWhitespace(this.Options, this.LineBreaks, this.Spaces, this.Language)); + formattingResultApplier(tokenPairIndex, context.TokenStream, new FormattedWhitespace(this.Options, this.LineBreaks, this.Spaces)); } } } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.Whitespace.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.Whitespace.cs index 116dda5456313..bda9b5b3785b4 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.Whitespace.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.Whitespace.cs @@ -21,14 +21,14 @@ protected class Whitespace : TriviaData { private readonly bool _elastic; - public Whitespace(SyntaxFormattingOptions options, int space, bool elastic, string language) - : this(options, lineBreaks: 0, indentation: space, elastic: elastic, language: language) + public Whitespace(LineFormattingOptions options, int space, bool elastic) + : this(options, lineBreaks: 0, indentation: space, elastic: elastic) { Contract.ThrowIfFalse(space >= 0); } - public Whitespace(SyntaxFormattingOptions options, int lineBreaks, int indentation, bool elastic, string language) - : base(options, language) + public Whitespace(LineFormattingOptions options, int lineBreaks, int indentation, bool elastic) + : base(options) { _elastic = elastic; @@ -47,11 +47,9 @@ public Whitespace(SyntaxFormattingOptions options, int lineBreaks, int indentati public override TriviaData WithSpace(int space, FormattingContext context, ChainedFormattingRules formattingRules) { if (this.LineBreaks == 0 && this.Spaces == space) - { return this; - } - return new ModifiedWhitespace(this.Options, this, /*lineBreak*/0, space, elastic: false, language: this.Language); + return new ModifiedWhitespace(this.Options, this, /*lineBreak*/0, space, elastic: false); } public override TriviaData WithLine(int line, int indentation, FormattingContext context, ChainedFormattingRules formattingRules, CancellationToken cancellationToken) @@ -63,7 +61,7 @@ public override TriviaData WithLine(int line, int indentation, FormattingContext return this; } - return new ModifiedWhitespace(this.Options, this, line, indentation, elastic: false, language: this.Language); + return new ModifiedWhitespace(this.Options, this, line, indentation, elastic: false); } public override TriviaData WithIndentation( @@ -74,7 +72,7 @@ public override TriviaData WithIndentation( return this; } - return new ModifiedWhitespace(this.Options, this, this.LineBreaks, indentation, elastic: false, language: this.Language); + return new ModifiedWhitespace(this.Options, this, this.LineBreaks, indentation, elastic: false); } public override void Format( diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.cs index 19b2882c81115..71a0fce380856 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/AbstractTriviaDataFactory.cs @@ -2,6 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; +using System.Collections.Generic; +using System.Security.Principal; using System.Threading; using Microsoft.CodeAnalysis.Diagnostics; using Roslyn.Utilities; @@ -14,23 +17,73 @@ internal abstract partial class AbstractTriviaDataFactory private const int LineBreakCacheSize = 5; private const int IndentationLevelCacheSize = 20; + private static readonly Dictionary s_optionsToWhitespace = new(); + private static Tuple? s_lastOptionAndWhitespace; + protected readonly TreeData TreeInfo; - protected readonly SyntaxFormattingOptions Options; + protected readonly LineFormattingOptions Options; private readonly Whitespace[] _spaces; - private readonly Whitespace?[,] _whitespaces = new Whitespace[LineBreakCacheSize, IndentationLevelCacheSize]; + private readonly Whitespace[,] _whitespaces; - protected AbstractTriviaDataFactory(TreeData treeInfo, SyntaxFormattingOptions options) + protected AbstractTriviaDataFactory(TreeData treeInfo, LineFormattingOptions options) { Contract.ThrowIfNull(treeInfo); TreeInfo = treeInfo; Options = options; - _spaces = new Whitespace[SpaceCacheSize]; - for (var i = 0; i < SpaceCacheSize; i++) + (_spaces, _whitespaces) = GetSpacesAndWhitespaces(options); + } + + private static (Whitespace[] spaces, Whitespace[,] whitespaces) GetSpacesAndWhitespaces(LineFormattingOptions options) + { + // Fast path where we'er asking for the same options as last time + var lastOptionAndWhitespace = s_lastOptionAndWhitespace; + if (lastOptionAndWhitespace?.Item1 == options) + return lastOptionAndWhitespace.Item2; + + // Otherwise, get from the dictionary, computing if necessary. + var (spaces, whitespaces) = ComputeAndCacheSpacesAndWhitespaces(options); + + // Cache this result for the next time. + s_lastOptionAndWhitespace = Tuple.Create(options, (spaces, whitespaces)); + return (spaces, whitespaces); + + static (Whitespace[] spaces, Whitespace[,] whitespaces) ComputeAndCacheSpacesAndWhitespaces(LineFormattingOptions options) { - _spaces[i] = new Whitespace(Options, space: i, elastic: false, language: treeInfo.Root.Language); + // First check if it's already in the cache. + lock (s_optionsToWhitespace) + { + if (s_optionsToWhitespace.TryGetValue(options, out var result)) + return result; + } + + // If not, compute it. + var spaces = new Whitespace[SpaceCacheSize]; + for (var i = 0; i < SpaceCacheSize; i++) + spaces[i] = new Whitespace(options, space: i, elastic: false); + + var whitespaces = new Whitespace[LineBreakCacheSize, IndentationLevelCacheSize]; + for (var lineIndex = 0; lineIndex < LineBreakCacheSize; lineIndex++) + { + for (var indentationLevel = 0; indentationLevel < IndentationLevelCacheSize; indentationLevel++) + { + var indentation = indentationLevel * options.IndentationSize; + whitespaces[lineIndex, indentationLevel] = new Whitespace( + options, lineBreaks: lineIndex + 1, indentation: indentation, elastic: false); + } + } + + // Attempt to store in cache. But defer to any other thread that may have already stored it. + lock (s_optionsToWhitespace) + { + if (s_optionsToWhitespace.TryGetValue(options, out var result)) + return result; + + s_optionsToWhitespace[options] = (spaces, whitespaces); + return (spaces, whitespaces); + } } } @@ -41,7 +94,7 @@ protected TriviaData GetSpaceTriviaData(int space, bool elastic = false) // if result has elastic trivia in them, never use cache if (elastic) { - return new Whitespace(this.Options, space, elastic: true, language: this.TreeInfo.Root.Language); + return new Whitespace(this.Options, space, elastic: true); } if (space < SpaceCacheSize) @@ -50,7 +103,7 @@ protected TriviaData GetSpaceTriviaData(int space, bool elastic = false) } // create a new space - return new Whitespace(this.Options, space, elastic: false, language: this.TreeInfo.Root.Language); + return new Whitespace(this.Options, space, elastic: false); } protected TriviaData GetWhitespaceTriviaData(int lineBreaks, int indentation, bool useTriviaAsItIs, bool elastic) @@ -75,29 +128,13 @@ protected TriviaData GetWhitespaceTriviaData(int lineBreaks, int indentation, bo if (indentationLevel < IndentationLevelCacheSize) { var lineIndex = lineBreaks - 1; - EnsureWhitespaceTriviaInfo(lineIndex, indentationLevel); return _whitespaces[lineIndex, indentationLevel]!; } } - return - useTriviaAsItIs - ? new Whitespace(this.Options, lineBreaks, indentation, elastic, language: this.TreeInfo.Root.Language) - : new ModifiedWhitespace(this.Options, lineBreaks, indentation, elastic, language: this.TreeInfo.Root.Language); - } - - private void EnsureWhitespaceTriviaInfo(int lineIndex, int indentationLevel) - { - Contract.ThrowIfFalse(lineIndex is >= 0 and < LineBreakCacheSize); - Contract.ThrowIfFalse(indentationLevel >= 0 && indentationLevel < _whitespaces.Length / _whitespaces.Rank); - - // set up caches - if (_whitespaces[lineIndex, indentationLevel] == null) - { - var indentation = indentationLevel * Options.IndentationSize; - var triviaInfo = new Whitespace(Options, lineBreaks: lineIndex + 1, indentation: indentation, elastic: false, language: this.TreeInfo.Root.Language); - Interlocked.CompareExchange(ref _whitespaces[lineIndex, indentationLevel], triviaInfo, null); - } + return useTriviaAsItIs + ? new Whitespace(this.Options, lineBreaks, indentation, elastic) + : new ModifiedWhitespace(this.Options, lineBreaks, indentation, elastic); } public abstract TriviaData CreateLeadingTrivia(SyntaxToken token); diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/TriviaData.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/TriviaData.cs index 5d39109a8d864..4f62d0df988a8 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/TriviaData.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/TriviaData.cs @@ -18,16 +18,12 @@ internal abstract class TriviaData { protected const int TokenPairIndexNotNeeded = int.MinValue; - private readonly string _language; - - protected TriviaData(SyntaxFormattingOptions options, string language) + protected TriviaData(LineFormattingOptions options) { Options = options; - _language = language; } - protected SyntaxFormattingOptions Options { get; } - protected string Language => _language; + protected LineFormattingOptions Options { get; } public int LineBreaks { get; protected set; } public int Spaces { get; protected set; } diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/TriviaDataWithList.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/TriviaDataWithList.cs index dff9d8703a24c..9cc7dc29fce5e 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/TriviaDataWithList.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/Engine/TriviaDataWithList.cs @@ -3,11 +3,10 @@ // See the LICENSE file in the project root for more information. using System.Threading; -using Microsoft.CodeAnalysis.Diagnostics; namespace Microsoft.CodeAnalysis.Formatting; -internal abstract class TriviaDataWithList(SyntaxFormattingOptions options, string language) : TriviaData(options, language) +internal abstract class TriviaDataWithList(LineFormattingOptions options) : TriviaData(options) { public abstract SyntaxTriviaList GetTriviaList(CancellationToken cancellationToken); } diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.AbstractLineBreakTrivia.vb b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.AbstractLineBreakTrivia.vb index d75d120ab0a90..4b543b4e32ee7 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.AbstractLineBreakTrivia.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.AbstractLineBreakTrivia.vb @@ -15,12 +15,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Protected ReadOnly _original As String Protected ReadOnly _newString As String - Public Sub New(options As SyntaxFormattingOptions, + Public Sub New(options As LineFormattingOptions, original As String, lineBreaks As Integer, indentation As Integer, elastic As Boolean) - MyBase.New(options, lineBreaks, indentation, elastic, LanguageNames.VisualBasic) + MyBase.New(options, lineBreaks, indentation, elastic) Me._original = original Me._newString = CreateStringFromState() diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.ComplexTrivia.vb b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.ComplexTrivia.vb index 7644e750dd40b..71c51db59f694 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.ComplexTrivia.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.ComplexTrivia.vb @@ -17,7 +17,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Private Class ComplexTrivia Inherits AbstractComplexTrivia - Public Sub New(options As SyntaxFormattingOptions, treeInfo As TreeData, token1 As SyntaxToken, token2 As SyntaxToken) + Public Sub New(options As LineFormattingOptions, treeInfo As TreeData, token1 As SyntaxToken, token2 As SyntaxToken) MyBase.New(options, treeInfo, token1, token2) Contract.ThrowIfNull(treeInfo) End Sub diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.FormattedComplexTrivia.vb b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.FormattedComplexTrivia.vb index ba33b5201885f..07fc99fba20f8 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.FormattedComplexTrivia.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.FormattedComplexTrivia.vb @@ -8,7 +8,7 @@ Imports Microsoft.CodeAnalysis.Text Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Partial Friend Class TriviaDataFactory - Private Class FormattedComplexTrivia + Private NotInheritable Class FormattedComplexTrivia Inherits TriviaDataWithList Private ReadOnly _formatter As VisualBasicTriviaFormatter @@ -22,7 +22,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting spaces As Integer, originalString As String, cancellationToken As CancellationToken) - MyBase.New(context.Options, LanguageNames.VisualBasic) + MyBase.New(context.Options.LineFormatting) Contract.ThrowIfNull(context) Contract.ThrowIfNull(formattingRules) diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.LineContinuationTrivia.vb b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.LineContinuationTrivia.vb index 83e0d3bf3d7dd..52007299afb51 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.LineContinuationTrivia.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.LineContinuationTrivia.vb @@ -16,7 +16,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Private Class LineContinuationTrivia Inherits AbstractLineBreakTrivia - Public Sub New(options As SyntaxFormattingOptions, + Public Sub New(options As LineFormattingOptions, originalString As String, indentation As Integer) MyBase.New(options, originalString, 1, indentation, False) diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.ModifiedComplexTrivia.vb b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.ModifiedComplexTrivia.vb index 2062779935531..4dcd37bdaca7e 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.ModifiedComplexTrivia.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.ModifiedComplexTrivia.vb @@ -3,19 +3,18 @@ ' See the LICENSE file in the project root for more information. Imports System.Threading -Imports Microsoft.CodeAnalysis.Diagnostics Imports Microsoft.CodeAnalysis.Formatting Imports Microsoft.CodeAnalysis.Text Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Partial Friend Class TriviaDataFactory - Private Class ModifiedComplexTrivia + Private NotInheritable Class ModifiedComplexTrivia Inherits TriviaDataWithList Private ReadOnly _original As ComplexTrivia - Public Sub New(options As SyntaxFormattingOptions, original As ComplexTrivia, lineBreaks As Integer, space As Integer) - MyBase.New(options, LanguageNames.VisualBasic) + Public Sub New(options As LineFormattingOptions, original As ComplexTrivia, lineBreaks As Integer, space As Integer) + MyBase.New(options) Contract.ThrowIfNull(original) Me._original = original diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.vb b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.vb index 11bdd60ff1700..3475c8aad1dc2 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/Trivia/TriviaDataFactory.vb @@ -20,7 +20,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Private ReadOnly _lineContinuations(s_lineContinuationCacheSize) As LineContinuationTrivia - Public Sub New(treeInfo As TreeData, options As SyntaxFormattingOptions) + Public Sub New(treeInfo As TreeData, options As LineFormattingOptions) MyBase.New(treeInfo, options) End Sub @@ -160,7 +160,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting If result.LineBreaks = 0 AndAlso result.Tab > 0 Then ' calculate actual space size from tab Dim spaces = CalculateSpaces(token1, token2) - Return New ModifiedWhitespace(Me.Options, result.LineBreaks, indentation:=spaces, elastic:=result.TreatAsElastic, language:=LanguageNames.VisualBasic) + Return New ModifiedWhitespace(Me.Options, result.LineBreaks, indentation:=spaces, elastic:=result.TreatAsElastic) End If ' check whether we can cache trivia info for current indentation diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/VisualBasicFormatEngine.vb b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/VisualBasicFormatEngine.vb index d6b00a74ecdb5..4e89985b11d94 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/VisualBasicFormatEngine.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/VisualBasicFormatEngine.vb @@ -27,7 +27,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Friend Overrides ReadOnly Property HeaderFacts As IHeaderFacts = VisualBasicHeaderFacts.Instance Protected Overrides Function CreateTriviaFactory() As AbstractTriviaDataFactory - Return New TriviaDataFactory(Me.TreeData, Me.Options) + Return New TriviaDataFactory(Me.TreeData, Me.Options.LineFormatting) End Function Protected Overrides Function CreateFormattingResult(tokenStream As TokenStream) As AbstractFormattingResult diff --git a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/VisualBasicStructuredTriviaFormatEngine.vb b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/VisualBasicStructuredTriviaFormatEngine.vb index ac7baf64c323a..e683b19beacec 100644 --- a/src/Workspaces/VisualBasic/Portable/Formatting/Engine/VisualBasicStructuredTriviaFormatEngine.vb +++ b/src/Workspaces/VisualBasic/Portable/Formatting/Engine/VisualBasicStructuredTriviaFormatEngine.vb @@ -35,7 +35,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting Friend Overrides ReadOnly Property HeaderFacts As IHeaderFacts = VisualBasicHeaderFacts.Instance Protected Overrides Function CreateTriviaFactory() As AbstractTriviaDataFactory - Return New TriviaDataFactory(Me.TreeData, Me.Options) + Return New TriviaDataFactory(Me.TreeData, Me.Options.LineFormatting) End Function Protected Overrides Function CreateFormattingContext(tokenStream As TokenStream, cancellationToken As CancellationToken) As FormattingContext