public void GetTokenLength(SyntaxToken token, out int length, out bool onMultipleLines) { // here, we can't just add token's length since there is token that span multiple lines. var text = token.ToString(); // multiple lines if (text.ContainsLineBreak()) { // get indentation from last line of the text onMultipleLines = true; length = text.GetTextColumn(_options.GetOption(FormattingOptions2.TabSize), initialColumn: 0); return; } onMultipleLines = false; // add spaces so far if (text.ContainsTab()) { // do expansive calculation var initialColumn = _treeData.GetOriginalColumn(_options.GetOption(FormattingOptions2.TabSize), token); length = text.ConvertTabToSpace(_options.GetOption(FormattingOptions2.TabSize), initialColumn, text.Length); return; } length = text.Length; }
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 override int GetOriginalColumn(int tabSize, SyntaxToken token) { if (_treeData is NodeAndText) { return(_treeData.GetOriginalColumn(tabSize, token)); } var text = _trivia.ToFullString().Substring(0, token.SpanStart - _trivia.FullSpan.Start); return(text.GetTextColumn(tabSize, _initialColumn)); }