зеркало из https://github.com/dotnet/razor.git
Create a helper method and revert change to shared code, just in case
This commit is contained in:
Родитель
4aeb51937b
Коммит
04f2ca6f3c
|
@ -322,4 +322,17 @@ internal static class SourceTextExtensions
|
|||
|
||||
return lfCount > crlfCount;
|
||||
}
|
||||
|
||||
public static ImmutableArray<TextChange> GetTextChangesArray(this SourceText newText, SourceText oldText)
|
||||
{
|
||||
var list = newText.GetTextChanges(oldText);
|
||||
|
||||
// Fast path for the common case. The base SourceText.GetTextChanges method returns an ImmutableArray
|
||||
if (list is ImmutableArray<TextChange> array)
|
||||
{
|
||||
return array;
|
||||
}
|
||||
|
||||
return list.ToImmutableArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
@ -63,9 +62,7 @@ internal sealed class CSharpFormattingPass(
|
|||
|
||||
_logger.LogTestOnly($"Generated C#:\r\n{context.CSharpSourceText}");
|
||||
|
||||
var finalChanges = changedText.GetTextChanges(originalText);
|
||||
|
||||
return finalChanges.ToImmutableArray();
|
||||
return changedText.GetTextChangesArray(originalText);
|
||||
}
|
||||
|
||||
private async Task<ImmutableArray<TextChange>> FormatCSharpAsync(FormattingContext context, CancellationToken cancellationToken)
|
||||
|
|
|
@ -177,7 +177,7 @@ internal sealed class CSharpOnTypeFormattingPass(
|
|||
}
|
||||
|
||||
// Now that we have made all the necessary changes to the document. Let's diff the original vs final version and return the diff.
|
||||
var finalChanges = cleanedText.GetTextChanges(originalText).ToImmutableArray();
|
||||
var finalChanges = cleanedText.GetTextChangesArray(originalText);
|
||||
|
||||
finalChanges = await AddUsingStatementEditsIfNecessaryAsync(context, codeDocument, csharpText, changes, originalTextWithChanges, finalChanges, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
|
|
|
@ -45,9 +45,7 @@ internal abstract class HtmlFormattingPassBase(ILogger logger) : IFormattingPass
|
|||
_logger.LogTestOnly($"After AdjustRazorIndentation:\r\n{changedText}");
|
||||
}
|
||||
|
||||
var finalChanges = changedText.GetTextChanges(originalText);
|
||||
|
||||
return finalChanges.ToImmutableArray();
|
||||
return changedText.GetTextChangesArray(originalText);
|
||||
}
|
||||
|
||||
private static ImmutableArray<TextChange> AdjustRazorIndentation(FormattingContext context)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
|
@ -43,9 +42,7 @@ internal sealed class RazorFormattingPass : IFormattingPass
|
|||
// Compute the final combined set of edits
|
||||
changedText = changedText.WithChanges(razorChanges);
|
||||
|
||||
var finalChanges = changedText.GetTextChanges(originalText);
|
||||
|
||||
return finalChanges.ToImmutableArray();
|
||||
return changedText.GetTextChangesArray(originalText);
|
||||
}
|
||||
|
||||
private static ImmutableArray<TextChange> FormatRazor(FormattingContext context, RazorSyntaxTree syntaxTree)
|
||||
|
|
|
@ -59,11 +59,6 @@ internal static class ReadOnlyListExtensions
|
|||
|
||||
public static ImmutableArray<T> ToImmutableArray<T>(this IReadOnlyList<T> list)
|
||||
{
|
||||
if (list is ImmutableArray<T> array)
|
||||
{
|
||||
return array;
|
||||
}
|
||||
|
||||
return list switch
|
||||
{
|
||||
[] => [],
|
||||
|
|
Загрузка…
Ссылка в новой задаче