Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static ImmutableArray<RazorVSInternalCodeAction> ProcessCodeActionsVSCod
continue;
}

var associatedValue = context.SourceText.GetSubTextString(diagnosticSpan);
var associatedValue = context.SourceText.ToString(diagnosticSpan);

var fqn = string.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal class ExtractToCodeBehindCodeActionResolver(
var text = await documentContext.GetSourceTextAsync(cancellationToken).ConfigureAwait(false);

var className = Path.GetFileNameWithoutExtension(path);
var codeBlockContent = text.GetSubTextString(new TextSpan(actionParams.ExtractStart, actionParams.ExtractEnd - actionParams.ExtractStart)).Trim();
var codeBlockContent = text.ToString(new TextSpan(actionParams.ExtractStart, actionParams.ExtractEnd - actionParams.ExtractStart)).Trim();
var codeBehindContent = GenerateCodeBehindClass(className, actionParams.Namespace, codeBlockContent, codeDocument);

codeBehindContent = await _roslynCodeActionHelpers.GetFormattedNewFileContentsAsync(documentContext.Project, codeBehindUri, codeBehindContent, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class ExtractToCssCodeActionResolver(

var text = await documentContext.GetSourceTextAsync(cancellationToken).ConfigureAwait(false);

var cssContent = text.GetSubTextString(new TextSpan(actionParams.ExtractStart, actionParams.ExtractEnd - actionParams.ExtractStart)).Trim();
var cssContent = text.ToString(new TextSpan(actionParams.ExtractStart, actionParams.ExtractEnd - actionParams.ExtractStart)).Trim();
var removeRange = codeDocument.Source.Text.GetRange(actionParams.RemoveStart, actionParams.RemoveEnd);

var codeDocumentIdentifier = new OptionalVersionedTextDocumentIdentifier { DocumentUri = new(documentContext.Uri) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class PromoteUsingCodeActionResolver(IFileSystem fileSystem) : IRazorCo

using var edits = new PooledArrayBuilder<SumType<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>>();

var textToInsert = sourceText.GetSubTextString(TextSpan.FromBounds(actionParams.UsingStart, actionParams.UsingEnd));
var textToInsert = sourceText.ToString(TextSpan.FromBounds(actionParams.UsingStart, actionParams.UsingEnd));
var insertLocation = new LinePosition(0, 0);
if (!_fileSystem.FileExists(importsFile))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Buffers;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.AspNetCore.Razor;
Expand Down Expand Up @@ -52,14 +51,6 @@ public static int GetPosition(this SourceText text, LinePosition position)
public static int GetPosition(this SourceText text, int line, int character)
=> text.GetPosition(new LinePosition(line, character));

public static string GetSubTextString(this SourceText text, TextSpan span)
{
using var _ = ArrayPool<char>.Shared.GetPooledArray(span.Length, out var charBuffer);

text.CopyTo(span.Start, charBuffer, 0, span.Length);
return new string(charBuffer, 0, span.Length);
}

public static bool NonWhitespaceContentEquals(this SourceText text, ImmutableArray<TextChange> changes)
{
if (changes.IsEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal static class FindAllReferencesHelper
!documentMappingService.TryMapToCSharpDocumentPosition(csharpDocument, line.End, out _, out _))
{
var start = line.GetFirstNonWhitespacePosition() ?? line.Start;
return codeDoc.Source.Text.GetSubTextString(TextSpan.FromBounds(start, line.End));
return codeDoc.Source.Text.ToString(TextSpan.FromBounds(start, line.End));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static string GetNamespaceFromDirective(UsingDirectiveSyntax usingDirectiveSynta
// as trivia to the using keyword.
var start = usingDirectiveSyntax.UsingKeyword.FullSpan.End;

return sourceText.GetSubTextString(TextSpan.FromBounds(start, end));
return sourceText.ToString(TextSpan.FromBounds(start, end));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public static int GetIndentationLevel(TextLine line, int firstNonWhitespaceChara
else
{
Debug.Assert(text[i] == ' ');
additionalIndentation = text.GetSubTextString(TextSpan.FromBounds(i, firstNonWhitespaceCharacterPosition));
additionalIndentation = text.ToString(TextSpan.FromBounds(i, firstNonWhitespaceCharacterPosition));
return tabCount;
}
}
Expand Down Expand Up @@ -222,7 +222,7 @@ public static string GetIndentationString(int indentation, bool insertSpaces, in
/// </summary>
public static void NaivelyUnindentSubstring(SourceText text, TextSpan extractionSpan, System.Text.StringBuilder builder)
{
var extractedText = text.GetSubTextString(extractionSpan);
var extractedText = text.ToString(extractionSpan);
var range = text.GetRange(extractionSpan);
if (range.Start.Line == range.End.Line)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ private void AddAdditionalLineFormattingContent(StringBuilder additionalLinesBui
{
additionalLinesBuilder.AppendLine("F<");
additionalLinesBuilder.AppendLine(GetAdditionalLineComment(originalSpan));
additionalLinesBuilder.AppendLine(_sourceText.GetSubTextString(originalSpan.ToTextSpan()));
additionalLinesBuilder.AppendLine(_sourceText.ToString(originalSpan.ToTextSpan()));
additionalLinesBuilder.AppendLine("> x;");
return;
}

additionalLinesBuilder.AppendLine(GetAdditionalLineComment(originalSpan));
additionalLinesBuilder.AppendLine(_sourceText.GetSubTextString(originalSpan.ToTextSpan()));
additionalLinesBuilder.AppendLine(_sourceText.ToString(originalSpan.ToTextSpan()));
additionalLinesBuilder.AppendLine(";");
}

Expand Down Expand Up @@ -337,7 +337,7 @@ _sourceText.Lines[nodeStartLine] is { } previousLine &&
// This is a multi-line literal, and we're emiting the 2nd line, and the literal didn't start at the start of
// the previous line, so it wouldn't have been handled by that lines formatting. We need to include it here,
// but skip it to not confuse things.
_builder.AppendLine(_sourceText.GetSubTextString(TextSpan.FromBounds(node.SpanStart, previousLine.End)));
_builder.AppendLine(_sourceText.ToString(TextSpan.FromBounds(node.SpanStart, previousLine.End)));
skipPreviousLine = true;
}

Expand Down Expand Up @@ -907,8 +907,8 @@ private LineInfo VisitCSharpCodeBlock(RazorSyntaxNode node, CSharpCodeBlockSynta

// Multi-line expressions are often not formatted by Roslyn much at all, but it will often move subsequent lines
// relative to the first, so make sure we include the users indentation so everything moves together, and is stable.
_builder.Append(_sourceText.GetSubTextString(TextSpan.FromBounds(_currentLine.Start, _currentFirstNonWhitespacePosition)));
_builder.AppendLine(_sourceText.GetSubTextString(TextSpan.FromBounds(_currentToken.Position + 1, _currentLine.End)));
_builder.Append(_sourceText.ToString(TextSpan.FromBounds(_currentLine.Start, _currentFirstNonWhitespacePosition)));
_builder.AppendLine(_sourceText.ToString(TextSpan.FromBounds(_currentToken.Position + 1, _currentLine.End)));
return CreateLineInfo(
processFormatting: true,
checkForNewLines: true,
Expand All @@ -919,7 +919,7 @@ private LineInfo VisitCSharpCodeBlock(RazorSyntaxNode node, CSharpCodeBlockSynta
public override LineInfo VisitCSharpCodeBlock(CSharpCodeBlockSyntax node)
{
// Matches things like @if, so skip the first character, but output as C# otherwise
_builder.AppendLine(_sourceText.GetSubTextString(TextSpan.FromBounds(_currentToken.Position + 1, _currentLine.End)));
_builder.AppendLine(_sourceText.ToString(TextSpan.FromBounds(_currentToken.Position + 1, _currentLine.End)));

return CreateLineInfo(
processFormatting: true,
Expand Down Expand Up @@ -1008,7 +1008,7 @@ private LineInfo VisitUsingDirective()
// For @using we just skip over the @ and format as a C# using directive
// "@using System" to "using System"
// Roslyn's parser is smart enough to not care about missing semicolons.
_builder.AppendLine(_sourceText.GetSubTextString(TextSpan.FromBounds(_currentToken.Position + 1, _currentLine.End)));
_builder.AppendLine(_sourceText.ToString(TextSpan.FromBounds(_currentToken.Position + 1, _currentLine.End)));
return CreateLineInfo(
processFormatting: true,
originOffset: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ private async Task<ImmutableArray<TextChange>> AdjustIndentationAsync(Formatting
{
var mappingSpan = new TextSpan(mapping.OriginalSpan.AbsoluteIndex, mapping.OriginalSpan.Length);
#if DEBUG
var spanText = context.SourceText.GetSubTextString(mappingSpan);
var spanText = context.SourceText.ToString(mappingSpan);
#endif

var options = new ShouldFormatOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ internal static TextChange MergeChanges(ImmutableArray<TextChange> changes, Sour
var affectedRange = changedText.GetEncompassingTextChangeRange(sourceText);
var spanBeforeChange = affectedRange.Span;
var spanAfterChange = new TextSpan(spanBeforeChange.Start, affectedRange.NewLength);
var newText = changedText.GetSubTextString(spanAfterChange);
var newText = changedText.ToString(spanAfterChange);

return new TextChange(spanBeforeChange, newText);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,8 @@ private async Task TestAsync(string contents)

if (resultSpan.Start != actionParams.Start || resultSpan.End != actionParams.End)
{
var resultText = context.SourceText.GetSubTextString(resultSpan);
var actualText = context.SourceText.GetSubTextString(TextSpan.FromBounds(actionParams.Start, actionParams.End));
var resultText = context.SourceText.ToString(resultSpan);
var actualText = context.SourceText.ToString(TextSpan.FromBounds(actionParams.Start, actionParams.End));
AssertEx.EqualOrDiff(resultText, actualText, "Code action span does not match expected");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void ConvertSpanToRange_ReturnsConvertedRange()
var range = RazorDiagnosticHelper.ConvertSpanToRange(sourceSpan, sourceText);

// Assert
Assert.Equal("lo W", sourceText.GetSubTextString(sourceText.GetTextSpan(range)));
Assert.Equal("lo W", sourceText.ToString(sourceText.GetTextSpan(range)));
Assert.Equal(expectedRange, range);
}

Expand All @@ -86,7 +86,7 @@ public void ConvertSpanToRange_StartsOutsideOfDocument_EmptyDocument_NormalizesT
var range = RazorDiagnosticHelper.ConvertSpanToRange(sourceSpan, sourceText);

// Assert
Assert.Equal("", sourceText.GetSubTextString(sourceText.GetTextSpan(range)));
Assert.Equal("", sourceText.ToString(sourceText.GetTextSpan(range)));
Assert.Equal(expectedRange, range);
}

Expand All @@ -102,7 +102,7 @@ public void ConvertSpanToRange_StartsOutsideOfDocument_NormalizesToEnd()
var range = RazorDiagnosticHelper.ConvertSpanToRange(sourceSpan, sourceText);

// Assert
Assert.Equal("", sourceText.GetSubTextString(sourceText.GetTextSpan(range)));
Assert.Equal("", sourceText.ToString(sourceText.GetTextSpan(range)));
Assert.Equal(expectedRange, range);
}

Expand All @@ -118,7 +118,7 @@ public void ConvertSpanToRange_EndsOutsideOfDocument_NormalizesToEnd()
var range = RazorDiagnosticHelper.ConvertSpanToRange(sourceSpan, sourceText);

// Assert
Assert.Equal("World", sourceText.GetSubTextString(sourceText.GetTextSpan(range)));
Assert.Equal("World", sourceText.ToString(sourceText.GetTextSpan(range)));
Assert.Equal(expectedRange, range);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ private static string GetFileRepresentationOfTokens(SourceText sourceText, int[]
builder.Append(length).Append(' ');
builder.Append(typeString).Append(' ');
builder.Append(data[i + 4]).Append(' ');
builder.Append('[').Append(sourceText.GetSubTextString(new TextSpan(sourceText.Lines[lineIndex].Start + lineOffset, length))).Append(']');
builder.Append('[').Append(sourceText.ToString(new TextSpan(sourceText.Lines[lineIndex].Start + lineOffset, length))).Append(']');
builder.AppendLine();

prevLength = length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ private async Task VerifyProximityExpressionsAsync(TestCode input, string[] extr

Assert.NotNull(result);

var expected = input.Spans.Select(inputText.GetSubTextString).Concat(extraExpressions).OrderAsArray();
var expected = input.Spans.Select(inputText.ToString).Concat(extraExpressions).OrderAsArray();
AssertEx.SequenceEqual(expected, result.OrderAsArray());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private static string GetTestOutput(SourceText sourceText, int[]? data, ISemanti

var type = tokenTypes[data[i + 3]];
var modifier = GetTokenModifierString(data[i + 4], legend);
var text = sourceText.GetSubTextString(new TextSpan(sourceText.Lines[lineIndex].Start + lineOffset, length));
var text = sourceText.ToString(new TextSpan(sourceText.Lines[lineIndex].Start + lineOffset, length));
builder.AppendLine($"{lineDelta} {charDelta} {length} {type} {modifier} [{text}]");

prevLength = length;
Expand Down