public TokenStream(TreeData treeData, OptionSet optionSet, TextSpan spanToFormat, AbstractTriviaDataFactory factory) { using (Logger.LogBlock(FunctionId.Formatting_TokenStreamConstruction, CancellationToken.None)) { // initialize basic info _factory = factory; _treeData = treeData; _optionSet = optionSet; // use some heuristics to get initial size of list rather than blindly start from default size == 4 int sizeOfList = spanToFormat.Length / MagicTextLengthToTokensRatio; _tokens = new List<SyntaxToken>(sizeOfList); _tokens.AddRange(_treeData.GetApplicableTokens(spanToFormat)); Contract.Requires(this.TokenCount > 0); // initialize trivia related info _cachedOriginalTriviaInfo = new TriviaData[this.TokenCount - 1]; _tokenToIndexMap = new Dictionary<SyntaxToken, int>(this.TokenCount); for (int i = 0; i < this.TokenCount; i++) { _tokenToIndexMap.Add(_tokens[i], i); } // Func Cache _getTriviaData = this.GetTriviaData; _getOriginalTriviaData = this.GetOriginalTriviaData; } DebugCheckTokenOrder(); }
internal AbstractFormattingResult( TreeData treeInfo, TokenStream tokenStream, TextSpan formattedSpan) { this.TreeInfo = treeInfo; this.TokenStream = tokenStream; this.FormattedSpan = formattedSpan; _lazyChanges = new CancellableLazy <IList <TextChange> >(CreateTextChanges); _lazyNode = new CancellableLazy <SyntaxNode>(CreateFormattedRoot); }
protected AbstractTriviaDataFactory(TreeData treeInfo, OptionSet optionSet) { Contract.ThrowIfNull(treeInfo); Contract.ThrowIfNull(optionSet); this.TreeInfo = treeInfo; this.OptionSet = optionSet; for (int i = 0; i < SpaceCacheSize; i++) { this.spaces[i] = new Whitespace(this.OptionSet, space: i, elastic: false, language: treeInfo.Root.Language); } }
public StructuredTrivia(SyntaxTrivia trivia, int initialColumn) : base(trivia.GetStructure() !) { Contract.ThrowIfFalse(trivia.HasStructure); _trivia = trivia; var root = trivia.GetStructure() !; var text = GetText(); _initialColumn = initialColumn; _treeData = (text == null) ? (TreeData) new Node(root) : new NodeAndText(root, text); }
protected AbstractTriviaDataFactory(TreeData treeInfo, AnalyzerConfigOptions options) { Contract.ThrowIfNull(treeInfo); Contract.ThrowIfNull(options); this.TreeInfo = treeInfo; this.Options = options; for (var i = 0; i < SpaceCacheSize; i++) { _spaces[i] = new Whitespace(this.Options, space: i, elastic: false, language: treeInfo.Root.Language); } }
public StructuredTrivia(SyntaxTrivia trivia, int initialColumn) : base(trivia.GetStructure()) { Contract.ThrowIfFalse(trivia.HasStructure); _trivia = trivia; var root = trivia.GetStructure(); var text = GetText(); _initialColumn = initialColumn; _treeData = (text == null) ? (TreeData)new Node(root) : new NodeAndText(root, text); }
protected AbstractTriviaDataFactory(TreeData treeInfo, SyntaxFormattingOptions options) { Contract.ThrowIfNull(treeInfo); TreeInfo = treeInfo; Options = options; _spaces = new Whitespace[SpaceCacheSize]; for (var i = 0; i < SpaceCacheSize; i++) { _spaces[i] = new Whitespace(Options, space: i, elastic: false, language: treeInfo.Root.Language); } }
public AbstractFormatEngine( TreeData treeData, OptionSet optionSet, IEnumerable <IFormattingRule> formattingRules, SyntaxToken token1, SyntaxToken token2) : this( treeData, optionSet, new ChainedFormattingRules(formattingRules, optionSet), token1, token2) { }
internal AbstractFormattingResult( TreeData treeInfo, TokenStream tokenStream, TextSpan formattedSpan, TaskExecutor taskExecutor) { this.TreeInfo = treeInfo; this.TokenStream = tokenStream; this.FormattedSpan = formattedSpan; this.TaskExecutor = taskExecutor; _lazyChanges = new CancellableLazy<IList<TextChange>>(CreateTextChanges); _lazyNode = new CancellableLazy<SyntaxNode>(CreateFormattedRoot); }
public AbstractFormatEngine( TreeData treeData, SyntaxFormattingOptions options, IEnumerable <AbstractFormattingRule> formattingRules, SyntaxToken startToken, SyntaxToken endToken) : this( treeData, options, new ChainedFormattingRules(formattingRules, options), startToken, endToken) { }
public AbstractFormatEngine( TreeData treeData, AnalyzerConfigOptions options, IEnumerable <AbstractFormattingRule> formattingRules, SyntaxToken token1, SyntaxToken token2) : this( treeData, options, new ChainedFormattingRules(formattingRules, options), token1, token2) { }
public AbstractComplexTrivia(OptionSet optionSet, TreeData treeInfo, SyntaxToken token1, SyntaxToken token2) : base(optionSet, token1.Language) { Contract.ThrowIfNull(treeInfo); _token1 = token1; _token2 = token2; _treatAsElastic = CommonFormattingHelpers.HasAnyWhitespaceElasticTrivia(token1, token2); this.TreeInfo = treeInfo; this.OriginalString = this.TreeInfo.GetTextBetween(token1, token2); ExtractLineAndSpace(this.OriginalString, out var lineBreaks, out var spaces); this.LineBreaks = lineBreaks; this.Spaces = spaces; }
protected AbstractTriviaDataFactory(TreeData treeInfo, AnalyzerConfigOptions options) { Contract.ThrowIfNull(treeInfo); Contract.ThrowIfNull(options); this.TreeInfo = treeInfo; this.Options = options; UseTabs = options.GetOption(FormattingOptions2.UseTabs); TabSize = options.GetOption(FormattingOptions2.TabSize); IndentationSize = options.GetOption(FormattingOptions2.IndentationSize); for (var i = 0; i < SpaceCacheSize; i++) { _spaces[i] = new Whitespace(this.Options, space: i, elastic: false, language: treeInfo.Root.Language); } }
internal AbstractFormatEngine( TreeData treeData, OptionSet optionSet, ChainedFormattingRules formattingRules, SyntaxToken token1, SyntaxToken token2, TaskExecutor executor) { Contract.ThrowIfNull(optionSet); Contract.ThrowIfNull(treeData); Contract.ThrowIfNull(formattingRules); Contract.ThrowIfNull(executor); Contract.ThrowIfTrue(treeData.Root.IsInvalidTokenRange(token1, token2)); this.OptionSet = optionSet; this.TreeData = treeData; _formattingRules = formattingRules; _token1 = token1; _token2 = token2; // get span and common root this.SpanToFormat = GetSpanToFormat(); _commonRoot = token1.GetCommonRoot(token2); if (token1 == default) { _language = token2.Language; } else { _language = token1.Language; } // set synchronous task executor if it is enabled (explicitly or as part of debug mode) or if there is not // many things to format var synchronousExecutorAllowed = !optionSet.GetOption(FormattingOptions.AllowConcurrent) || optionSet.GetOption(FormattingOptions.DebugMode, _language); var useSynchronousExecutor = synchronousExecutorAllowed || SpanToFormat.Length < ConcurrentThreshold; TaskExecutor = useSynchronousExecutor ? TaskExecutor.Synchronous : executor; }
internal AbstractFormatEngine( TreeData treeData, SyntaxFormattingOptions options, ChainedFormattingRules formattingRules, SyntaxToken startToken, SyntaxToken endToken) { Contract.ThrowIfTrue(treeData.Root.IsInvalidTokenRange(startToken, endToken)); this.Options = options; this.TreeData = treeData; _formattingRules = formattingRules; _startToken = startToken; _endToken = endToken; // get span and common root this.SpanToFormat = GetSpanToFormat(); _commonRoot = startToken.GetCommonRoot(endToken) ?? throw ExceptionUtilities.Unreachable; }
internal AbstractFormatEngine( TreeData treeData, OptionSet optionSet, ChainedFormattingRules formattingRules, SyntaxToken token1, SyntaxToken token2, TaskExecutor executor) { Contract.ThrowIfNull(optionSet); Contract.ThrowIfNull(treeData); Contract.ThrowIfNull(formattingRules); Contract.ThrowIfNull(executor); Contract.ThrowIfTrue(treeData.Root.IsInvalidTokenRange(token1, token2)); this.OptionSet = optionSet; this.TreeData = treeData; this.formattingRules = formattingRules; this.token1 = token1; this.token2 = token2; // get span and common root this.SpanToFormat = GetSpanToFormat(); this.commonRoot = token1.GetCommonRoot(token2); if (token1 == default(SyntaxToken)) { this.language = token2.Language; } else { this.language = token1.Language; } // set synchronous task executor if it is debug mode or if there is not many things to format this.TaskExecutor = optionSet.GetOption(FormattingOptions.DebugMode, this.language) ? TaskExecutor.Synchronous : (SpanToFormat.Length < ConcurrentThreshold) ? TaskExecutor.Synchronous : executor; }
internal AbstractFormatEngine( TreeData treeData, AnalyzerConfigOptions options, ChainedFormattingRules formattingRules, SyntaxToken token1, SyntaxToken token2) { Contract.ThrowIfNull(options); Contract.ThrowIfNull(treeData); Contract.ThrowIfNull(formattingRules); Contract.ThrowIfTrue(treeData.Root.IsInvalidTokenRange(token1, token2)); this.Options = options; this.TreeData = treeData; _formattingRules = formattingRules; _token1 = token1; _token2 = token2; // get span and common root this.SpanToFormat = GetSpanToFormat(); _commonRoot = token1.GetCommonRoot(token2) ?? throw ExceptionUtilities.Unreachable; }
public static void ProcessTextBetweenTokens( this string text, TreeData treeInfo, SyntaxToken baseToken, int tabSize, out int lineBreaks, out int spaceOrIndentation) { // initialize out param lineBreaks = text.GetNumberOfLineBreaks(); // multiple line case if (lineBreaks > 0) { var indentationString = text.GetLastLineText(); spaceOrIndentation = indentationString.GetColumnFromLineOffset(indentationString.Length, tabSize); return; } // with tab, more expensive way. get column of token1 and then calculate right space amount var initialColumn = baseToken.RawKind == 0 ? 0 /* the very beginning of the file */ : treeInfo.GetOriginalColumn(tabSize, baseToken); spaceOrIndentation = text.ConvertTabToSpace(tabSize, baseToken.ToString().GetTextColumn(tabSize, initialColumn), text.Length); }
public TokenStream( TreeData treeData, AnalyzerConfigOptions options, TextSpan spanToFormat, AbstractTriviaDataFactory factory ) { using ( Logger.LogBlock( FunctionId.Formatting_TokenStreamConstruction, CancellationToken.None ) ) { // initialize basic info _factory = factory; _treeData = treeData; _options = options; // use some heuristics to get initial size of list rather than blindly start from default size == 4 var sizeOfList = spanToFormat.Length / MagicTextLengthToTokensRatio; _tokens = new SegmentedList <SyntaxToken>(sizeOfList); _tokens.AddRange(_treeData.GetApplicableTokens(spanToFormat)); Debug.Assert(this.TokenCount > 0); // initialize trivia related info _cachedOriginalTriviaInfo = new SegmentedArray <TriviaData>(this.TokenCount - 1); // Func Cache _getTriviaData = this.GetTriviaData; _getOriginalTriviaData = this.GetOriginalTriviaData; } DebugCheckTokenOrder(); }
public Debug(SyntaxNode root, SourceText text) : base(root, text) { _debugNodeData = new Node(root); }
public ComplexTrivia(OptionSet optionSet, TreeData treeInfo, SyntaxToken token1, SyntaxToken token2) : base(optionSet, treeInfo, token1, token2) { }
internal FormattingResult(TreeData treeInfo, TokenStream tokenStream, TextSpan spanToFormat, TaskExecutor taskExecutor) : base(treeInfo, tokenStream, spanToFormat, taskExecutor) { }
public TriviaDataFactory(TreeData treeInfo, OptionSet optionSet) : base(treeInfo, optionSet) { }