[WIP] Port ConvertSwitchStatementToExpression analyzer/fixer to shared layer#41815
[WIP] Port ConvertSwitchStatementToExpression analyzer/fixer to shared layer#41815mavasani wants to merge 6 commits intodotnet:masterfrom
Conversation
There was a problem hiding this comment.
Moving existing code into shared layer
There was a problem hiding this comment.
Code moved to partial declaration which was moved to shared layer.
Extracted out of dotnet#41363 so it only contains the following changes: 1. Port analyzer/fixer/test files for ConvertSwitchStatementToExpression to shared layer 2. Options related namespace changes (see comment dotnet#41363 (comment) for details) 3. MEF based language service discovery in CodeStyle layer. dotnet#41462 tracks replacing this with a non-MEF based approach. 4. Minimal resx/xlf file changes - few were needed as the resources used by analyzer/fixer were moved to shared resx file. 5. Enable .editorconfig based unit test support for CodeStyle layer. NOTE: First commit dotnet@b006324 just ports changes from dotnet#40513 which are required to enable this support. This commit should become redundant once that PR is merged in.
e20527f to
d545499
Compare
|
Unit test failures are due to #41823 |
| {E7BC93F8-51F0-45A8-872D-86C387243D38} = {B20208C3-D3A6-4020-A274-6BE3786D29FB} | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {6F599E08-A9EA-4FAA-897F-5D824B0210E6} |
There was a problem hiding this comment.
why is all this changing?
| // Consider moving all the CodeQuality diagnostic analyzers into analyzer repo as CA rules. | ||
| internal abstract class AbstractCodeQualityDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer | ||
| { | ||
| // Diagnostics in CodeStyle layer should be warnings by default. |
There was a problem hiding this comment.
this feels very hacky.
| /// This utility class is only to be used by the formatting analyzer and formatting code fixer in Code Style layer. | ||
| /// Other components should use the public "Formatter" type defined in "Microsoft.CodeAnalysis.Formatting" namespace. | ||
| /// </remarks> | ||
| internal static class Formatter |
There was a problem hiding this comment.
i have to admit this is getting very confusing.
There was a problem hiding this comment.
i also don't like all the duplication in the code below... is this all realy necessary?
|
|
||
| public static CodeStyleHostLanguageServices? GetMappedCodeStyleLanguageServices(HostLanguageServices? hostLanguageServices) | ||
| => hostLanguageServices != null ? s_mappedLanguageServices.GetOrAdd(hostLanguageServices, Create) : null; | ||
| public static CodeStyleHostLanguageServices GetRequiredMappedCodeStyleLanguageServices(HostLanguageServices hostLanguageServices) |
There was a problem hiding this comment.
| public static CodeStyleHostLanguageServices GetRequiredMappedCodeStyleLanguageServices(HostLanguageServices hostLanguageServices) | |
| public static CodeStyleHostLanguageServices GetRequiredMappedCodeStyleLanguageServices(HostLanguageServices hostLanguageServices) |
| => hostLanguageServices != null ? s_mappedLanguageServices.GetOrAdd(hostLanguageServices, Create) : null; | ||
| public static CodeStyleHostLanguageServices GetRequiredMappedCodeStyleLanguageServices(HostLanguageServices hostLanguageServices) | ||
| => s_mappedLanguageServices.GetOrAdd(hostLanguageServices, Create); | ||
| private static CodeStyleHostLanguageServices Create(HostLanguageServices hostLanguageServices) |
There was a problem hiding this comment.
| private static CodeStyleHostLanguageServices Create(HostLanguageServices hostLanguageServices) | |
| private static CodeStyleHostLanguageServices Create(HostLanguageServices hostLanguageServices) |
| { | ||
| get | ||
| { | ||
| #if CODE_STYLE |
There was a problem hiding this comment.
i really don't like how infectious this seems to be. it feels like we're becoming a c++ codebase with ifdefs everywhere to support conditional compilation.
| return solution; | ||
| } | ||
|
|
||
| #if CODE_STYLE |
There was a problem hiding this comment.
like... this literally feels like entirely separate approaches here. having us use ifdefs instead of other mechanisms (i.e. interfaces/DI/etc.) just feels really hacky and hard to maintain.
| return; | ||
| } | ||
|
|
||
| _optionService.RegisterDocumentOptionsProvider(documentOptionsProvider); |
There was a problem hiding this comment.
what's going on in this file?
| #if CODE_STYLE | ||
| using Microsoft.CodeAnalysis.Internal.Options; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.CSharp.Internal.CodeStyle |
There was a problem hiding this comment.
this is super confusing to read and understand. i also just am hating the ifdef shenanigans.
|
@CyrusNajmabadi Please hold off reviewing this PR for now. @sharwell is changing options infrastructure to avoid requiring any conditional preprocessor directives in shared layer. |
Hooray! :) |
|
Superceded by #42171 |
Extracted out of #41363 so it only contains the following changes: