fix: Fixes sourcegen spacing (#766)

This commit is contained in:
Kamron Batman 2021-09-05 13:18:31 -07:00 • committed by GitHub
parent 04b5a6c609
commit 21aa6aaade
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View file

@ -225,12 +225,12 @@ namespace SerializationGenerator
if (attrTypeArg.Kind == TypedConstantKind.Primitive && attrTypeArg.Value is string attrStr) if (attrTypeArg.Kind == TypedConstantKind.Primitive && attrTypeArg.Value is string attrStr)
{ {
source.AppendLine($"{indent} {attrStr}"); source.AppendLine($"{indent}{attrStr}");
} }
else else
{ {
var attrType = (ITypeSymbol)attrTypeArg.Value; var attrType = (ITypeSymbol)attrTypeArg.Value;
source.GenerateAttribute(attrType?.Name, ctorArgs[1].Values); source.GenerateAttribute(indent, attrType?.Name, ctorArgs[1].Values);
} }
} }
@ -245,6 +245,7 @@ namespace SerializationGenerator
{ {
source.GenerateSerializableProperty( source.GenerateSerializableProperty(
compilation, compilation,
indent,
fieldSymbol, fieldSymbol,
getterAccessor, getterAccessor,
setterAccessor, setterAccessor,
@ -357,7 +358,7 @@ namespace SerializationGenerator
int index = 0; int index = 0;
foreach (var (order, _) in serializableFieldSaveFlags) foreach (var (order, _) in serializableFieldSaveFlags)
{ {
source.GenerateEnumValue($"{indent} ", true, serializableProperties[order].Name, index++); source.GenerateEnumValue($"{indent} ", true, serializableProperties[order].Name, index++);
} }
source.GenerateEnumEnd($"{indent} "); source.GenerateEnumEnd($"{indent} ");

View file

@ -24,6 +24,7 @@ namespace SerializationGenerator
public static void GenerateSerializableProperty( public static void GenerateSerializableProperty(
this StringBuilder source, this StringBuilder source,
Compilation compilation, Compilation compilation,
string indent,
IFieldSymbol fieldSymbol, IFieldSymbol fieldSymbol,
Accessibility getter, Accessibility getter,
Accessibility? setter, Accessibility? setter,
@ -43,9 +44,8 @@ namespace SerializationGenerator
) ?? false ) ?? false
); );
const string indent = " "; var propertyIndent = $"{indent} ";
const string innerIndent = " "; var innerIndent = $"{propertyIndent} ";
const string propertyIndent = " ";
var propertyAccessor = setter > getter ? setter : getter; var propertyAccessor = setter > getter ? setter : getter;
var getterAccessor = getter == propertyAccessor ? Accessibility.NotApplicable : getter; var getterAccessor = getter == propertyAccessor ? Accessibility.NotApplicable : getter;

View file

@ -21,9 +21,14 @@ namespace SerializationGenerator
{ {
public static partial class SourceGeneration public static partial class SourceGeneration
{ {
public static void GenerateAttribute(this StringBuilder source, string attrClassName, ImmutableArray<TypedConstant> args) public static void GenerateAttribute(
this StringBuilder source,
string indent,
string attrClassName,
ImmutableArray<TypedConstant> args
)
{ {
source.Append($" [{attrClassName}"); source.Append($"{indent}[{attrClassName}");
var hasArgs = args.Length > 0; var hasArgs = args.Length > 0;
if (hasArgs) if (hasArgs)