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

Remove usages of #if CODE_STYLE where possible. #74958

Merged
merged 26 commits into from
Aug 31, 2024

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Aug 30, 2024

Trying to unify the behavior (and especially teh code) for analyzers/fixers shipped in the features layer and code-style SDK layers.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 30, 2024
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.OrganizeImports;

[DataContract]
internal readonly record struct OrganizeImportsOptions
Copy link
Member Author

Choose a reason for hiding this comment

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

options type moved to tis own file in the CodeStyle layer. The 'Providers' types move to the CodeFixes layer. This removes the need for CODE_STYLE checks, and properly layers things.

@@ -26,20 +18,11 @@ internal sealed record class CodeCleanupOptions
[DataMember] public AddImportPlacementOptions AddImportOptions { get; init; } = AddImportPlacementOptions.Default;
[DataMember] public DocumentFormattingOptions DocumentFormattingOptions { get; init; } = DocumentFormattingOptions.Default;

#if !CODE_STYLE
public static CodeCleanupOptions GetDefault(LanguageServices languageServices)
Copy link
Member Author

Choose a reason for hiding this comment

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

thios moved to the CodeFixes layer.

namespace Microsoft.CodeAnalysis.CodeGeneration;

[DataContract]
internal readonly record struct CodeAndImportGenerationOptions
Copy link
Member Author

Choose a reason for hiding this comment

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

extracted out type into its own file.

}

[DataContract]
internal readonly record struct CodeAndImportGenerationOptions
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to its own file.

@@ -38,28 +30,4 @@ private protected CodeGenerationOptions(IOptionsReader options, string language)
{
NamingStyle = options.GetOption(NamingStyleOptions.NamingPreferences, language);
}

#if !CODE_STYLE
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to codefixes layer.

[DataMember]
public required AddImportPlacementOptions AddImportOptions { get; init; }

#if !CODE_STYLE
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to codefixes layer.

#if !CODE_STYLE
public static SyntaxFormattingOptions GetDefault(Host.LanguageServices languageServices)
=> languageServices.GetRequiredService<ISyntaxFormattingService>().DefaultOptions;
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to codefixes layer

@@ -19,9 +15,4 @@ internal readonly record struct IndentationOptions(
[DataMember(Order = 2)] public FormattingOptions2.IndentStyle IndentStyle { get; init; } = DefaultIndentStyle;

public const FormattingOptions2.IndentStyle DefaultIndentStyle = FormattingOptions2.IndentStyle.Smart;

#if !CODE_STYLE
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to codefixes layer

namespace Microsoft.CodeAnalysis.OrganizeImports;

[DataContract]
internal readonly record struct OrganizeImportsOptions
Copy link
Member Author

Choose a reason for hiding this comment

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

moved this type to codestyle layer.

@@ -52,9 +52,4 @@ public bool TryGetQualifyMemberAccessOption(SymbolKind symbolKind, [NotNullWhen(

return option != null;
}

#if !CODE_STYLE
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to codefixes layer

@@ -23,31 +19,27 @@ internal readonly record struct CleanCodeGenerationOptions
[DataMember]
public required CodeCleanupOptions CleanupOptions { get; init; }

#if !CODE_STYLE
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to codefixes layer.

return _document.Project.Solution.Services.GetRequiredLanguageService<TLanguageService>(language);
#endif
}
=> _document.Project.Solution.Workspace.Services.GetExtendedLanguageServices(language).GetRequiredService<TLanguageService>();
Copy link
Member Author

Choose a reason for hiding this comment

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

the call to GetExtendedLanguageServices already defers to GetRequiredLanguageService if not in the code-style layer. so we can simplify all of this.

@CyrusNajmabadi CyrusNajmabadi changed the title in progress Remove usages of #if CODE_STYLE where possible. Aug 30, 2024
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review August 30, 2024 19:52
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner August 30, 2024 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants