зеркало из 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;
|
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.
|
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
@ -63,9 +62,7 @@ internal sealed class CSharpFormattingPass(
|
||||||
|
|
||||||
_logger.LogTestOnly($"Generated C#:\r\n{context.CSharpSourceText}");
|
_logger.LogTestOnly($"Generated C#:\r\n{context.CSharpSourceText}");
|
||||||
|
|
||||||
var finalChanges = changedText.GetTextChanges(originalText);
|
return changedText.GetTextChangesArray(originalText);
|
||||||
|
|
||||||
return finalChanges.ToImmutableArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<ImmutableArray<TextChange>> FormatCSharpAsync(FormattingContext context, CancellationToken cancellationToken)
|
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.
|
// 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);
|
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}");
|
_logger.LogTestOnly($"After AdjustRazorIndentation:\r\n{changedText}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var finalChanges = changedText.GetTextChanges(originalText);
|
return changedText.GetTextChangesArray(originalText);
|
||||||
|
|
||||||
return finalChanges.ToImmutableArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ImmutableArray<TextChange> AdjustRazorIndentation(FormattingContext context)
|
private static ImmutableArray<TextChange> AdjustRazorIndentation(FormattingContext context)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
// 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.Collections.Immutable;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
@ -43,9 +42,7 @@ internal sealed class RazorFormattingPass : IFormattingPass
|
||||||
// Compute the final combined set of edits
|
// Compute the final combined set of edits
|
||||||
changedText = changedText.WithChanges(razorChanges);
|
changedText = changedText.WithChanges(razorChanges);
|
||||||
|
|
||||||
var finalChanges = changedText.GetTextChanges(originalText);
|
return changedText.GetTextChangesArray(originalText);
|
||||||
|
|
||||||
return finalChanges.ToImmutableArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ImmutableArray<TextChange> FormatRazor(FormattingContext context, RazorSyntaxTree syntaxTree)
|
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)
|
public static ImmutableArray<T> ToImmutableArray<T>(this IReadOnlyList<T> list)
|
||||||
{
|
{
|
||||||
if (list is ImmutableArray<T> array)
|
|
||||||
{
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
return list switch
|
return list switch
|
||||||
{
|
{
|
||||||
[] => [],
|
[] => [],
|
||||||
|
|
Загрузка…
Ссылка в новой задаче