Improved formatting for implicitly captured local functions

このコミットが含まれているのは:
Sergio Pedri committed 2019-09-05 18:21:47 +02:00
1 親 c706e64940
コミット 9956ad3483
2ファイル変更
+29 -1

検索条件に一致するファイルはありません

+28
ファイルの表示
@@ -0,0 +1,28 @@
using System;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text.RegularExpressions;
namespace ComputeSharp.Shaders.Extensions
{
/// <summary>
/// A <see langword="class"/> that provides extension methods for the <see langword="string"/> type
/// </summary>
internal static class StringExtensions
{
/// <summary>
/// Removes the left padding for an input multiline <see langword="string"/>
/// </summary>
/// <param name="text">The input <see langword="string"/> to process</param>
/// <returns>A left-aligned <see langword="string"/> with the same text as the input</returns>
[Pure]
public static string RemoveLeftPadding(this string text)
{
string[] lines = text.Split(Environment.NewLine);
int spaces = text.TakeWhile(c => c == ' ').Count();
Regex regex = new Regex($"^{new string(Enumerable.Repeat(' ', spaces).ToArray())}");
return lines.Aggregate(string.Empty, (result, line) => $"{result}{Environment.NewLine}{regex.Replace(line, string.Empty)}");
}
}
}
+1 -1
ファイルの表示
@@ -305,7 +305,7 @@ namespace ComputeSharp.Shaders.Translation
// Extract the implicit local functions
var locals = root.DescendantNodes().OfType<LocalFunctionStatementSyntax>().ToArray();
root = root.RemoveNodes(locals, SyntaxRemoveOptions.KeepNoTrivia);
_LocalFunctionsList.AddRange(locals.Select(local => new LocalFunctionInfo(local.ToString())));
_LocalFunctionsList.AddRange(locals.Select(local => new LocalFunctionInfo(local.ToFullString().RemoveLeftPadding().Trim(' ', '\r', '\n'))));
// Register the captured static members
foreach (var member in syntaxRewriter.StaticMembers)