diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslSourceProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslSourceProperty.Syntax.cs index 21ff370c..70c3c9e8 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslSourceProperty.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateHlslSourceProperty.Syntax.cs @@ -23,7 +23,8 @@ partial class ID2D1ShaderGenerator /// The resulting instance for the HlslSource property. public static PropertyDeclarationSyntax GetSyntax(string hlslSource, int hierarchyDepth) { - SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth); + // The indentation level is the current depth + 1 (for the property) + SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth + 1); // This code produces a property declaration as follows: // diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxTokenHelper.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxTokenHelper.cs index f537568f..8210504c 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxTokenHelper.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Helpers/SyntaxTokenHelper.cs @@ -17,13 +17,11 @@ internal static class SyntaxTokenHelper /// A representing a raw multiline string literal with the value of . public static SyntaxToken CreateRawMultilineStringLiteral(string text, int indentationLevel) { - // Create a token to represent the raw multiline string literal expression. Here some spaces are - // also added to properly align the resulting text with one indentation below the declaring string constant. - // The spaces are: 4 for each containing type, 4 for the containing method, and 4 for the one additional indentation. - // An extra newline and indentation has to be added to the raw text when there is no trailing newline, as not doing - // so would otherwise case the terminating """ token to fall on the same line, which is invalid syntax. This is only - // needed to make the code valid, as the actual literal context of the string is not affected and remains the same. - string indentation = new(' ', (4 * indentationLevel) + 4 + 4); + // Create a token to represent the raw multiline string literal expression. An extra newline and indentation + // has to be added to the raw text when there is no trailing newline, as not doing so would otherwise case + // the terminating """ token to fall on the same line, which is invalid syntax. This is only needed to make + // the code valid, as the actual literal context of the string is not affected and remains the same. + string indentation = new(' ', 4 * indentationLevel); return Token( TriviaList(), diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs index c0484d51..3b693127 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.Syntax.cs @@ -119,7 +119,8 @@ partial class IShaderGenerator sizeHint += textBuilder.Length; - SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth); + // The indentation level is the current depth + 2 (the method, and the return expression) + SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth + 2); statements.Add( ExpressionStatement(