diff --git a/src/Bicep.LangServer.UnitTests/Snippets/SnippetsProviderTests.cs b/src/Bicep.LangServer.UnitTests/Snippets/SnippetsProviderTests.cs index bc9400dba0e..cf52e9a48bd 100644 --- a/src/Bicep.LangServer.UnitTests/Snippets/SnippetsProviderTests.cs +++ b/src/Bicep.LangServer.UnitTests/Snippets/SnippetsProviderTests.cs @@ -286,10 +286,10 @@ public void GetResourceBodyCompletionSnippets_WithNoStaticTemplate_ShouldReturnS location: $3 name: $4 sku: { - name: $5 - properties: { - loadBalancerType: $6 - } + name: $5 + properties: { + loadBalancerType: $6 + } } $0 }"); diff --git a/src/Bicep.LangServer/Snippets/SnippetsProvider.cs b/src/Bicep.LangServer/Snippets/SnippetsProvider.cs index 49b303bad68..737d00c6b83 100644 --- a/src/Bicep.LangServer/Snippets/SnippetsProvider.cs +++ b/src/Bicep.LangServer/Snippets/SnippetsProvider.cs @@ -228,7 +228,7 @@ public IEnumerable GetResourceBodyCompletionSnippets(TypeSymbol typeSym foreach (KeyValuePair kvp in objectType.Properties.OrderBy(x => x.Key)) { - string? snippetText = GetSnippetText(kvp.Value, ref index); + string? snippetText = GetSnippetText(kvp.Value, indentLevel: 1, ref index); if (snippetText is not null) { @@ -251,7 +251,7 @@ public IEnumerable GetResourceBodyCompletionSnippets(TypeSymbol typeSym return null; } - private string? GetSnippetText(TypeProperty typeProperty, ref int index) + private string? GetSnippetText(TypeProperty typeProperty, int indentLevel, ref int index) { if (typeProperty.Flags.HasFlag(TypePropertyFlags.Required)) { @@ -259,22 +259,25 @@ public IEnumerable GetResourceBodyCompletionSnippets(TypeSymbol typeSym if (typeProperty.TypeReference.Type is ObjectType objectType) { - sb.AppendLine("\t" + typeProperty.Name + ": {"); + sb.AppendLine(GetIndentString(indentLevel) + typeProperty.Name + ": {"); + + indentLevel++; foreach (KeyValuePair kvp in objectType.Properties.OrderBy(x => x.Key)) { - string? snippetText = GetSnippetText(kvp.Value, ref index); + string? snippetText = GetSnippetText(kvp.Value, indentLevel, ref index); if (snippetText is not null) { sb.Append(snippetText); } } - sb.AppendLine("\t}"); + indentLevel--; + sb.AppendLine(GetIndentString(indentLevel) + "}"); } else { - sb.AppendLine("\t" + typeProperty.Name + ": $" + (index).ToString()); + sb.AppendLine(GetIndentString(indentLevel) + typeProperty.Name + ": $" + (index).ToString()); index++; } @@ -284,6 +287,11 @@ public IEnumerable GetResourceBodyCompletionSnippets(TypeSymbol typeSym return null; } + private string GetIndentString(int indentLevel) + { + return new string('\t', indentLevel); + } + private Snippet GetEmptySnippet() { string label = "{}";