From 95ede42853822fb0a7c88380061a4b4590fa57cd Mon Sep 17 00:00:00 2001 From: Anthony Martin <38542602+anthony-c-martin@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:04:23 -0500 Subject: [PATCH] InsertResource - correctly strip read-only properties (#15689) Looks like this was inadvertently changed with #13290 (screenshot below). This PR restores the old behavior: ![image](https://github.com/user-attachments/assets/dba22f2f-45fd-454e-ab6c-9f8fbd09d092) ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/15689) --- .../InsertResourceCommandTests.cs | 4 ---- src/Bicep.LangServer/Handlers/InsertResourceHandler.cs | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Bicep.LangServer.IntegrationTests/InsertResourceCommandTests.cs b/src/Bicep.LangServer.IntegrationTests/InsertResourceCommandTests.cs index f94e3fb72c1..290bb91efd7 100644 --- a/src/Bicep.LangServer.IntegrationTests/InsertResourceCommandTests.cs +++ b/src/Bicep.LangServer.IntegrationTests/InsertResourceCommandTests.cs @@ -166,7 +166,6 @@ public async Task Insert_resource_command_should_insert_basic_resource() resource myName 'My.Rp/myTypes@2020-01-01' = { name: 'myName' properties: { - readOnlyProp: 'abc' readWriteProp: 'def' writeOnlyProp: 'ghi' int64Prop: 9223372036854775807 @@ -286,7 +285,6 @@ public async Task Insert_resource_command_should_insert_resource_group() resource myRg 'Microsoft.Resources/resourceGroups@2020-01-01' = { name: 'myRg' properties: { - readOnlyProp: 'abc' readWriteProp: 'def' writeOnlyProp: 'ghi' } @@ -359,7 +357,6 @@ public async Task Insert_resource_command_should_insert_child_resource() resource childName 'My.Rp/myTypes/childType@2020-01-01' = { name: 'myName/childName' properties: { - readOnlyProp: 'abc' readWriteProp: 'def' writeOnlyProp: 'ghi' } @@ -512,7 +509,6 @@ public async Task Insert_resource_command_should_try_to_fetch_without_apiVersion resource myName 'My.Rp/myTypes@2020-01-01' = { name: 'myName' properties: { - readOnlyProp: 'abc' readWriteProp: 'def' writeOnlyProp: 'ghi' } diff --git a/src/Bicep.LangServer/Handlers/InsertResourceHandler.cs b/src/Bicep.LangServer/Handlers/InsertResourceHandler.cs index 45b0222058e..081f73e2143 100644 --- a/src/Bicep.LangServer/Handlers/InsertResourceHandler.cs +++ b/src/Bicep.LangServer/Handlers/InsertResourceHandler.cs @@ -208,7 +208,7 @@ private static CodeReplacement GenerateCodeReplacement(BicepCompiler compiler, R model => new ReadOnlyPropertyRemovalRewriter(model)); var printerOptions = configuration.Formatting.Data; - var printed = PrettyPrinterV2.PrintValid(program, printerOptions); + var printed = PrettyPrinterV2.PrintValid(bicepFile.ProgramSyntax, printerOptions); var newline = printerOptions.NewlineKind.ToEscapeSequence(); var newlineCharacters = newline.ToCharArray();