-
Notifications
You must be signed in to change notification settings - Fork 745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a codefix for BCP035 #4570
Add a codefix for BCP035 #4570
Conversation
…ode-fix # Conflicts: # src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs
/// <summary> | ||
/// Generate a string that represents this Syntax element optionally preserving formatting. | ||
/// </summary> | ||
public static string ToTextPreserveFormatting(this SyntaxBase syntax) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In \src\Bicep.Core.IntegrationTests\ParserTests.cs, we have FilesShouldRoundTripSuccessfully()
and Oneliners_ShouldRoundTripSuccessfully()
. Can you update them to also assert that the result from ToTextPreserveFormatting()
matches what the tests get from their own print visitor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to remove the last usage of PrintVisitor and stumbled on this test code in PrintProgram_AnyProgram_ShouldRoundTrip:
printVisitor.Visit(program);
string programText = buffer.ToString();
buffer.Clear();
printVisitor.Visit(program);
string formattedProgramText = buffer.ToString();
formattedProgramText.Should().Be(programText);
Am I missing something or does it compare two equivalent outputs of printVisitor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should've been:
printVisitor.Visit(formattedProgram);
string formattedProgramText = buffer.ToString();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I won't try to fix it in this PR, but FYI it starts failing if you try to format the formattedProgram
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a good question for @shenglol who did the formatter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh good catch. That's definitely a bug. I've created #4605 to track it and will try to fix it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shengol I ended up fixing the test in this PR (https://github.com/Azure/bicep/pull/4570/files/90f961f9042ae2e8ed9b46712c9172d33d0c6cd8#diff-026bc8f7b01e7149a98805711f52ea0f2df9cc6f0664ad061d6f982358cbe5d4) to get rid of test PrintVisitor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks for fixing it. I've assigned #4605 to you and linked it.
If you start with this Bicep file (don't include the resource foo 'Microsoft.Storage/storageAccounts@2021-04-01' = {
|
} And then leave the cursor at the resource foo 'Microsoft.Storage/storageAccounts@2021-04-01' = {
kind:
location:
name:
sku:
} Would it be possible to get rid of the extra line above the |
I added some comments, but this is such a great feature! Thanks for contributing this! ❤ |
Btw, there's another case with discriminated object types. The codefix doesn't appear for a resource like this: resource bar 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
} This is a rarer case, so we don't need to block this PR on this part. The experience here would have to be different because there are |
The other thing I noticed is that the code fix only adds one level of required properties. For example with modules when I start with an empty body I get this: module mod 'passthrough.bicep' = {
name:
params:
} Then I have to specify the curly braces and click the code fix again to get the required params as well. Should we make it recursive to match the snippets? |
Found an indentation bug as well. If I start with: module mod 'passthrough.bicep' = {
name: 2
params: {}
} Then click the code fix on module mod 'passthrough.bicep' = {
name: 2
params: {
myInput:
}
} |
I've added more tests and improved indentation.
Happy to look into it but would prefer to do it in a separate PR. |
CI failure seems to be the build flakiness. |
…ode-fix # Conflicts: # src/Bicep.LangServer.IntegrationTests/CodeActionTests.cs
@@ -42,7 +42,6 @@ public static async Task<ILanguageClient> StartServerWithClientConnectionAsync(T | |||
creationOptions = creationOptions with | |||
{ | |||
SnippetsProvider = creationOptions.SnippetsProvider ?? SnippetsProvider, | |||
NamespaceProvider = creationOptions.NamespaceProvider ?? TestTypeHelper.CreateEmptyProvider(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes it so the test server uses the same set of type definitions (AzTypes) as the normal bicep invocation.
Not sure if my change caused the ModifyBicepConfigFileAndVerifyCallsToFileResolver failure. |
Nope that's a flaky test we are working on fixing. |
I think I've addressed all comments in this PR and the OSx failure is build flakiness. Please tell me if there is something else I've missed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I just requeued the build jobs and hopefully they will pass this time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM too. Thanks for adding this!
Fixes: #4563