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

[WIP] Port ConvertSwitchStatementToExpression analyzer/fixer to shared layer #41815

Closed
wants to merge 6 commits into from

Conversation

mavasani
Copy link
Contributor

Extracted out of #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 Port few IDE analyzers/fixers to shared layer to be enabled in CodeStyle NuGet package #41363 (comment) for details)
  3. MEF based language service discovery in CodeStyle layer. Follow up items after PR 41363 #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 b006324 just ports changes from Always try to register the EditorConfigDocumentOptionsProvider #40513 which are required to enable this support. This commit should become redundant once that PR is merged in.

using Microsoft.CodeAnalysis.Options;
#endif

namespace Microsoft.CodeAnalysis.Diagnostics
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.
@mavasani
Copy link
Contributor Author

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}
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private static CodeStyleHostLanguageServices Create(HostLanguageServices hostLanguageServices)
private static CodeStyleHostLanguageServices Create(HostLanguageServices hostLanguageServices)

{
get
{
#if CODE_STYLE
Copy link
Member

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
Copy link
Member

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);
Copy link
Member

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
Copy link
Member

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.

@mavasani
Copy link
Contributor Author

@CyrusNajmabadi Please hold off reviewing this PR for now. @sharwell is changing options infrastructure to avoid requiring any conditional preprocessor directives in shared layer.

@mavasani mavasani changed the title Port ConvertSwitchStatementToExpression analyzer/fixer to shared layer [WIP] Port ConvertSwitchStatementToExpression analyzer/fixer to shared layer Feb 23, 2020
@CyrusNajmabadi
Copy link
Member

@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! :)

@mavasani
Copy link
Contributor Author

mavasani commented Mar 4, 2020

Superceded by #42171

@mavasani mavasani closed this Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants