Skip to content

Commit eb881c0

Browse files
Switch IDE to using modern extensions
1 parent 2d01ce7 commit eb881c0

File tree

518 files changed

+31282
-28022
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

518 files changed

+31282
-28022
lines changed

src/Analyzers/CSharp/Analyzers/CodeStyle/CSharpAnalyzerOptionsProvider.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,45 @@ public static implicit operator AnalyzerOptionsProvider(CSharpAnalyzerOptionsPro
9595

9696
internal static class CSharpAnalyzerOptionsProviders
9797
{
98-
public static CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions(this AnalyzerOptions options, SyntaxTree syntaxTree)
98+
extension(AnalyzerOptions options)
99+
{
100+
public CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions(SyntaxTree syntaxTree)
99101
=> new(options.AnalyzerConfigOptionsProvider.GetOptions(syntaxTree).GetOptionsReader());
102+
}
100103

101-
public static CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions(this SemanticModelAnalysisContext context)
104+
extension(SemanticModelAnalysisContext context)
105+
{
106+
public CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions()
102107
=> GetCSharpAnalyzerOptions(context.Options, context.SemanticModel.SyntaxTree);
108+
}
103109

104-
public static CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions(this SyntaxNodeAnalysisContext context)
110+
extension(SyntaxNodeAnalysisContext context)
111+
{
112+
public CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions()
105113
=> GetCSharpAnalyzerOptions(context.Options, context.Node.SyntaxTree);
114+
}
106115

107-
public static CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions(this SyntaxTreeAnalysisContext context)
116+
extension(SyntaxTreeAnalysisContext context)
117+
{
118+
public CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions()
108119
=> GetCSharpAnalyzerOptions(context.Options, context.Tree);
120+
}
109121

110-
public static CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions(this CodeBlockAnalysisContext context)
122+
extension(CodeBlockAnalysisContext context)
123+
{
124+
public CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions()
111125
=> GetCSharpAnalyzerOptions(context.Options, context.SemanticModel.SyntaxTree);
126+
}
112127

113-
public static CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions(this OperationAnalysisContext context)
128+
extension(OperationAnalysisContext context)
129+
{
130+
public CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions()
114131
=> GetCSharpAnalyzerOptions(context.Options, context.Operation.Syntax.SyntaxTree);
132+
}
115133

116-
public static CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions(this SymbolStartAnalysisContext context, SyntaxTree syntaxTree)
134+
extension(SymbolStartAnalysisContext context)
135+
{
136+
public CSharpAnalyzerOptionsProvider GetCSharpAnalyzerOptions(SyntaxTree syntaxTree)
117137
=> GetCSharpAnalyzerOptions(context.Options, syntaxTree);
138+
}
118139
}

src/Analyzers/CSharp/Tests/UseVarTestExtensions.cs

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,83 +22,86 @@ internal static class UseVarTestExtensions
2222
private static readonly CodeStyleOption2<bool> offWithError = new(false, NotificationOption2.Error);
2323
private static readonly CodeStyleOption2<bool> onWithError = new(true, NotificationOption2.Error);
2424

25-
public static OptionsCollection PreferExplicitTypeWithError(this AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
25+
extension(AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
26+
{
27+
public OptionsCollection PreferExplicitTypeWithError()
2628
=> new(test.GetLanguage())
2729
{
2830
{ CSharpCodeStyleOptions.VarElsewhere, offWithError },
2931
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithError },
3032
{ CSharpCodeStyleOptions.VarForBuiltInTypes, offWithError },
3133
};
3234

33-
public static OptionsCollection PreferImplicitTypeWithError(this AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
34-
=> new(test.GetLanguage())
35-
{
35+
public OptionsCollection PreferImplicitTypeWithError()
36+
=> new(test.GetLanguage())
37+
{
3638
{ CSharpCodeStyleOptions.VarElsewhere, onWithError },
3739
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithError },
3840
{ CSharpCodeStyleOptions.VarForBuiltInTypes, onWithError },
39-
};
41+
};
4042

41-
public static OptionsCollection PreferExplicitTypeWithWarning(this AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
42-
=> new(test.GetLanguage())
43-
{
43+
public OptionsCollection PreferExplicitTypeWithWarning()
44+
=> new(test.GetLanguage())
45+
{
4446
{ CSharpCodeStyleOptions.VarElsewhere, offWithWarning },
4547
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithWarning },
4648
{ CSharpCodeStyleOptions.VarForBuiltInTypes, offWithWarning },
47-
};
49+
};
4850

49-
public static OptionsCollection PreferImplicitTypeWithWarning(this AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
50-
=> new(test.GetLanguage())
51-
{
51+
public OptionsCollection PreferImplicitTypeWithWarning()
52+
=> new(test.GetLanguage())
53+
{
5254
{ CSharpCodeStyleOptions.VarElsewhere, onWithWarning },
5355
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithWarning },
5456
{ CSharpCodeStyleOptions.VarForBuiltInTypes, onWithWarning },
55-
};
57+
};
5658

57-
public static OptionsCollection PreferExplicitTypeWithInfo(this AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
58-
=> new(test.GetLanguage())
59-
{
59+
public OptionsCollection PreferExplicitTypeWithInfo()
60+
=> new(test.GetLanguage())
61+
{
6062
{ CSharpCodeStyleOptions.VarElsewhere, offWithInfo },
6163
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithInfo },
6264
{ CSharpCodeStyleOptions.VarForBuiltInTypes, offWithInfo },
63-
};
65+
};
6466

65-
public static OptionsCollection PreferImplicitTypeWithInfo(this AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
66-
=> new(test.GetLanguage())
67-
{
67+
public OptionsCollection PreferImplicitTypeWithInfo()
68+
=> new(test.GetLanguage())
69+
{
6870
{ CSharpCodeStyleOptions.VarElsewhere, onWithInfo },
6971
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithInfo },
7072
{ CSharpCodeStyleOptions.VarForBuiltInTypes, onWithInfo },
71-
};
73+
};
7274

73-
public static OptionsCollection PreferExplicitTypeWithSilent(this AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
74-
=> new(test.GetLanguage())
75-
{
75+
public OptionsCollection PreferExplicitTypeWithSilent()
76+
=> new(test.GetLanguage())
77+
{
7678
{ CSharpCodeStyleOptions.VarElsewhere, offWithSilent },
7779
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithSilent },
7880
{ CSharpCodeStyleOptions.VarForBuiltInTypes, offWithSilent },
79-
};
81+
};
8082

81-
public static OptionsCollection PreferImplicitTypeWithSilent(this AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
82-
=> new(test.GetLanguage())
83-
{
83+
public OptionsCollection PreferImplicitTypeWithSilent()
84+
=> new(test.GetLanguage())
85+
{
8486
{ CSharpCodeStyleOptions.VarElsewhere, onWithSilent },
8587
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithSilent },
8688
{ CSharpCodeStyleOptions.VarForBuiltInTypes, onWithSilent },
87-
};
89+
};
8890

89-
public static OptionsCollection PreferExplicitTypeWithNone(this AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
90-
=> new(test.GetLanguage())
91-
{
91+
public OptionsCollection PreferExplicitTypeWithNone()
92+
=> new(test.GetLanguage())
93+
{
9294
{ CSharpCodeStyleOptions.VarElsewhere, offWithNone },
9395
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, offWithNone },
9496
{ CSharpCodeStyleOptions.VarForBuiltInTypes, offWithNone },
95-
};
97+
};
9698

97-
public static OptionsCollection PreferImplicitTypeWithNone(this AbstractCodeActionOrUserDiagnosticTest_NoEditor<TestHostDocument, TestHostProject, TestHostSolution, TestWorkspace> test)
98-
=> new(test.GetLanguage())
99-
{
99+
public OptionsCollection PreferImplicitTypeWithNone()
100+
=> new(test.GetLanguage())
101+
{
100102
{ CSharpCodeStyleOptions.VarElsewhere, onWithNone },
101103
{ CSharpCodeStyleOptions.VarWhenTypeIsApparent, onWithNone },
102104
{ CSharpCodeStyleOptions.VarForBuiltInTypes, onWithNone },
103-
};
105+
};
106+
}
104107
}

src/Analyzers/Core/Analyzers/AnalyzerOptionsProvider.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,39 @@ internal IOptionsReader GetAnalyzerConfigOptions()
8383

8484
internal static partial class AnalyzerOptionsProviders
8585
{
86-
public static AnalyzerOptionsProvider GetAnalyzerOptions(this AnalyzerOptions analyzerOptions, SyntaxTree syntaxTree)
86+
extension(AnalyzerOptions analyzerOptions)
87+
{
88+
public AnalyzerOptionsProvider GetAnalyzerOptions(SyntaxTree syntaxTree)
8789
=> new(analyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(syntaxTree).GetOptionsReader(), syntaxTree.Options.Language);
90+
}
8891

89-
public static AnalyzerOptionsProvider GetAnalyzerOptions(this SemanticModelAnalysisContext context)
92+
extension(SemanticModelAnalysisContext context)
93+
{
94+
public AnalyzerOptionsProvider GetAnalyzerOptions()
9095
=> GetAnalyzerOptions(context.Options, context.SemanticModel.SyntaxTree);
96+
}
9197

92-
public static AnalyzerOptionsProvider GetAnalyzerOptions(this SyntaxNodeAnalysisContext context)
98+
extension(SyntaxNodeAnalysisContext context)
99+
{
100+
public AnalyzerOptionsProvider GetAnalyzerOptions()
93101
=> GetAnalyzerOptions(context.Options, context.Node.SyntaxTree);
102+
}
94103

95-
public static AnalyzerOptionsProvider GetAnalyzerOptions(this SyntaxTreeAnalysisContext context)
104+
extension(SyntaxTreeAnalysisContext context)
105+
{
106+
public AnalyzerOptionsProvider GetAnalyzerOptions()
96107
=> GetAnalyzerOptions(context.Options, context.Tree);
108+
}
97109

98-
public static AnalyzerOptionsProvider GetAnalyzerOptions(this OperationAnalysisContext context)
110+
extension(OperationAnalysisContext context)
111+
{
112+
public AnalyzerOptionsProvider GetAnalyzerOptions()
99113
=> GetAnalyzerOptions(context.Options, context.Operation.Syntax.SyntaxTree);
114+
}
100115

101-
public static AnalyzerOptionsProvider GetAnalyzerOptions(this CodeBlockAnalysisContext context)
116+
extension(CodeBlockAnalysisContext context)
117+
{
118+
public AnalyzerOptionsProvider GetAnalyzerOptions()
102119
=> GetAnalyzerOptions(context.Options, context.CodeBlock.SyntaxTree);
120+
}
103121
}

src/Analyzers/Core/Analyzers/EnforceOnBuild.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ internal enum EnforceOnBuild
3636

3737
internal static class EnforceOnBuildExtensions
3838
{
39-
public static string ToCustomTag(this EnforceOnBuild enforceOnBuild)
39+
extension(EnforceOnBuild enforceOnBuild)
40+
{
41+
public string ToCustomTag()
4042
=> $"{nameof(EnforceOnBuild)}_{enforceOnBuild}";
43+
}
4144
}

src/Analyzers/Core/CodeFixes/AnalyzerOptionsProviders.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ namespace Microsoft.CodeAnalysis.Diagnostics;
1111

1212
internal static partial class AnalyzerOptionsProviders
1313
{
14-
public static async ValueTask<AnalyzerOptionsProvider> GetAnalyzerOptionsProviderAsync(this Document document, CancellationToken cancellationToken)
14+
extension(Document document)
1515
{
16-
var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
17-
var analyzerOptions = document.Project.AnalyzerOptions;
18-
var configOptions = analyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(syntaxTree).GetOptionsReader();
16+
public async ValueTask<AnalyzerOptionsProvider> GetAnalyzerOptionsProviderAsync(CancellationToken cancellationToken)
17+
{
18+
var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
19+
var analyzerOptions = document.Project.AnalyzerOptions;
20+
var configOptions = analyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(syntaxTree).GetOptionsReader();
1921

20-
return new AnalyzerOptionsProvider(configOptions, document.Project.Language);
22+
return new AnalyzerOptionsProvider(configOptions, document.Project.Language);
23+
}
2124
}
2225
}

src/Analyzers/Core/CodeFixes/ImplementType/ImplementTypeOptions.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,22 @@ internal static class ImplementTypeOptionsStorage
6767

6868
internal static class ImplementTypeOptionsProviders
6969
{
70-
public static ImplementTypeOptions GetImplementTypeOptions(this IOptionsReader reader, string language)
70+
extension(IOptionsReader reader)
71+
{
72+
public ImplementTypeOptions GetImplementTypeOptions(string language)
7173
=> new()
7274
{
7375
InsertionBehavior = reader.GetOption(ImplementTypeOptionsStorage.InsertionBehavior, language),
7476
PropertyGenerationBehavior = reader.GetOption(ImplementTypeOptionsStorage.PropertyGenerationBehavior, language)
7577
};
78+
}
7679

77-
public static async ValueTask<ImplementTypeOptions> GetImplementTypeOptionsAsync(this Document document, CancellationToken cancellationToken)
80+
extension(Document document)
7881
{
79-
var configOptions = await document.GetHostAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false);
80-
return configOptions.GetImplementTypeOptions(document.Project.Language);
82+
public async ValueTask<ImplementTypeOptions> GetImplementTypeOptionsAsync(CancellationToken cancellationToken)
83+
{
84+
var configOptions = await document.GetHostAnalyzerConfigOptionsAsync(cancellationToken).ConfigureAwait(false);
85+
return configOptions.GetImplementTypeOptions(document.Project.Language);
86+
}
8187
}
8288
}

src/Analyzers/Core/CodeFixes/Naming/NamingExtensions.cs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,31 @@ namespace Microsoft.CodeAnalysis.Shared.Extensions;
1313

1414
internal static class NamingExtensions
1515
{
16-
public static async Task<NamingRule> GetApplicableNamingRuleAsync(
17-
this Document document, SymbolKind symbolKind, Accessibility accessibility, CancellationToken cancellationToken)
16+
extension(Document document)
1817
{
19-
var rules = await document.GetNamingRulesAsync(cancellationToken).ConfigureAwait(false);
20-
foreach (var rule in rules)
18+
public async Task<NamingRule> GetApplicableNamingRuleAsync(
19+
SymbolKind symbolKind, Accessibility accessibility, CancellationToken cancellationToken)
2120
{
22-
if (rule.SymbolSpecification.AppliesTo(symbolKind, accessibility))
23-
return rule;
24-
}
21+
var rules = await document.GetNamingRulesAsync(cancellationToken).ConfigureAwait(false);
22+
foreach (var rule in rules)
23+
{
24+
if (rule.SymbolSpecification.AppliesTo(symbolKind, accessibility))
25+
return rule;
26+
}
2527

26-
throw ExceptionUtilities.Unreachable();
27-
}
28+
throw ExceptionUtilities.Unreachable();
29+
}
2830

29-
/// <summary>
30-
/// Gets the set of naming rules the user has set for this document. Will include a set of default naming rules
31-
/// that match if the user hasn't specified any for a particular symbol type. The are added at the end so they
32-
/// will only be used if the user hasn't specified a preference.
33-
/// </summary>
34-
public static async Task<ImmutableArray<NamingRule>> GetNamingRulesAsync(
35-
this Document document, CancellationToken cancellationToken)
36-
{
37-
var options = await document.GetNamingStylePreferencesAsync(cancellationToken).ConfigureAwait(false);
38-
return options.Rules.NamingRules.AddRange(FallbackNamingRules.Default);
31+
/// <summary>
32+
/// Gets the set of naming rules the user has set for this document. Will include a set of default naming rules
33+
/// that match if the user hasn't specified any for a particular symbol type. The are added at the end so they
34+
/// will only be used if the user hasn't specified a preference.
35+
/// </summary>
36+
public async Task<ImmutableArray<NamingRule>> GetNamingRulesAsync(
37+
CancellationToken cancellationToken)
38+
{
39+
var options = await document.GetNamingStylePreferencesAsync(cancellationToken).ConfigureAwait(false);
40+
return options.Rules.NamingRules.AddRange(FallbackNamingRules.Default);
41+
}
3942
}
4043
}

0 commit comments

Comments
 (0)