Skip to content
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

Refactor: Use single Diagnostic class to represent all core diagnostics #14875

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

anthony-c-martin
Copy link
Member

@anthony-c-martin anthony-c-martin commented Aug 22, 2024

The split class structure between ErrorDiagnostic & Diagnostic is something I've been meaning to remove since the very early days of Bicep. I've decided to do it now, because it'll simplify the refactor needed for #14842.

The majority of the changes in this PR were made using refactoring tools, not manually. The main changes I made were:

  • Removed ErrorDiagnostic, ErrorBuilderDelegate, FixableErrorDiagnostic
  • Converted diag is ErrorDiagnostic type checks to use diag.Level == DiagnosticLevel.Error instead
  • Renamed ResultWithDiagnostic to ResultWithDiagnosticBuilder instead to more accurately represent its purpose
  • Created ResultWithDiagnotic<T>, and replaced usage of Result<T, Diagnostic> with it
  • Other changes were mostly downstream changes of the above
Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor

github-actions bot commented Aug 22, 2024

Test this change out locally with the following install scripts (Action run 10532680475)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 10532680475
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 10532680475"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 10532680475
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 10532680475"

Copy link
Contributor

github-actions bot commented Aug 22, 2024

Dotnet Test Results

   12 files   -     96     12 suites   - 96   2m 37s ⏱️ - 31m 2s
3 021 tests  -  8 046  3 021 ✅  -  8 046  0 💤 ±0  0 ❌ ±0 
3 023 runs   - 35 778  3 023 ✅  - 35 778  0 💤 ±0  0 ❌ ±0 

Results for commit 49bbaa7. ± Comparison against base commit 9bbe7ae.

♻️ This comment has been updated with latest results.

@anthony-c-martin anthony-c-martin changed the title Refactor: Remove ErrorDiagnostic class Refactor: Use single Diagnostic class to represent all core diagnostics Aug 23, 2024

namespace Bicep.Core.Diagnostics;

public class ResultWithDiagnosticBuilder<TSuccess> : Result<TSuccess, DiagnosticBuilder.DiagnosticBuilderDelegate>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the new name, this was confusing.

@@ -228,8 +228,8 @@ private DeclaredTypeAssignment GetParameterType(ParameterDeclarationSyntax synta
if (!binder.FileSymbol.TryGetBicepFileSemanticModelViaUsing().IsSuccess(out var semanticModel, out var failureDiagnostic))
{
// failed to resolve using
return failureDiagnostic is ErrorDiagnostic error
? ErrorType.Create(error)
return failureDiagnostic.Level == DiagnosticLevel.Error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth it to have an IsErrorDiagnostic() or IsErrorLevel() extension for IDiagnostic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion! I have a follow-up PR - will address this there.

@anthony-c-martin anthony-c-martin merged commit e8ae96b into main Aug 23, 2024
47 checks passed
@anthony-c-martin anthony-c-martin deleted the ant/diags branch August 23, 2024 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants