-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[WIP] Port ConvertSwitchStatementToExpression analyzer/fixer to shared layer #41815
Conversation
using Microsoft.CodeAnalysis.Options; | ||
#endif | ||
|
||
namespace Microsoft.CodeAnalysis.Diagnostics |
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.
Moving existing code into shared layer
@@ -109,92 +107,19 @@ public static async ValueTask<OptionSet> GetAnalyzerOptionSetAsync(this Analyzer | |||
return new AnalyzerConfigOptionSet(configOptions, optionSet); | |||
} | |||
|
|||
public static T GetOption<T>(this SemanticModelAnalysisContext context, Option<T> option) |
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.
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 |
@@ -515,6 +532,7 @@ Global | |||
{8A02AFAF-F622-4E3E-9E1A-8CFDACC7C7E1} = {FD0FAF5F-1DED-485C-99FA-84B97F3A8EEC} | |||
{6D407402-CC4A-4125-9B00-C70562A636A5} = {274B96B7-F815-47E3-9CA4-4024A57A478F} | |||
{706CFC25-B6E0-4DAA-BCC4-F6FAAFEEDF87} = {3FF38FD4-DF16-44B0-924F-0D5AE155495B} | |||
{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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is all this changing?
internal abstract class AbstractCodeQualityDiagnosticAnalyzer : DiagnosticAnalyzer, IBuiltInAnalyzer | ||
{ | ||
// Diagnostics in CodeStyle layer should be warnings by default. |
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 feels very hacky.
/// <remarks> | ||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have to admit this is getting very confusing.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static CodeStyleHostLanguageServices Create(HostLanguageServices hostLanguageServices) | |
private static CodeStyleHostLanguageServices Create(HostLanguageServices hostLanguageServices) |
{ | ||
get | ||
{ | ||
#if CODE_STYLE |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: