Refactoring as operator to/from cast operator#48672
Refactoring as operator to/from cast operator#48672CyrusNajmabadi merged 70 commits intodotnet:masterfrom
Conversation
… wrong on right hand side of as
...eatures/CSharpTest/CodeActions/ConvertConversionOperators/ConvertConversionOperatorsTests.cs
Outdated
Show resolved
Hide resolved
...eatures/CSharpTest/CodeActions/ConvertConversionOperators/ConvertConversionOperatorsTests.cs
Outdated
Show resolved
Hide resolved
...CodeRefactorings/ConvertConversionOperators/ConvertConversionOperatorsRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...CodeRefactorings/ConvertConversionOperators/ConvertConversionOperatorsRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...CodeRefactorings/ConvertConversionOperators/ConvertConversionOperatorsRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...CodeRefactorings/ConvertConversionOperators/ConvertConversionOperatorsRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...CodeRefactorings/ConvertConversionOperators/ConvertConversionOperatorsRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...torings/ConvertConversionsOperators/AbstractConvertConversionOperatorsRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...torings/ConvertConversionsOperators/AbstractConvertConversionOperatorsRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...torings/ConvertConversionsOperators/AbstractConvertConversionOperatorsRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...torings/ConvertConversionsOperators/AbstractConvertConversionOperatorsRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
...torings/ConvertConversionsOperators/AbstractConvertConversionOperatorsRefactoringProvider.cs
Outdated
Show resolved
Hide resolved
|
Done with pass. |
Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
|
Please avoid touching anything for the moment as i refactor things :) |
MaStr11
left a comment
There was a problem hiding this comment.
Thanks for the refactoring. It's much simpler/clearer now. And thanks for taking care of the naming too!
I just found some issues in one of the test cases.
| }"; | ||
| await new VerifyCS.Test | ||
| { | ||
| TestCode = InitialMarkup, |
There was a problem hiding this comment.
If FixedCode is not set, the refactoring provider is not called at all. The setup must to look like this
| TestCode = InitialMarkup, | |
| TestCode = InitialMarkup, | |
| FixedCode = InitialMarkup, | |
| OffersEmptyRefactoring = false, |
There was a problem hiding this comment.
It's a bit sad, that this case is not covered any longer (The refactoring was behaving like a code fixer in such cases).
| await new VerifyCS.Test | ||
| { | ||
| TestCode = InitialMarkup, | ||
| CompilerDiagnostics = CompilerDiagnostics.None, // CS0077 is present, but we present the refactoring anyway (this may overlap with a diagnostic fixer) |
There was a problem hiding this comment.
Should test for ExpectedDiagnostics instead.
This was another troubling test case I stumbled upon:
- The refactoring was acting like a CodeFix: There was a diagnostic and after applying the code action it was gone
- I was not able to cover this with
ExpectedDiagnosticsbecause the verifier tried to look up the diagnostic marker in the fixed source, even though I provided differentExpectedDiagnosticsfor TestState and FixedSate.
Maybe I missed something, but I gave up quickly and used CompilerDiagnostics.None as a recourse.
| var fromNodes = await context.GetRelevantNodesAsync<TFromExpression>().ConfigureAwait(false); | ||
| var from = fromNodes.FirstOrDefault(n => n.RawKind == FromKind); | ||
| if (from == null) | ||
| return; |
There was a problem hiding this comment.
| return; | |
| { | |
| return; | |
| } |
| return; | ||
|
|
||
| if (from.GetDiagnostics().Any(d => d.DefaultSeverity == DiagnosticSeverity.Error)) | ||
| return; |
There was a problem hiding this comment.
| return; | |
| { | |
| return; | |
| } |
|
@MaStr11 Thank you for this it is proving super useful!! |
Fixes #48621
Enables toggling between cast expressions:
TODO
asconversionsCTypetoTryCastconversionsCBooland the likeGetTitledynamic