From 3ead6de9479d6e457631720ceac962d266940c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Sun, 15 Apr 2018 17:10:33 +0200 Subject: [PATCH 01/23] SymbolKindOrTypeKind -> SymbolOrTypeOrMethodKind --- ...oPropertyToFullPropertyTests_OptionSets.cs | 4 +- .../EditorConfigNamingStyleParserTests.cs | 30 +++--- .../NamingStylesTestOptionSets.cs | 20 ++-- .../DeclarationNameCompletionProvider.cs | 2 +- ...ionNameCompletionProvider_BuiltInStyles.cs | 8 +- ...tyToFullPropertyCodeRefactoringProvider.cs | 4 +- ...erCodeRefactoringProviderMemberCreation.cs | 6 +- .../SymbolSpecificationViewModel.cs | 6 +- ...ditorConfigNamingStyleParser_SymbolSpec.cs | 34 +++--- .../Serialization/SymbolSpecification.cs | 100 +++++++++++------- 10 files changed, 116 insertions(+), 98 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests_OptionSets.cs b/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests_OptionSets.cs index 92100628c0385..5eec55060001b 100644 --- a/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests_OptionSets.cs +++ b/src/EditorFeatures/CSharpTest/ConvertAutoPropertyToFullProperty/ConvertAutoPropertyToFullPropertyTests_OptionSets.cs @@ -56,7 +56,7 @@ private NamingStylePreferences CreateCustomFieldNamingStylePreference() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Field)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -88,7 +88,7 @@ private NamingStylePreferences CreateCustomStaticFieldNamingStylePreference() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Field)), + ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Field)), ImmutableArray.Empty, ImmutableArray.Create(new ModifierKind(DeclarationModifiers.Static))); diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs index 02cb26990f1d0..231b60fb26889 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs @@ -37,8 +37,8 @@ public static void TestPascalCaseRule() Assert.Equal("method_and_property_symbols", symbolSpec.Name); var expectedApplicableSymbolKindList = new[] { - new SymbolKindOrTypeKind(SymbolKind.Method), - new SymbolKindOrTypeKind(SymbolKind.Property) + new SymbolOrTypeOrMethodKind(SymbolKind.Method), + new SymbolOrTypeOrMethodKind(SymbolKind.Property) }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); Assert.Empty(symbolSpec.RequiredModifierList); @@ -83,7 +83,7 @@ public static void TestAsyncMethodsRule() Assert.Equal(DiagnosticSeverity.Error, namingRule.EnforcementLevel); Assert.Equal("method_symbols", symbolSpec.Name); Assert.Single(symbolSpec.ApplicableSymbolKindList); - Assert.Contains(new SymbolKindOrTypeKind(SymbolKind.Method), symbolSpec.ApplicableSymbolKindList); + Assert.Contains(new SymbolOrTypeOrMethodKind(SymbolKind.Method), symbolSpec.ApplicableSymbolKindList); Assert.Single(symbolSpec.RequiredModifierList); Assert.Contains(new ModifierKind(ModifierKindEnum.IsAsync), symbolSpec.RequiredModifierList); Assert.Empty(symbolSpec.ApplicableAccessibilityList); @@ -136,11 +136,11 @@ public static void TestPublicMembersCapitalizedRule() Assert.Equal("public_symbols", symbolSpec.Name); var expectedApplicableSymbolKindList = new[] { - new SymbolKindOrTypeKind(SymbolKind.Property), - new SymbolKindOrTypeKind(SymbolKind.Method), - new SymbolKindOrTypeKind(SymbolKind.Field), - new SymbolKindOrTypeKind(SymbolKind.Event), - new SymbolKindOrTypeKind(TypeKind.Delegate) + new SymbolOrTypeOrMethodKind(SymbolKind.Property), + new SymbolOrTypeOrMethodKind(SymbolKind.Method), + new SymbolOrTypeOrMethodKind(SymbolKind.Field), + new SymbolOrTypeOrMethodKind(SymbolKind.Event), + new SymbolOrTypeOrMethodKind(TypeKind.Delegate) }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); var expectedApplicableAccessibilityList = new[] @@ -184,11 +184,11 @@ public static void TestNonPublicMembersLowerCaseRule() Assert.Equal("non_public_symbols", symbolSpec.Name); var expectedApplicableSymbolKindList = new[] { - new SymbolKindOrTypeKind(SymbolKind.Property), - new SymbolKindOrTypeKind(SymbolKind.Method), - new SymbolKindOrTypeKind(SymbolKind.Field), - new SymbolKindOrTypeKind(SymbolKind.Event), - new SymbolKindOrTypeKind(TypeKind.Delegate) + new SymbolOrTypeOrMethodKind(SymbolKind.Property), + new SymbolOrTypeOrMethodKind(SymbolKind.Method), + new SymbolOrTypeOrMethodKind(SymbolKind.Field), + new SymbolOrTypeOrMethodKind(SymbolKind.Event), + new SymbolOrTypeOrMethodKind(TypeKind.Delegate) }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); Assert.Single(symbolSpec.ApplicableAccessibilityList); @@ -228,8 +228,8 @@ public static void TestParametersAndLocalsAreCamelCaseRule() Assert.Equal("parameters_and_locals", symbolSpec.Name); var expectedApplicableSymbolKindList = new[] { - new SymbolKindOrTypeKind(SymbolKind.Parameter), - new SymbolKindOrTypeKind(SymbolKind.Local), + new SymbolOrTypeOrMethodKind(SymbolKind.Parameter), + new SymbolOrTypeOrMethodKind(SymbolKind.Local), }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); diff --git a/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs b/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs index 781a496f46543..dd30b81db19b2 100644 --- a/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs +++ b/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs @@ -56,7 +56,7 @@ private static NamingStylePreferences ClassNamesArePascalCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(TypeKind.Class)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(TypeKind.Class)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -86,7 +86,7 @@ private static NamingStylePreferences MethodNamesArePascalCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Method)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Method)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -117,7 +117,7 @@ private static NamingStylePreferences ParameterNamesAreCamelCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Parameter)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Parameter)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -149,7 +149,7 @@ private static NamingStylePreferences LocalNamesAreCamelCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Local)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Local)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -181,7 +181,7 @@ private static NamingStylePreferences PropertyNamesArePascalCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Property)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Property)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -213,7 +213,7 @@ private static NamingStylePreferences InterfacesNamesStartWithIOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(TypeKind.Interface)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(TypeKind.Interface)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -246,8 +246,8 @@ private static NamingStylePreferences ConstantsAreUpperCaseOption() null, "Name", ImmutableArray.Create( - new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field), - new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Local)), + new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Field), + new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Local)), ImmutableArray.Empty, ImmutableArray.Create(new SymbolSpecification.ModifierKind(SymbolSpecification.ModifierKindEnum.IsConst))); @@ -279,14 +279,14 @@ private static NamingStylePreferences LocalsAreCamelCaseConstantsAreUpperCaseOpt var localsSymbolSpecification = new SymbolSpecification( null, "Locals", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Local)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Local)), ImmutableArray.Empty, ImmutableArray.Empty); var constLocalsSymbolSpecification = new SymbolSpecification( null, "Const Locals", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Local)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Local)), ImmutableArray.Empty, ImmutableArray.Create(new SymbolSpecification.ModifierKind(SymbolSpecification.ModifierKindEnum.IsConst))); diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.cs index a3817f45af929..dc529d133ed9c 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.cs @@ -223,7 +223,7 @@ private Glyph GetGlyph(SymbolKind kind, Accessibility declaredAccessibility) var result = new Dictionary(); foreach (var symbolKind in declarationInfo.PossibleSymbolKinds) { - var kind = new SymbolKindOrTypeKind(symbolKind); + var kind = new SymbolOrTypeOrMethodKind(symbolKind); var modifiers = declarationInfo.Modifiers; foreach (var rule in rules) { diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs index 2c21388d9032b..2e1d3416ffb67 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs @@ -23,7 +23,7 @@ static DeclarationNameCompletionProvider() private static NamingRule CreateGetAsyncRule() { - var kinds = ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Method)); + var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Method)); var modifiers = ImmutableArray.Create(new ModifierKind(ModifierKindEnum.IsAsync)); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "endswithasync", kinds, ImmutableArray.Create(), modifiers), @@ -33,7 +33,7 @@ private static NamingRule CreateGetAsyncRule() private static NamingRule CreateCamelCaseFieldsAndParametersRule() { - var kinds = ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Field), new SymbolKindOrTypeKind(SymbolKind.Parameter), new SymbolKindOrTypeKind(SymbolKind.Local)); + var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Field), new SymbolOrTypeOrMethodKind(SymbolKind.Parameter), new SymbolOrTypeOrMethodKind(SymbolKind.Local)); var modifiers = ImmutableArray.Create(); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "camelcasefields", kinds, ImmutableArray.Create(), modifiers), @@ -43,7 +43,7 @@ private static NamingRule CreateCamelCaseFieldsAndParametersRule() private static NamingRule CreateEndWithAsyncRule() { - var kinds = ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Method)); + var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Method)); var modifiers = ImmutableArray.Create(new ModifierKind(ModifierKindEnum.IsAsync)); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "endswithasynct", kinds, ImmutableArray.Create(), modifiers), @@ -53,7 +53,7 @@ private static NamingRule CreateEndWithAsyncRule() private static NamingRule CreateMethodStartsWithGetRule() { - var kinds = ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Method)); + var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Method)); var modifiers = ImmutableArray.Create(); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "startswithget", kinds, ImmutableArray.Create(), modifiers), diff --git a/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs index 1ec35406a13b6..d83d448143281 100644 --- a/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs @@ -87,7 +87,7 @@ private static ImmutableArray CreateNewRule( new SymbolSpecification( Guid.NewGuid(), "Field", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Field)), modifiers: modifiers), new NamingStyles.NamingStyle( Guid.NewGuid(), @@ -103,7 +103,7 @@ private string GenerateFieldName(IPropertySymbol property, ImmutableArray s_builtInRules = ImmutableArray.Create( new NamingRule(new SymbolSpecification( Guid.NewGuid(), "Property", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Property))), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Property))), new NamingStyles.NamingStyle(Guid.NewGuid(), capitalizationScheme: Capitalization.PascalCase), enforcementLevel: DiagnosticSeverity.Hidden), new NamingRule(new SymbolSpecification( Guid.NewGuid(), "Field", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field))), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Field))), new NamingStyles.NamingStyle(Guid.NewGuid(), capitalizationScheme: Capitalization.CamelCase), enforcementLevel: DiagnosticSeverity.Hidden), new NamingRule(new SymbolSpecification( Guid.NewGuid(), "FieldWithUnderscore", - ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field))), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Field))), new NamingStyles.NamingStyle(Guid.NewGuid(), prefix: "_", capitalizationScheme: Capitalization.CamelCase), enforcementLevel: DiagnosticSeverity.Hidden)); diff --git a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs index 7c3ef60b550ac..ed855a4a41951 100644 --- a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs +++ b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs @@ -182,15 +182,15 @@ public SymbolKindViewModel(TypeKind typeKind, string name, SymbolSpecification s IsChecked = specification.ApplicableSymbolKindList.Any(k => k.TypeKind == typeKind); } - internal SymbolKindOrTypeKind CreateSymbolKindOrTypeKind() + internal SymbolOrTypeOrMethodKind CreateSymbolKindOrTypeKind() { if (_symbolKind.HasValue) { - return new SymbolKindOrTypeKind(_symbolKind.Value); + return new SymbolOrTypeOrMethodKind(_symbolKind.Value); } else { - return new SymbolKindOrTypeKind(_typeKind.Value); + return new SymbolOrTypeOrMethodKind(_typeKind.Value); } } } diff --git a/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs b/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs index 0d8176d9d9ca2..4d4e9b786db81 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs @@ -50,7 +50,7 @@ private static bool TryGetSymbolSpecNameForNamingRule( return false; } - private static ImmutableArray GetSymbolsApplicableKinds( + private static ImmutableArray GetSymbolsApplicableKinds( string symbolSpecName, IReadOnlyDictionary conventionsDictionary) { @@ -59,21 +59,21 @@ private static ImmutableArray GetSymbolsApplicableKinds( return ParseSymbolKindList(result as string ?? string.Empty); } - return ImmutableArray.Empty; + return ImmutableArray.Empty; } - private static readonly SymbolKindOrTypeKind _class = new SymbolKindOrTypeKind(TypeKind.Class); - private static readonly SymbolKindOrTypeKind _struct = new SymbolKindOrTypeKind(TypeKind.Struct); - private static readonly SymbolKindOrTypeKind _interface = new SymbolKindOrTypeKind(TypeKind.Interface); - private static readonly SymbolKindOrTypeKind _enum = new SymbolKindOrTypeKind(TypeKind.Enum); - private static readonly SymbolKindOrTypeKind _property = new SymbolKindOrTypeKind(SymbolKind.Property); - private static readonly SymbolKindOrTypeKind _method = new SymbolKindOrTypeKind(SymbolKind.Method); - private static readonly SymbolKindOrTypeKind _field = new SymbolKindOrTypeKind(SymbolKind.Field); - private static readonly SymbolKindOrTypeKind _event = new SymbolKindOrTypeKind(SymbolKind.Event); - private static readonly SymbolKindOrTypeKind _delegate = new SymbolKindOrTypeKind(TypeKind.Delegate); - private static readonly SymbolKindOrTypeKind _parameter = new SymbolKindOrTypeKind(SymbolKind.Parameter); - private static readonly SymbolKindOrTypeKind _local = new SymbolKindOrTypeKind(SymbolKind.Local); - private static readonly ImmutableArray _all = + private static readonly SymbolOrTypeOrMethodKind _class = new SymbolOrTypeOrMethodKind(TypeKind.Class); + private static readonly SymbolOrTypeOrMethodKind _struct = new SymbolOrTypeOrMethodKind(TypeKind.Struct); + private static readonly SymbolOrTypeOrMethodKind _interface = new SymbolOrTypeOrMethodKind(TypeKind.Interface); + private static readonly SymbolOrTypeOrMethodKind _enum = new SymbolOrTypeOrMethodKind(TypeKind.Enum); + private static readonly SymbolOrTypeOrMethodKind _property = new SymbolOrTypeOrMethodKind(SymbolKind.Property); + private static readonly SymbolOrTypeOrMethodKind _method = new SymbolOrTypeOrMethodKind(SymbolKind.Method); + private static readonly SymbolOrTypeOrMethodKind _field = new SymbolOrTypeOrMethodKind(SymbolKind.Field); + private static readonly SymbolOrTypeOrMethodKind _event = new SymbolOrTypeOrMethodKind(SymbolKind.Event); + private static readonly SymbolOrTypeOrMethodKind _delegate = new SymbolOrTypeOrMethodKind(TypeKind.Delegate); + private static readonly SymbolOrTypeOrMethodKind _parameter = new SymbolOrTypeOrMethodKind(SymbolKind.Parameter); + private static readonly SymbolOrTypeOrMethodKind _local = new SymbolOrTypeOrMethodKind(SymbolKind.Local); + private static readonly ImmutableArray _all = ImmutableArray.Create( _class, _struct, @@ -87,11 +87,11 @@ private static ImmutableArray GetSymbolsApplicableKinds( _parameter, _local); - private static ImmutableArray ParseSymbolKindList(string symbolSpecApplicableKinds) + private static ImmutableArray ParseSymbolKindList(string symbolSpecApplicableKinds) { if (symbolSpecApplicableKinds == null) { - return ImmutableArray.Empty; + return ImmutableArray.Empty; } if (symbolSpecApplicableKinds.Trim() == "*") @@ -99,7 +99,7 @@ private static ImmutableArray ParseSymbolKindList(string s return _all; } - var builder = ArrayBuilder.GetInstance(); + var builder = ArrayBuilder.GetInstance(); foreach (var symbolSpecApplicableKind in symbolSpecApplicableKinds.Split(',').Select(x => x.Trim())) { switch (symbolSpecApplicableKind) diff --git a/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs b/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs index 8611ee2e3efe5..5a9cdd68fc1cb 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs @@ -17,13 +17,13 @@ internal class SymbolSpecification public Guid ID { get; } public string Name { get; } - public ImmutableArray ApplicableSymbolKindList { get; } + public ImmutableArray ApplicableSymbolKindList { get; } public ImmutableArray ApplicableAccessibilityList { get; } public ImmutableArray RequiredModifierList { get; } public SymbolSpecification( Guid? id, string symbolSpecName, - ImmutableArray symbolKindList, + ImmutableArray symbolKindList, ImmutableArray accessibilityList = default, ImmutableArray modifiers = default) { @@ -44,21 +44,21 @@ public static SymbolSpecification CreateDefaultSymbolSpecification() id: Guid.NewGuid(), symbolSpecName: null, symbolKindList: ImmutableArray.Create( - new SymbolKindOrTypeKind(SymbolKind.Namespace), - new SymbolKindOrTypeKind(TypeKind.Class), - new SymbolKindOrTypeKind(TypeKind.Struct), - new SymbolKindOrTypeKind(TypeKind.Interface), - new SymbolKindOrTypeKind(TypeKind.Delegate), - new SymbolKindOrTypeKind(TypeKind.Enum), - new SymbolKindOrTypeKind(TypeKind.Module), - new SymbolKindOrTypeKind(TypeKind.Pointer), - new SymbolKindOrTypeKind(TypeKind.TypeParameter), - new SymbolKindOrTypeKind(SymbolKind.Property), - new SymbolKindOrTypeKind(SymbolKind.Method), - new SymbolKindOrTypeKind(SymbolKind.Field), - new SymbolKindOrTypeKind(SymbolKind.Event), - new SymbolKindOrTypeKind(SymbolKind.Parameter), - new SymbolKindOrTypeKind(SymbolKind.Local)), + new SymbolOrTypeOrMethodKind(SymbolKind.Namespace), + new SymbolOrTypeOrMethodKind(TypeKind.Class), + new SymbolOrTypeOrMethodKind(TypeKind.Struct), + new SymbolOrTypeOrMethodKind(TypeKind.Interface), + new SymbolOrTypeOrMethodKind(TypeKind.Delegate), + new SymbolOrTypeOrMethodKind(TypeKind.Enum), + new SymbolOrTypeOrMethodKind(TypeKind.Module), + new SymbolOrTypeOrMethodKind(TypeKind.Pointer), + new SymbolOrTypeOrMethodKind(TypeKind.TypeParameter), + new SymbolOrTypeOrMethodKind(SymbolKind.Property), + new SymbolOrTypeOrMethodKind(SymbolKind.Method), + new SymbolOrTypeOrMethodKind(SymbolKind.Field), + new SymbolOrTypeOrMethodKind(SymbolKind.Event), + new SymbolOrTypeOrMethodKind(SymbolKind.Parameter), + new SymbolOrTypeOrMethodKind(SymbolKind.Local)), accessibilityList: ImmutableArray.Create( Accessibility.Public, Accessibility.Internal, @@ -77,9 +77,9 @@ internal bool AppliesTo(ISymbol symbol) } internal bool AppliesTo(SymbolKind symbolKind, Accessibility accessibility) - => this.AppliesTo(new SymbolKindOrTypeKind(symbolKind), new DeclarationModifiers(), accessibility); + => this.AppliesTo(new SymbolOrTypeOrMethodKind(symbolKind), new DeclarationModifiers(), accessibility); - internal bool AppliesTo(SymbolKindOrTypeKind kind, DeclarationModifiers modifiers, Accessibility accessibility) + internal bool AppliesTo(SymbolOrTypeOrMethodKind kind, DeclarationModifiers modifiers, Accessibility accessibility) { if (ApplicableSymbolKindList.Any() && !ApplicableSymbolKindList.Any(k => k.Equals(kind))) { @@ -239,17 +239,17 @@ internal static SymbolSpecification FromXElement(XElement symbolSpecificationEle accessibilityList: GetAccessibilityListFromXElement(symbolSpecificationElement.Element(nameof(ApplicableAccessibilityList))), modifiers: GetModifierListFromXElement(symbolSpecificationElement.Element(nameof(RequiredModifierList)))); - private static ImmutableArray GetSymbolKindListFromXElement(XElement symbolKindListElement) + private static ImmutableArray GetSymbolKindListFromXElement(XElement symbolKindListElement) { - var applicableSymbolKindList = ArrayBuilder.GetInstance(); + var applicableSymbolKindList = ArrayBuilder.GetInstance(); foreach (var symbolKindElement in symbolKindListElement.Elements(nameof(SymbolKind))) { - applicableSymbolKindList.Add(SymbolKindOrTypeKind.AddSymbolKindFromXElement(symbolKindElement)); + applicableSymbolKindList.Add(SymbolOrTypeOrMethodKind.AddSymbolKindFromXElement(symbolKindElement)); } foreach (var typeKindElement in symbolKindListElement.Elements(nameof(TypeKind))) { - applicableSymbolKindList.Add(SymbolKindOrTypeKind.AddTypeKindFromXElement(typeKindElement)); + applicableSymbolKindList.Add(SymbolOrTypeOrMethodKind.AddTypeKindFromXElement(typeKindElement)); } return applicableSymbolKindList.ToImmutableAndFree(); @@ -281,48 +281,66 @@ private interface ISymbolMatcher bool MatchesSymbol(ISymbol symbol); } - public struct SymbolKindOrTypeKind : IEquatable, ISymbolMatcher + public struct SymbolOrTypeOrMethodKind : IEquatable, ISymbolMatcher { public SymbolKind? SymbolKind { get; } public TypeKind? TypeKind { get; } + public MethodKind? MethodKind { get; } - public SymbolKindOrTypeKind(SymbolKind symbolKind) : this() + public SymbolOrTypeOrMethodKind(SymbolKind symbolKind) : this() { SymbolKind = symbolKind; TypeKind = null; + MethodKind = null; } - public SymbolKindOrTypeKind(TypeKind typeKind) : this() + public SymbolOrTypeOrMethodKind(TypeKind typeKind) : this() { SymbolKind = null; TypeKind = typeKind; + MethodKind = null; + } + + public SymbolOrTypeOrMethodKind(MethodKind methodKind) : this() + { + SymbolKind = null; + TypeKind = null; + MethodKind = methodKind; } public bool MatchesSymbol(ISymbol symbol) - => SymbolKind.HasValue - ? symbol.IsKind(SymbolKind.Value) - : symbol is ITypeSymbol s && s.TypeKind == TypeKind.Value; + => SymbolKind.HasValue ? symbol.IsKind(SymbolKind.Value) : + TypeKind.HasValue ? symbol is ITypeSymbol type && type.TypeKind == TypeKind.Value : + MethodKind.HasValue ? symbol is IMethodSymbol method && method.MethodKind == MethodKind.Value : + throw ExceptionUtilities.Unreachable; internal XElement CreateXElement() - => SymbolKind.HasValue - ? new XElement(nameof(SymbolKind), SymbolKind) - : new XElement(nameof(TypeKind), TypeKind); + => SymbolKind.HasValue ? new XElement(nameof(SymbolKind), SymbolKind) : + TypeKind.HasValue ? new XElement(nameof(TypeKind), TypeKind) : + MethodKind.HasValue ? new XElement(nameof(MethodKind), MethodKind) : + throw ExceptionUtilities.Unreachable; + + internal static SymbolOrTypeOrMethodKind AddSymbolKindFromXElement(XElement symbolKindElement) + => new SymbolOrTypeOrMethodKind((SymbolKind)Enum.Parse(typeof(SymbolKind), symbolKindElement.Value)); - internal static SymbolKindOrTypeKind AddSymbolKindFromXElement(XElement symbolKindElement) - => new SymbolKindOrTypeKind((SymbolKind)Enum.Parse(typeof(SymbolKind), symbolKindElement.Value)); + internal static SymbolOrTypeOrMethodKind AddTypeKindFromXElement(XElement typeKindElement) + => new SymbolOrTypeOrMethodKind((TypeKind)Enum.Parse(typeof(TypeKind), typeKindElement.Value)); - internal static SymbolKindOrTypeKind AddTypeKindFromXElement(XElement typeKindElement) - => new SymbolKindOrTypeKind((TypeKind)Enum.Parse(typeof(TypeKind), typeKindElement.Value)); + internal static SymbolOrTypeOrMethodKind AddMethodKindFromXElement(XElement methodKindElement) + => new SymbolOrTypeOrMethodKind((MethodKind)Enum.Parse(typeof(MethodKind), methodKindElement.Value)); public override bool Equals(object obj) - => Equals((SymbolKindOrTypeKind)obj); + => Equals((SymbolOrTypeOrMethodKind)obj); - public bool Equals(SymbolKindOrTypeKind other) - => this.SymbolKind == other.SymbolKind && this.TypeKind == other.TypeKind; + public bool Equals(SymbolOrTypeOrMethodKind other) + => this.SymbolKind == other.SymbolKind && this.TypeKind == other.TypeKind && this.MethodKind == other.MethodKind; public override int GetHashCode() - => Hash.Combine((int)this.SymbolKind.GetValueOrDefault(), - (int)this.TypeKind.GetValueOrDefault()); + => Hash.CombineValues(new[] { + (int)this.SymbolKind.GetValueOrDefault(), + (int)this.TypeKind.GetValueOrDefault(), + (int)this.MethodKind.GetValueOrDefault() + }); } public struct ModifierKind : ISymbolMatcher From 6cb35298961932bda4a24db25714e6649d51afb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Sun, 15 Apr 2018 18:21:34 +0200 Subject: [PATCH 02/23] Adding local function symbol specification --- .../EditorConfigNamingStyleParserTests.cs | 8 ++++---- .../EditorConfigNamingStyleParser_SymbolSpec.cs | 7 ++++++- .../Core/Portable/NamingStyles/NamingStyleRules.cs | 9 +++++---- .../Serialization/NamingStylePreferences.cs | 12 ++++++------ .../Serialization/SymbolSpecification.cs | 8 +++++++- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs index 231b60fb26889..545355b1be706 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs @@ -37,7 +37,7 @@ public static void TestPascalCaseRule() Assert.Equal("method_and_property_symbols", symbolSpec.Name); var expectedApplicableSymbolKindList = new[] { - new SymbolOrTypeOrMethodKind(SymbolKind.Method), + new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), new SymbolOrTypeOrMethodKind(SymbolKind.Property) }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); @@ -83,7 +83,7 @@ public static void TestAsyncMethodsRule() Assert.Equal(DiagnosticSeverity.Error, namingRule.EnforcementLevel); Assert.Equal("method_symbols", symbolSpec.Name); Assert.Single(symbolSpec.ApplicableSymbolKindList); - Assert.Contains(new SymbolOrTypeOrMethodKind(SymbolKind.Method), symbolSpec.ApplicableSymbolKindList); + Assert.Contains(new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), symbolSpec.ApplicableSymbolKindList); Assert.Single(symbolSpec.RequiredModifierList); Assert.Contains(new ModifierKind(ModifierKindEnum.IsAsync), symbolSpec.RequiredModifierList); Assert.Empty(symbolSpec.ApplicableAccessibilityList); @@ -137,7 +137,7 @@ public static void TestPublicMembersCapitalizedRule() var expectedApplicableSymbolKindList = new[] { new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(SymbolKind.Method), + new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), new SymbolOrTypeOrMethodKind(SymbolKind.Field), new SymbolOrTypeOrMethodKind(SymbolKind.Event), new SymbolOrTypeOrMethodKind(TypeKind.Delegate) @@ -185,7 +185,7 @@ public static void TestNonPublicMembersLowerCaseRule() var expectedApplicableSymbolKindList = new[] { new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(SymbolKind.Method), + new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), new SymbolOrTypeOrMethodKind(SymbolKind.Field), new SymbolOrTypeOrMethodKind(SymbolKind.Event), new SymbolOrTypeOrMethodKind(TypeKind.Delegate) diff --git a/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs b/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs index 4d4e9b786db81..f928256d0b94b 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs @@ -67,7 +67,8 @@ private static ImmutableArray GetSymbolsApplicableKind private static readonly SymbolOrTypeOrMethodKind _interface = new SymbolOrTypeOrMethodKind(TypeKind.Interface); private static readonly SymbolOrTypeOrMethodKind _enum = new SymbolOrTypeOrMethodKind(TypeKind.Enum); private static readonly SymbolOrTypeOrMethodKind _property = new SymbolOrTypeOrMethodKind(SymbolKind.Property); - private static readonly SymbolOrTypeOrMethodKind _method = new SymbolOrTypeOrMethodKind(SymbolKind.Method); + private static readonly SymbolOrTypeOrMethodKind _method = new SymbolOrTypeOrMethodKind(MethodKind.Ordinary); + private static readonly SymbolOrTypeOrMethodKind _localFunction = new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction); private static readonly SymbolOrTypeOrMethodKind _field = new SymbolOrTypeOrMethodKind(SymbolKind.Field); private static readonly SymbolOrTypeOrMethodKind _event = new SymbolOrTypeOrMethodKind(SymbolKind.Event); private static readonly SymbolOrTypeOrMethodKind _delegate = new SymbolOrTypeOrMethodKind(TypeKind.Delegate); @@ -81,6 +82,7 @@ private static ImmutableArray GetSymbolsApplicableKind _enum, _property, _method, + _localFunction, _field, _event, _delegate, @@ -122,6 +124,9 @@ private static ImmutableArray ParseSymbolKindList(stri case "method": builder.Add(_method); break; + case "local_function": + builder.Add(_localFunction); + break; case "field": builder.Add(_field); break; diff --git a/src/Workspaces/Core/Portable/NamingStyles/NamingStyleRules.cs b/src/Workspaces/Core/Portable/NamingStyles/NamingStyleRules.cs index 43f876c27674f..5aeda195c2966 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/NamingStyleRules.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/NamingStyleRules.cs @@ -47,14 +47,15 @@ private bool IsSymbolNameAnalyzable(ISymbol symbol) return false; } - if (symbol.Kind == SymbolKind.Method) + if (symbol is IMethodSymbol method) { - return ((IMethodSymbol)symbol).MethodKind == MethodKind.Ordinary; + return method.MethodKind == MethodKind.Ordinary || + method.MethodKind == MethodKind.LocalFunction; } - if (symbol.Kind == SymbolKind.Property) + if (symbol is IPropertySymbol property) { - return !((IPropertySymbol)symbol).IsIndexer; + return !property.IsIndexer; } return true; diff --git a/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs b/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs index addf4ac7f98a4..6e46530e7b7a5 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs @@ -16,7 +16,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles /// internal class NamingStylePreferences : IEquatable { - private const int s_serializationVersion = 4; + private const int s_serializationVersion = 5; public readonly ImmutableArray SymbolSpecifications; public readonly ImmutableArray NamingStyles; @@ -190,7 +190,7 @@ public override int GetHashCode() - Method + Ordinary Public @@ -199,7 +199,7 @@ public override int GetHashCode() - Method + Ordinary Private @@ -208,7 +208,7 @@ public override int GetHashCode() - Method + Ordinary Public @@ -223,7 +223,7 @@ public override int GetHashCode() - Method + Ordinary Public @@ -315,7 +315,7 @@ public override int GetHashCode() Property - Method + Ordinary Event diff --git a/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs b/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs index 5a9cdd68fc1cb..b0c51f11a73e4 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs @@ -54,7 +54,8 @@ public static SymbolSpecification CreateDefaultSymbolSpecification() new SymbolOrTypeOrMethodKind(TypeKind.Pointer), new SymbolOrTypeOrMethodKind(TypeKind.TypeParameter), new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(SymbolKind.Method), + new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), + new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction), new SymbolOrTypeOrMethodKind(SymbolKind.Field), new SymbolOrTypeOrMethodKind(SymbolKind.Event), new SymbolOrTypeOrMethodKind(SymbolKind.Parameter), @@ -252,6 +253,11 @@ private static ImmutableArray GetSymbolKindListFromXEl applicableSymbolKindList.Add(SymbolOrTypeOrMethodKind.AddTypeKindFromXElement(typeKindElement)); } + foreach (var methodKindElement in symbolKindListElement.Elements(nameof(MethodKind))) + { + applicableSymbolKindList.Add(SymbolOrTypeOrMethodKind.AddMethodKindFromXElement(methodKindElement)); + } + return applicableSymbolKindList.ToImmutableAndFree(); } From 06009c9fddbfe946020dba71b961c7249d4d90ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Sun, 15 Apr 2018 18:49:10 +0200 Subject: [PATCH 03/23] Adding EditorConfig test --- .../EditorConfigNamingStyleParserTests.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs index 545355b1be706..12c31ab517324 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs @@ -232,6 +232,45 @@ public static void TestParametersAndLocalsAreCamelCaseRule() new SymbolOrTypeOrMethodKind(SymbolKind.Local), }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); + Assert.Empty(symbolSpec.ApplicableAccessibilityList); + Assert.Empty(symbolSpec.RequiredModifierList); + + Assert.Equal("camel_case_style", namingStyle.Name); + Assert.Equal("", namingStyle.Prefix); + Assert.Equal("", namingStyle.Suffix); + Assert.Equal("", namingStyle.WordSeparator); + Assert.Equal(Capitalization.CamelCase, namingStyle.CapitalizationScheme); + } + + [Fact] + public static void TestLocalFunctionsAreCamelCaseRule() + { + var dictionary = new Dictionary() + { + ["dotnet_naming_rule.local_functions_are_camel_case.severity"] = "suggestion", + ["dotnet_naming_rule.local_functions_are_camel_case.symbols"] = "local_functions", + ["dotnet_naming_rule.local_functions_are_camel_case.style"] = "camel_case_style", + ["dotnet_naming_symbols.local_functions.applicable_kinds"] = "local_function", + ["dotnet_naming_style.camel_case_style.capitalization"] = "camel_case", + }; + + var result = ParseDictionary(dictionary); + Assert.Single(result.NamingRules); + var namingRule = result.NamingRules.Single(); + Assert.Single(result.NamingStyles); + var namingStyle = result.NamingStyles.Single(); + Assert.Single(result.SymbolSpecifications); + + var symbolSpec = result.SymbolSpecifications.Single(); + Assert.Equal(namingStyle.ID, namingRule.NamingStyleID); + Assert.Equal(symbolSpec.ID, namingRule.SymbolSpecificationID); + Assert.Equal(DiagnosticSeverity.Info, namingRule.EnforcementLevel); + + Assert.Equal("local_functions", symbolSpec.Name); + var expectedApplicableSymbolKindList = new[] { new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction) }; + AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); + Assert.Empty(symbolSpec.ApplicableAccessibilityList); + Assert.Empty(symbolSpec.RequiredModifierList); Assert.Equal("camel_case_style", namingStyle.Name); Assert.Equal("", namingStyle.Prefix); From 4484ca7019505feec7fea715bf6bf60ce79ecfce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Sun, 15 Apr 2018 19:53:37 +0200 Subject: [PATCH 04/23] Adding code fix tests --- .../NamingStyles/NamingStylesTests.cs | 52 +++++++++++++++++++ .../NamingStylesTestOptionSets.cs | 37 ++++++++++++- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs index be932c843aeac..50f12a79b16ce 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs @@ -112,6 +112,21 @@ public int [|this|][int index] }", new TestParameters(options: options.MethodNamesArePascalCase)); } + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public async Task TestPascalCaseMethod_LocalFunctionIsIgnored() + { + await TestMissingInRegularAndScriptAsync( +@"class C +{ + void M() + { + void [|f|]() + { + } + } +}", new TestParameters(options: options.MethodNamesArePascalCase)); + } + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] public async Task TestCamelCaseParameters() { @@ -697,6 +712,43 @@ void M() options: options.LocalsAreCamelCaseConstantsAreUpperCase); } + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public async Task TestCamelCaseLocalFunctions() + { + await TestInRegularAndScriptAsync( +@"class C +{ + void M() + { + void [|F|]() + { + } + } +}", +@"class C +{ + void M() + { + void f() + { + } + } +}", + options: options.LocalFunctionNamesAreCamelCase); + } + + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public async Task TestCamelCaseLocalFunctions_MethodIsIgnored() + { + await TestMissingInRegularAndScriptAsync( +@"class C +{ + void [|M|]() + { + } +}", new TestParameters(options: options.LocalFunctionNamesAreCamelCase)); + } + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] public async Task TestPascalCaseMethod_InInterfaceWithImplicitImplementation() { diff --git a/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs b/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs index dd30b81db19b2..6fd8de7745ce3 100644 --- a/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs +++ b/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs @@ -31,6 +31,9 @@ public NamingStylesTestOptionSets(string languageName) public IDictionary LocalNamesAreCamelCase => Options(new OptionKey(SimplificationOptions.NamingPreferences, languageName), LocalNamesAreCamelCaseOption()); + public IDictionary LocalFunctionNamesAreCamelCase => + Options(new OptionKey(SimplificationOptions.NamingPreferences, languageName), LocalFunctionNamesAreCamelCaseOption()); + public IDictionary PropertyNamesArePascalCase => Options(new OptionKey(SimplificationOptions.NamingPreferences, languageName), PropertyNamesArePascalCaseOption()); @@ -86,7 +89,7 @@ private static NamingStylePreferences MethodNamesArePascalCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Method)), + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(MethodKind.Ordinary)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -176,6 +179,38 @@ private static NamingStylePreferences LocalNamesAreCamelCaseOption() return info; } + private static NamingStylePreferences LocalFunctionNamesAreCamelCaseOption() + { + var symbolSpecification = new SymbolSpecification( + null, + "Name", + ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)), + ImmutableArray.Empty, + ImmutableArray.Empty); + + var namingStyle = new NamingStyle( + Guid.NewGuid(), + capitalizationScheme: Capitalization.CamelCase, + name: "Name", + prefix: "", + suffix: "", + wordSeparator: ""); + + var namingRule = new SerializableNamingRule() + { + SymbolSpecificationID = symbolSpecification.ID, + NamingStyleID = namingStyle.ID, + EnforcementLevel = DiagnosticSeverity.Error + }; + + var info = new NamingStylePreferences( + ImmutableArray.Create(symbolSpecification), + ImmutableArray.Create(namingStyle), + ImmutableArray.Create(namingRule)); + + return info; + } + private static NamingStylePreferences PropertyNamesArePascalCaseOption() { var symbolSpecification = new SymbolSpecification( From 62c426c2c16788cd68aaa882067ab76d72065432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Thu, 10 May 2018 02:27:35 +0200 Subject: [PATCH 05/23] Adding analysis of local functions This reverts commit 18659c7ba8adbbc2b6870403ce335001e7943ebd. --- .../Analyzers/CSharpNamingStyleDiagnosticAnalyzer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Features/CSharp/Portable/Diagnostics/Analyzers/CSharpNamingStyleDiagnosticAnalyzer.cs b/src/Features/CSharp/Portable/Diagnostics/Analyzers/CSharpNamingStyleDiagnosticAnalyzer.cs index 1c28e966c65b1..b85c1914dead8 100644 --- a/src/Features/CSharp/Portable/Diagnostics/Analyzers/CSharpNamingStyleDiagnosticAnalyzer.cs +++ b/src/Features/CSharp/Portable/Diagnostics/Analyzers/CSharpNamingStyleDiagnosticAnalyzer.cs @@ -14,6 +14,7 @@ internal sealed class CSharpNamingStyleDiagnosticAnalyzer : NamingStyleDiagnosti SyntaxKind.VariableDeclarator, SyntaxKind.ForEachStatement, SyntaxKind.CatchDeclaration, - SyntaxKind.SingleVariableDesignation); + SyntaxKind.SingleVariableDesignation, + SyntaxKind.LocalFunctionStatement); } } From 2dcfaf507d90557a654a3f596e74e3edf6255a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Sun, 15 Apr 2018 20:25:47 +0200 Subject: [PATCH 06/23] Adding VS integration --- .../NamingStyleOptionPageViewModel.cs | 2 +- .../SymbolSpecificationViewModel.cs | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/NamingStyleOptionPageViewModel.cs b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/NamingStyleOptionPageViewModel.cs index 77142e0081ab6..8dbf130262b5e 100644 --- a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/NamingStyleOptionPageViewModel.cs +++ b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/NamingStyleOptionPageViewModel.cs @@ -92,7 +92,7 @@ internal void UpdateSpecificationList(ManageSymbolSpecificationsDialogViewModel var symbolSpecifications = viewModel.Items.Cast().Select(n => new SymbolSpecification( n.ID, n.ItemName, - n.SymbolKindList.Where(s => s.IsChecked).Select(k => k.CreateSymbolKindOrTypeKind()).ToImmutableArray(), + n.SymbolKindList.Where(s => s.IsChecked).Select(k => k.CreateSymbolOrTypeOrMethodKind()).ToImmutableArray(), n.AccessibilityList.Where(s => s.IsChecked).Select(a => a._accessibility).ToImmutableArray(), n.ModifierList.Where(s => s.IsChecked).Select(m => new SymbolSpecification.ModifierKind(m._modifier)).ToImmutableArray())); diff --git a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs index ed855a4a41951..475ad89c97277 100644 --- a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs +++ b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs @@ -9,6 +9,7 @@ using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Notification; using Microsoft.VisualStudio.LanguageServices.Implementation.Utilities; +using Roslyn.Utilities; using static Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles.SymbolSpecification; namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences @@ -48,7 +49,8 @@ public SymbolSpecificationViewModel(string languageName, SymbolSpecification spe new SymbolKindViewModel(TypeKind.Interface, "interface", specification), new SymbolKindViewModel(TypeKind.Enum, "enum", specification), new SymbolKindViewModel(SymbolKind.Property, "property", specification), - new SymbolKindViewModel(SymbolKind.Method, "method", specification), + new SymbolKindViewModel(MethodKind.Ordinary, "method", specification), + new SymbolKindViewModel(MethodKind.LocalFunction, "local function", specification), new SymbolKindViewModel(SymbolKind.Field, "field", specification), new SymbolKindViewModel(SymbolKind.Event, "event", specification), new SymbolKindViewModel(TypeKind.Delegate, "delegate", specification), @@ -127,7 +129,7 @@ internal SymbolSpecification GetSymbolSpecification() return new SymbolSpecification( ID, ItemName, - SymbolKindList.Where(s => s.IsChecked).Select(s => s.CreateSymbolKindOrTypeKind()).ToImmutableArray(), + SymbolKindList.Where(s => s.IsChecked).Select(s => s.CreateSymbolOrTypeOrMethodKind()).ToImmutableArray(), AccessibilityList.Where(a => a.IsChecked).Select(a => a._accessibility).ToImmutableArray(), ModifierList.Where(m => m.IsChecked).Select(m => new ModifierKind(m._modifier)).ToImmutableArray()); } @@ -165,6 +167,7 @@ public bool IsChecked private readonly SymbolKind? _symbolKind; private readonly TypeKind? _typeKind; + private readonly MethodKind? _methodKind; private bool _isChecked; @@ -182,16 +185,20 @@ public SymbolKindViewModel(TypeKind typeKind, string name, SymbolSpecification s IsChecked = specification.ApplicableSymbolKindList.Any(k => k.TypeKind == typeKind); } - internal SymbolOrTypeOrMethodKind CreateSymbolKindOrTypeKind() + public SymbolKindViewModel(MethodKind methodKind, string name, SymbolSpecification specification) { - if (_symbolKind.HasValue) - { - return new SymbolOrTypeOrMethodKind(_symbolKind.Value); - } - else - { - return new SymbolOrTypeOrMethodKind(_typeKind.Value); - } + _methodKind = methodKind; + Name = name; + IsChecked = specification.ApplicableSymbolKindList.Any(k => k.MethodKind == methodKind); + } + + internal SymbolOrTypeOrMethodKind CreateSymbolOrTypeOrMethodKind() + { + return + _symbolKind.HasValue ? new SymbolOrTypeOrMethodKind(_symbolKind.Value) : + _typeKind.HasValue ? new SymbolOrTypeOrMethodKind(_typeKind.Value) : + _methodKind.HasValue ? new SymbolOrTypeOrMethodKind(_methodKind.Value) : + throw ExceptionUtilities.Unreachable; } } From 9d6a970046da1ee1807994f2510461f3dade897a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Sun, 15 Apr 2018 20:39:07 +0200 Subject: [PATCH 07/23] Adding local functions to async naming EditorConfig test --- .../EditorConfigNamingStyleParserTests.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs index 12c31ab517324..ae73ea26fd730 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs @@ -59,14 +59,14 @@ public static void TestPascalCaseRule() } [Fact] - public static void TestAsyncMethodsRule() + public static void TestAsyncMethodsAndLocalFunctionsRule() { var dictionary = new Dictionary() { ["dotnet_naming_rule.async_methods_must_end_with_async.severity"] = "error", ["dotnet_naming_rule.async_methods_must_end_with_async.symbols"] = "method_symbols", ["dotnet_naming_rule.async_methods_must_end_with_async.style"] = "end_in_async_style", - ["dotnet_naming_symbols.method_symbols.applicable_kinds"] = "method", + ["dotnet_naming_symbols.method_symbols.applicable_kinds"] = "method,local_function", ["dotnet_naming_symbols.method_symbols.required_modifiers"] = "async", ["dotnet_naming_style.end_in_async_style.capitalization "] = "pascal_case", ["dotnet_naming_style.end_in_async_style.required_suffix"] = "Async", @@ -82,8 +82,12 @@ public static void TestAsyncMethodsRule() Assert.Equal(symbolSpec.ID, namingRule.SymbolSpecificationID); Assert.Equal(DiagnosticSeverity.Error, namingRule.EnforcementLevel); Assert.Equal("method_symbols", symbolSpec.Name); - Assert.Single(symbolSpec.ApplicableSymbolKindList); - Assert.Contains(new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), symbolSpec.ApplicableSymbolKindList); + var expectedApplicableSymbolKindList = new[] + { + new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), + new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction) + }; + AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); Assert.Single(symbolSpec.RequiredModifierList); Assert.Contains(new ModifierKind(ModifierKindEnum.IsAsync), symbolSpec.RequiredModifierList); Assert.Empty(symbolSpec.ApplicableAccessibilityList); From 531c92ae1f04c49282cb58863ecff8a233ddb4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Sun, 15 Apr 2018 21:09:58 +0200 Subject: [PATCH 08/23] Adding code fix tests for async methods & local functions --- .../NamingStyles/NamingStylesTests.cs | 74 +++++++++++++++++++ .../NamingStylesTestOptionSets.cs | 37 ++++++++++ 2 files changed, 111 insertions(+) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs index 50f12a79b16ce..f1c3af074b646 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs @@ -749,6 +749,80 @@ await TestMissingInRegularAndScriptAsync( }", new TestParameters(options: options.LocalFunctionNamesAreCamelCase)); } + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public async Task TestAsyncFunctions_AsyncMethod() + { + await TestInRegularAndScriptAsync( +@"class C +{ + async void [|M|]() + { + } +}", +@"class C +{ + async void MAsync() + { + } +}", + options: options.AsyncFunctionNamesEndWithAsync); + } + + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public async Task TestAsyncFunctions_AsyncLocalFunction() + { + await TestInRegularAndScriptAsync( +@"class C +{ + void M() + { + async void [|F|]() + { + } + } +}", +@"class C +{ + void M() + { + async void FAsync() + { + } + } +}", + options: options.AsyncFunctionNamesEndWithAsync); + } + + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public async Task TestAsyncFunctions_NonAsyncMethodIgnored() + { + await TestMissingInRegularAndScriptAsync( +@"class C +{ + void [|M|]() + { + async void F() + { + } + } +}", new TestParameters(options: options.AsyncFunctionNamesEndWithAsync)); + } + + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public async Task TestAsyncFunctions_NonAsyncLocalFunctionIgnored() + { + await TestMissingInRegularAndScriptAsync( +@"class C +{ + async void M() + { + void [|F|]() + { + } + } +}", new TestParameters(options: options.AsyncFunctionNamesEndWithAsync)); + } + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] public async Task TestPascalCaseMethod_InInterfaceWithImplicitImplementation() { diff --git a/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs b/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs index 6fd8de7745ce3..f3d08d92cc257 100644 --- a/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs +++ b/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs @@ -46,6 +46,9 @@ public NamingStylesTestOptionSets(string languageName) public IDictionary LocalsAreCamelCaseConstantsAreUpperCase => Options(new OptionKey(SimplificationOptions.NamingPreferences, languageName), LocalsAreCamelCaseConstantsAreUpperCaseOption()); + public IDictionary AsyncFunctionNamesEndWithAsync => + Options(new OptionKey(SimplificationOptions.NamingPreferences, languageName), AsyncFunctionNamesEndWithAsyncOption()); + private static IDictionary Options(OptionKey option, object value) { return new Dictionary @@ -362,5 +365,39 @@ private static NamingStylePreferences LocalsAreCamelCaseConstantsAreUpperCaseOpt return info; } + + private static NamingStylePreferences AsyncFunctionNamesEndWithAsyncOption() + { + var symbolSpecification = new SymbolSpecification( + null, + "Name", + ImmutableArray.Create( + new SymbolSpecification.SymbolOrTypeOrMethodKind(MethodKind.Ordinary), + new SymbolSpecification.SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)), + ImmutableArray.Empty, + ImmutableArray.Create(new SymbolSpecification.ModifierKind(SymbolSpecification.ModifierKindEnum.IsAsync))); + + var namingStyle = new NamingStyle( + Guid.NewGuid(), + capitalizationScheme: Capitalization.PascalCase, + name: "Name", + prefix: "", + suffix: "Async", + wordSeparator: ""); + + var namingRule = new SerializableNamingRule() + { + SymbolSpecificationID = symbolSpecification.ID, + NamingStyleID = namingStyle.ID, + EnforcementLevel = DiagnosticSeverity.Error + }; + + var info = new NamingStylePreferences( + ImmutableArray.Create(symbolSpecification), + ImmutableArray.Create(namingStyle), + ImmutableArray.Create(namingRule)); + + return info; + } } } From 294eb5cb758996a0841d80709c458f6769174e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Mon, 16 Apr 2018 00:05:28 +0200 Subject: [PATCH 09/23] Changing tests --- .../DeclarationNameCompletionProviderTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs index 12ee3afda61a3..f644f39fb19ab 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs @@ -32,8 +32,8 @@ public class MyClass MyClass $$ } "; - await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.MethodPublic); await VerifyItemExistsAsync(markup, "myClass", glyph: (int)Glyph.FieldPublic); + await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.PropertyPublic); await VerifyItemExistsAsync(markup, "GetMyClass", glyph: (int)Glyph.MethodPublic); } @@ -552,7 +552,9 @@ public class MyClass MyClass $$ } "; - await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.MethodPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemExistsAsync(markup, "myClass", glyph: (int)Glyph.FieldPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemExistsAsync(markup, "MyClass", glyph: (int)Glyph.PropertyPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemExistsAsync(markup, "GetMyClass", glyph: (int)Glyph.MethodPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } [WorkItem(20273, "https://github.com/dotnet/roslyn/issues/20273")] From 4bb5b9bbffec576e559cd28e8ff0d7d718e364c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Mon, 16 Apr 2018 02:20:19 +0200 Subject: [PATCH 10/23] Fixing DeclarationNameCompletionProvider to account for local functions --- ...nProviderTests_NameDeclarationInfoTests.cs | 121 +++++++++++++----- ...nNameCompletionProvider.DeclarationInfo.cs | 59 ++++++--- .../DeclarationNameCompletionProvider.cs | 10 +- ...ionNameCompletionProvider_BuiltInStyles.cs | 6 +- 4 files changed, 137 insertions(+), 59 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs index 862705c096d20..787f2b35096b5 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs @@ -7,6 +7,7 @@ using Roslyn.Test.Utilities; using Xunit; using static Microsoft.CodeAnalysis.CSharp.Completion.Providers.DeclarationNameCompletionProvider; +using static Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles.SymbolSpecification; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.DeclarationInfoTests { @@ -24,7 +25,10 @@ class C int $$ } "; - await VerifySymbolKinds(markup, SymbolKind.Field, SymbolKind.Method, SymbolKind.Property); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Field), + new SymbolOrTypeOrMethodKind(SymbolKind.Property), + new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); await VerifyNoModifiers(markup); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -39,7 +43,10 @@ class C public int $$ } "; - await VerifySymbolKinds(markup, SymbolKind.Field, SymbolKind.Method, SymbolKind.Property); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Field), + new SymbolOrTypeOrMethodKind(SymbolKind.Property), + new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); await VerifyNoModifiers(markup); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.Public); @@ -54,7 +61,9 @@ class C public virtual int $$ } "; - await VerifySymbolKinds(markup, SymbolKind.Method, SymbolKind.Property); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Property), + new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); await VerifyModifiers(markup, new DeclarationModifiers(isVirtual: true)); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.Public); @@ -69,7 +78,10 @@ class C private static int $$ } "; - await VerifySymbolKinds(markup, SymbolKind.Field, SymbolKind.Method, SymbolKind.Property); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Field), + new SymbolOrTypeOrMethodKind(SymbolKind.Property), + new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); await VerifyModifiers(markup, new DeclarationModifiers(isStatic: true)); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.Private); @@ -84,7 +96,8 @@ class C private const int $$ } "; - await VerifySymbolKinds(markup, SymbolKind.Field); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Field)); await VerifyModifiers(markup, new DeclarationModifiers(isConst: true)); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.Private); @@ -102,7 +115,9 @@ void goo() } } "; - await VerifySymbolKinds(markup, SymbolKind.Local); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Local), + new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -120,7 +135,8 @@ void goo() } } "; - await VerifySymbolKinds(markup, SymbolKind.Local); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -138,7 +154,9 @@ readonly int $$ } } "; - await VerifySymbolKinds(markup, SymbolKind.Local); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Local), + new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)); await VerifyModifiers(markup, new DeclarationModifiers(isReadOnly: true)); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -156,7 +174,8 @@ void goo() } } "; - await VerifySymbolKinds(markup, SymbolKind.Local); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers(isReadOnly: true)); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -174,7 +193,8 @@ void M() } } "; - await VerifySymbolKinds(markup, SymbolKind.Local); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -192,7 +212,8 @@ void M() } } "; - await VerifySymbolKinds(markup, SymbolKind.Local); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -210,7 +231,8 @@ void M() } } "; - await VerifySymbolKinds(markup, SymbolKind.Local); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -228,7 +250,8 @@ void M() } } "; - await VerifySymbolKinds(markup, SymbolKind.Local); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -246,7 +269,8 @@ void M() } } "; - await VerifySymbolKinds(markup, SymbolKind.Local); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -262,7 +286,8 @@ void goo(C $$ } } "; - await VerifySymbolKinds(markup, SymbolKind.Parameter); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "global::C"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -278,7 +303,8 @@ void goo(C c1, C $$ } } "; - await VerifySymbolKinds(markup, SymbolKind.Parameter); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "global::C"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -294,7 +320,8 @@ void goo(string $$ } } "; - await VerifySymbolKinds(markup, SymbolKind.Parameter); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "string"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -310,7 +337,8 @@ void goo(C c1, string $$ } } "; - await VerifySymbolKinds(markup, SymbolKind.Parameter); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "string"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -327,7 +355,8 @@ void goo(C c1, List $$ } } "; - await VerifySymbolKinds(markup, SymbolKind.Parameter); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "global::System.Collections.Generic.List"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -341,7 +370,8 @@ class C<$$ { } "; - await VerifySymbolKinds(markup, SymbolKind.TypeParameter); + await VerifySymbolKinds(markup, + new SymbolOrTypeOrMethodKind(SymbolKind.TypeParameter)); } [Fact, Trait(Traits.Feature, Traits.Features.Completion)] @@ -352,7 +382,8 @@ class C s_parameterSyntaxKind = ImmutableArray.Create(SymbolKind.Parameter); + private static readonly ImmutableArray s_parameterSyntaxKind = + ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); public NameDeclarationInfo( - ImmutableArray possibleSymbolKinds, + ImmutableArray possibleSymbolKinds, Accessibility accessibility, DeclarationModifiers declarationModifiers, ITypeSymbol type, @@ -32,7 +34,7 @@ public NameDeclarationInfo( Alias = alias; } - public ImmutableArray PossibleSymbolKinds { get; } + public ImmutableArray PossibleSymbolKinds { get; } public DeclarationModifiers Modifiers { get; } public ITypeSymbol Type { get; } public IAliasSymbol Alias { get; } @@ -86,7 +88,7 @@ private static bool IsPossibleOutVariableDeclaration(SyntaxToken token, Semantic if (type != null) { result = new NameDeclarationInfo( - ImmutableArray.Create(SymbolKind.Local), + ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Local)), Accessibility.NotApplicable, new DeclarationModifiers(), type, @@ -106,7 +108,9 @@ private static bool IsPossibleVariableOrLocalMethodDeclaration( token, semanticModel, e => e.Expression, _ => default, - _ => ImmutableArray.Create(SymbolKind.Local), + _ => ImmutableArray.Create( + new SymbolOrTypeOrMethodKind(SymbolKind.Local), + new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)), cancellationToken); return result.Type != null; } @@ -119,7 +123,7 @@ private static bool IsPropertyDeclaration(SyntaxToken token, SemanticModel seman semanticModel, m => m.Type, m => m.Modifiers, - GetPossibleDeclarations, + GetPossibleMemberDeclarations, cancellationToken); return result.Type != null; @@ -133,7 +137,7 @@ private static bool IsMethodDeclaration(SyntaxToken token, SemanticModel semanti semanticModel, m => m.ReturnType, m => m.Modifiers, - GetPossibleDeclarations, + GetPossibleMemberDeclarations, cancellationToken); return result.Type != null; @@ -143,7 +147,7 @@ private static NameDeclarationInfo IsFollowingTypeOrComma(SyntaxTok SemanticModel semanticModel, Func typeSyntaxGetter, Func modifierGetter, - Func> possibleDeclarationComputer, + Func> possibleDeclarationComputer, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode { if (!IsPossibleTypeToken(token) && !token.IsKind(SyntaxKind.CommaToken)) @@ -196,7 +200,7 @@ private static NameDeclarationInfo IsLastTokenOfType( SemanticModel semanticModel, Func typeSyntaxGetter, Func modifierGetter, - Func> possibleDeclarationComputer, + Func> possibleDeclarationComputer, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode { if (!IsPossibleTypeToken(token)) @@ -232,7 +236,7 @@ private static bool IsFieldDeclaration(SyntaxToken token, SemanticModel semantic result = IsFollowingTypeOrComma(token, semanticModel, v => v.Type, v => v.Parent is FieldDeclarationSyntax f ? f.Modifiers : default(SyntaxTokenList?), - GetPossibleDeclarations, + GetPossibleMemberDeclarations, cancellationToken); return result.Type != null; } @@ -243,7 +247,7 @@ private static bool IsIncompleteMemberDeclaration(SyntaxToken token, SemanticMod result = IsLastTokenOfType(token, semanticModel, i => i.Type, i => i.Modifiers, - GetPossibleDeclarations, + GetPossibleMemberDeclarations, cancellationToken); return result.Type != null; } @@ -258,9 +262,20 @@ private static bool IsVariableDeclaration(SyntaxToken token, SemanticModel seman v.Parent is UsingStatementSyntax ? default(SyntaxTokenList) : v.Parent is ForStatementSyntax ? default(SyntaxTokenList) : default(SyntaxTokenList?), // Return null to bail out. - possibleDeclarationComputer: d => ImmutableArray.Create(SymbolKind.Local), + possibleDeclarationComputer: d => GetPossibleKinds(), cancellationToken); return result.Type != null; + + ImmutableArray GetPossibleKinds() + { + // If we only have a type, this can still end up being a local function. + return token.IsKind(SyntaxKind.CommaToken) + ? ImmutableArray.Create( + new SymbolOrTypeOrMethodKind(SymbolKind.Local)) + : ImmutableArray.Create( + new SymbolOrTypeOrMethodKind(SymbolKind.Local), + new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)); + } } private static bool IsForEachVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, @@ -274,7 +289,7 @@ private static bool IsForEachVariableDeclaration(SyntaxToken token, SemanticMode f is ForEachVariableStatementSyntax forEachVariableStatement ? forEachVariableStatement.Variable : null, // Return null to bail out. modifierGetter: f => default, - possibleDeclarationComputer: d => ImmutableArray.Create(SymbolKind.Local), + possibleDeclarationComputer: d => ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Local)), cancellationToken); return result.Type != null; } @@ -286,7 +301,7 @@ private static bool IsTypeParameterDeclaration(SyntaxToken token, SemanticModel token.Parent.IsKind(SyntaxKind.TypeParameterList)) { result = new NameDeclarationInfo( - ImmutableArray.Create(SymbolKind.TypeParameter), + ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.TypeParameter)), Accessibility.NotApplicable, new DeclarationModifiers(), type: null, @@ -353,24 +368,28 @@ private static bool IsPossibleTypeToken(SyntaxToken token) => SyntaxKind.CloseBracketToken) || token.Parent.IsKind(SyntaxKind.PredefinedType); - private static ImmutableArray GetPossibleDeclarations(DeclarationModifiers modifiers) + private static ImmutableArray GetPossibleMemberDeclarations(DeclarationModifiers modifiers) { if (modifiers.IsConst || modifiers.IsReadOnly) { - return ImmutableArray.Create(SymbolKind.Field); + return ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Field)); } - var possibleTypes = ImmutableArray.Create(SymbolKind.Field, SymbolKind.Method, SymbolKind.Property); + var possibleTypes = ImmutableArray.Create( + new SymbolOrTypeOrMethodKind(SymbolKind.Field), + new SymbolOrTypeOrMethodKind(SymbolKind.Property), + new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); + if (modifiers.IsAbstract || modifiers.IsVirtual || modifiers.IsSealed || modifiers.IsOverride) { - possibleTypes = possibleTypes.Remove(SymbolKind.Field); + possibleTypes = possibleTypes.Remove(new SymbolOrTypeOrMethodKind(SymbolKind.Field)); } if (modifiers.IsAsync || modifiers.IsPartial) { // Fields and properties cannot be async or partial. - possibleTypes = possibleTypes.Remove(SymbolKind.Property); - possibleTypes = possibleTypes.Remove(SymbolKind.Field); + possibleTypes = possibleTypes.Remove(new SymbolOrTypeOrMethodKind(SymbolKind.Field)); + possibleTypes = possibleTypes.Remove(new SymbolOrTypeOrMethodKind(SymbolKind.Property)); } return possibleTypes; diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.cs index dc529d133ed9c..1ae1bde92acc1 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.cs @@ -221,9 +221,15 @@ private Glyph GetGlyph(SymbolKind kind, Accessibility declaredAccessibility) var namingStyleOptions = options.GetOption(SimplificationOptions.NamingPreferences); var rules = namingStyleOptions.CreateRules().NamingRules.Concat(s_BuiltInRules); var result = new Dictionary(); - foreach (var symbolKind in declarationInfo.PossibleSymbolKinds) + foreach (var kind in declarationInfo.PossibleSymbolKinds) { - var kind = new SymbolOrTypeOrMethodKind(symbolKind); + // There's no special glyph for local functions. + // We don't need to differentiate them at this point. + var symbolKind = + kind.SymbolKind.HasValue ? kind.SymbolKind.Value : + kind.MethodKind.HasValue ? SymbolKind.Method : + throw ExceptionUtilities.Unreachable; + var modifiers = declarationInfo.Modifiers; foreach (var rule in rules) { diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs index 2e1d3416ffb67..6fe477f52a01d 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs @@ -23,7 +23,7 @@ static DeclarationNameCompletionProvider() private static NamingRule CreateGetAsyncRule() { - var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Method)); + var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); var modifiers = ImmutableArray.Create(new ModifierKind(ModifierKindEnum.IsAsync)); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "endswithasync", kinds, ImmutableArray.Create(), modifiers), @@ -43,7 +43,7 @@ private static NamingRule CreateCamelCaseFieldsAndParametersRule() private static NamingRule CreateEndWithAsyncRule() { - var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Method)); + var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); var modifiers = ImmutableArray.Create(new ModifierKind(ModifierKindEnum.IsAsync)); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "endswithasynct", kinds, ImmutableArray.Create(), modifiers), @@ -53,7 +53,7 @@ private static NamingRule CreateEndWithAsyncRule() private static NamingRule CreateMethodStartsWithGetRule() { - var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Method)); + var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); var modifiers = ImmutableArray.Create(); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "startswithget", kinds, ImmutableArray.Create(), modifiers), From 2d07f569433eebfd5d707a5bd4191c60a1264704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Mon, 16 Apr 2018 14:35:00 +0200 Subject: [PATCH 11/23] Undoing rename --- ...nProviderTests_NameDeclarationInfoTests.cs | 106 +++++++++--------- ...oPropertyToFullPropertyTests_OptionSets.cs | 4 +- .../EditorConfigNamingStyleParserTests.cs | 34 +++--- .../NamingStylesTestOptionSets.cs | 26 ++--- ...nNameCompletionProvider.DeclarationInfo.cs | 46 ++++---- ...ionNameCompletionProvider_BuiltInStyles.cs | 8 +- ...tyToFullPropertyCodeRefactoringProvider.cs | 4 +- ...erCodeRefactoringProviderMemberCreation.cs | 6 +- .../SymbolSpecificationViewModel.cs | 8 +- ...ditorConfigNamingStyleParser_SymbolSpec.cs | 36 +++--- .../Serialization/SymbolSpecification.cs | 74 ++++++------ 11 files changed, 176 insertions(+), 176 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs index 787f2b35096b5..29d1fdd2f03bc 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs @@ -26,9 +26,9 @@ class C } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Field), - new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); + new SymbolKindOrTypeKind(SymbolKind.Field), + new SymbolKindOrTypeKind(SymbolKind.Property), + new SymbolKindOrTypeKind(MethodKind.Ordinary)); await VerifyNoModifiers(markup); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -44,9 +44,9 @@ public int $$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Field), - new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); + new SymbolKindOrTypeKind(SymbolKind.Field), + new SymbolKindOrTypeKind(SymbolKind.Property), + new SymbolKindOrTypeKind(MethodKind.Ordinary)); await VerifyNoModifiers(markup); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.Public); @@ -62,8 +62,8 @@ public virtual int $$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); + new SymbolKindOrTypeKind(SymbolKind.Property), + new SymbolKindOrTypeKind(MethodKind.Ordinary)); await VerifyModifiers(markup, new DeclarationModifiers(isVirtual: true)); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.Public); @@ -79,9 +79,9 @@ private static int $$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Field), - new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); + new SymbolKindOrTypeKind(SymbolKind.Field), + new SymbolKindOrTypeKind(SymbolKind.Property), + new SymbolKindOrTypeKind(MethodKind.Ordinary)); await VerifyModifiers(markup, new DeclarationModifiers(isStatic: true)); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.Private); @@ -97,7 +97,7 @@ private const int $$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Field)); + new SymbolKindOrTypeKind(SymbolKind.Field)); await VerifyModifiers(markup, new DeclarationModifiers(isConst: true)); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.Private); @@ -116,8 +116,8 @@ void goo() } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Local), - new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)); + new SymbolKindOrTypeKind(SymbolKind.Local), + new SymbolKindOrTypeKind(MethodKind.LocalFunction)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -136,7 +136,7 @@ void goo() } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Local)); + new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -155,8 +155,8 @@ readonly int $$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Local), - new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)); + new SymbolKindOrTypeKind(SymbolKind.Local), + new SymbolKindOrTypeKind(MethodKind.LocalFunction)); await VerifyModifiers(markup, new DeclarationModifiers(isReadOnly: true)); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -175,7 +175,7 @@ void goo() } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Local)); + new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers(isReadOnly: true)); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -194,7 +194,7 @@ void M() } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Local)); + new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -213,7 +213,7 @@ void M() } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Local)); + new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -232,7 +232,7 @@ void M() } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Local)); + new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -251,7 +251,7 @@ void M() } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Local)); + new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -270,7 +270,7 @@ void M() } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Local)); + new SymbolKindOrTypeKind(SymbolKind.Local)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "int"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -287,7 +287,7 @@ void goo(C $$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); + new SymbolKindOrTypeKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "global::C"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -304,7 +304,7 @@ void goo(C c1, C $$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); + new SymbolKindOrTypeKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "global::C"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -321,7 +321,7 @@ void goo(string $$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); + new SymbolKindOrTypeKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "string"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -338,7 +338,7 @@ void goo(C c1, string $$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); + new SymbolKindOrTypeKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "string"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -356,7 +356,7 @@ void goo(C c1, List $$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); + new SymbolKindOrTypeKind(SymbolKind.Parameter)); await VerifyModifiers(markup, new DeclarationModifiers()); await VerifyTypeName(markup, "global::System.Collections.Generic.List"); await VerifyAccessibility(markup, Accessibility.NotApplicable); @@ -371,7 +371,7 @@ class C<$$ } "; await VerifySymbolKinds(markup, - new SymbolOrTypeOrMethodKind(SymbolKind.TypeParameter)); + new SymbolKindOrTypeKind(SymbolKind.TypeParameter)); } [Fact, Trait(Traits.Feature, Traits.Features.Completion)] @@ -383,7 +383,7 @@ class C.Empty, ImmutableArray.Empty); @@ -88,7 +88,7 @@ private NamingStylePreferences CreateCustomStaticFieldNamingStylePreference() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Field)), + ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Field)), ImmutableArray.Empty, ImmutableArray.Create(new ModifierKind(DeclarationModifiers.Static))); diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs index ae73ea26fd730..7da4550cf89d6 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/EditorConfigNamingStyleParserTests.cs @@ -37,8 +37,8 @@ public static void TestPascalCaseRule() Assert.Equal("method_and_property_symbols", symbolSpec.Name); var expectedApplicableSymbolKindList = new[] { - new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), - new SymbolOrTypeOrMethodKind(SymbolKind.Property) + new SymbolKindOrTypeKind(MethodKind.Ordinary), + new SymbolKindOrTypeKind(SymbolKind.Property) }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); Assert.Empty(symbolSpec.RequiredModifierList); @@ -84,8 +84,8 @@ public static void TestAsyncMethodsAndLocalFunctionsRule() Assert.Equal("method_symbols", symbolSpec.Name); var expectedApplicableSymbolKindList = new[] { - new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), - new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction) + new SymbolKindOrTypeKind(MethodKind.Ordinary), + new SymbolKindOrTypeKind(MethodKind.LocalFunction) }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); Assert.Single(symbolSpec.RequiredModifierList); @@ -140,11 +140,11 @@ public static void TestPublicMembersCapitalizedRule() Assert.Equal("public_symbols", symbolSpec.Name); var expectedApplicableSymbolKindList = new[] { - new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), - new SymbolOrTypeOrMethodKind(SymbolKind.Field), - new SymbolOrTypeOrMethodKind(SymbolKind.Event), - new SymbolOrTypeOrMethodKind(TypeKind.Delegate) + new SymbolKindOrTypeKind(SymbolKind.Property), + new SymbolKindOrTypeKind(MethodKind.Ordinary), + new SymbolKindOrTypeKind(SymbolKind.Field), + new SymbolKindOrTypeKind(SymbolKind.Event), + new SymbolKindOrTypeKind(TypeKind.Delegate) }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); var expectedApplicableAccessibilityList = new[] @@ -188,11 +188,11 @@ public static void TestNonPublicMembersLowerCaseRule() Assert.Equal("non_public_symbols", symbolSpec.Name); var expectedApplicableSymbolKindList = new[] { - new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), - new SymbolOrTypeOrMethodKind(SymbolKind.Field), - new SymbolOrTypeOrMethodKind(SymbolKind.Event), - new SymbolOrTypeOrMethodKind(TypeKind.Delegate) + new SymbolKindOrTypeKind(SymbolKind.Property), + new SymbolKindOrTypeKind(MethodKind.Ordinary), + new SymbolKindOrTypeKind(SymbolKind.Field), + new SymbolKindOrTypeKind(SymbolKind.Event), + new SymbolKindOrTypeKind(TypeKind.Delegate) }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); Assert.Single(symbolSpec.ApplicableAccessibilityList); @@ -232,8 +232,8 @@ public static void TestParametersAndLocalsAreCamelCaseRule() Assert.Equal("parameters_and_locals", symbolSpec.Name); var expectedApplicableSymbolKindList = new[] { - new SymbolOrTypeOrMethodKind(SymbolKind.Parameter), - new SymbolOrTypeOrMethodKind(SymbolKind.Local), + new SymbolKindOrTypeKind(SymbolKind.Parameter), + new SymbolKindOrTypeKind(SymbolKind.Local), }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); Assert.Empty(symbolSpec.ApplicableAccessibilityList); @@ -271,7 +271,7 @@ public static void TestLocalFunctionsAreCamelCaseRule() Assert.Equal(DiagnosticSeverity.Info, namingRule.EnforcementLevel); Assert.Equal("local_functions", symbolSpec.Name); - var expectedApplicableSymbolKindList = new[] { new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction) }; + var expectedApplicableSymbolKindList = new[] { new SymbolKindOrTypeKind(MethodKind.LocalFunction) }; AssertEx.SetEqual(expectedApplicableSymbolKindList, symbolSpec.ApplicableSymbolKindList); Assert.Empty(symbolSpec.ApplicableAccessibilityList); Assert.Empty(symbolSpec.RequiredModifierList); diff --git a/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs b/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs index f3d08d92cc257..38654e194e18f 100644 --- a/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs +++ b/src/EditorFeatures/TestUtilities/Diagnostics/NamingStyles/NamingStylesTestOptionSets.cs @@ -62,7 +62,7 @@ private static NamingStylePreferences ClassNamesArePascalCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(TypeKind.Class)), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(TypeKind.Class)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -92,7 +92,7 @@ private static NamingStylePreferences MethodNamesArePascalCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(MethodKind.Ordinary)), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(MethodKind.Ordinary)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -123,7 +123,7 @@ private static NamingStylePreferences ParameterNamesAreCamelCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Parameter)), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Parameter)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -155,7 +155,7 @@ private static NamingStylePreferences LocalNamesAreCamelCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Local)), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Local)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -187,7 +187,7 @@ private static NamingStylePreferences LocalFunctionNamesAreCamelCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(MethodKind.LocalFunction)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -219,7 +219,7 @@ private static NamingStylePreferences PropertyNamesArePascalCaseOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Property)), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Property)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -251,7 +251,7 @@ private static NamingStylePreferences InterfacesNamesStartWithIOption() var symbolSpecification = new SymbolSpecification( null, "Name", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(TypeKind.Interface)), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(TypeKind.Interface)), ImmutableArray.Empty, ImmutableArray.Empty); @@ -284,8 +284,8 @@ private static NamingStylePreferences ConstantsAreUpperCaseOption() null, "Name", ImmutableArray.Create( - new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Field), - new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Local)), + new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field), + new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Local)), ImmutableArray.Empty, ImmutableArray.Create(new SymbolSpecification.ModifierKind(SymbolSpecification.ModifierKindEnum.IsConst))); @@ -317,14 +317,14 @@ private static NamingStylePreferences LocalsAreCamelCaseConstantsAreUpperCaseOpt var localsSymbolSpecification = new SymbolSpecification( null, "Locals", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Local)), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Local)), ImmutableArray.Empty, ImmutableArray.Empty); var constLocalsSymbolSpecification = new SymbolSpecification( null, "Const Locals", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Local)), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Local)), ImmutableArray.Empty, ImmutableArray.Create(new SymbolSpecification.ModifierKind(SymbolSpecification.ModifierKindEnum.IsConst))); @@ -372,8 +372,8 @@ private static NamingStylePreferences AsyncFunctionNamesEndWithAsyncOption() null, "Name", ImmutableArray.Create( - new SymbolSpecification.SymbolOrTypeOrMethodKind(MethodKind.Ordinary), - new SymbolSpecification.SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)), + new SymbolSpecification.SymbolKindOrTypeKind(MethodKind.Ordinary), + new SymbolSpecification.SymbolKindOrTypeKind(MethodKind.LocalFunction)), ImmutableArray.Empty, ImmutableArray.Create(new SymbolSpecification.ModifierKind(SymbolSpecification.ModifierKindEnum.IsAsync))); diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs index f8d0e53544212..9314581a023d3 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs @@ -17,11 +17,11 @@ internal partial class DeclarationNameCompletionProvider { internal struct NameDeclarationInfo { - private static readonly ImmutableArray s_parameterSyntaxKind = - ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Parameter)); + private static readonly ImmutableArray s_parameterSyntaxKind = + ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Parameter)); public NameDeclarationInfo( - ImmutableArray possibleSymbolKinds, + ImmutableArray possibleSymbolKinds, Accessibility accessibility, DeclarationModifiers declarationModifiers, ITypeSymbol type, @@ -34,7 +34,7 @@ public NameDeclarationInfo( Alias = alias; } - public ImmutableArray PossibleSymbolKinds { get; } + public ImmutableArray PossibleSymbolKinds { get; } public DeclarationModifiers Modifiers { get; } public ITypeSymbol Type { get; } public IAliasSymbol Alias { get; } @@ -88,7 +88,7 @@ private static bool IsPossibleOutVariableDeclaration(SyntaxToken token, Semantic if (type != null) { result = new NameDeclarationInfo( - ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Local)), + ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)), Accessibility.NotApplicable, new DeclarationModifiers(), type, @@ -109,8 +109,8 @@ private static bool IsPossibleVariableOrLocalMethodDeclaration( e => e.Expression, _ => default, _ => ImmutableArray.Create( - new SymbolOrTypeOrMethodKind(SymbolKind.Local), - new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)), + new SymbolKindOrTypeKind(SymbolKind.Local), + new SymbolKindOrTypeKind(MethodKind.LocalFunction)), cancellationToken); return result.Type != null; } @@ -147,7 +147,7 @@ private static NameDeclarationInfo IsFollowingTypeOrComma(SyntaxTok SemanticModel semanticModel, Func typeSyntaxGetter, Func modifierGetter, - Func> possibleDeclarationComputer, + Func> possibleDeclarationComputer, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode { if (!IsPossibleTypeToken(token) && !token.IsKind(SyntaxKind.CommaToken)) @@ -200,7 +200,7 @@ private static NameDeclarationInfo IsLastTokenOfType( SemanticModel semanticModel, Func typeSyntaxGetter, Func modifierGetter, - Func> possibleDeclarationComputer, + Func> possibleDeclarationComputer, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode { if (!IsPossibleTypeToken(token)) @@ -266,15 +266,15 @@ private static bool IsVariableDeclaration(SyntaxToken token, SemanticModel seman cancellationToken); return result.Type != null; - ImmutableArray GetPossibleKinds() + ImmutableArray GetPossibleKinds() { // If we only have a type, this can still end up being a local function. return token.IsKind(SyntaxKind.CommaToken) ? ImmutableArray.Create( - new SymbolOrTypeOrMethodKind(SymbolKind.Local)) + new SymbolKindOrTypeKind(SymbolKind.Local)) : ImmutableArray.Create( - new SymbolOrTypeOrMethodKind(SymbolKind.Local), - new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction)); + new SymbolKindOrTypeKind(SymbolKind.Local), + new SymbolKindOrTypeKind(MethodKind.LocalFunction)); } } @@ -289,7 +289,7 @@ private static bool IsForEachVariableDeclaration(SyntaxToken token, SemanticMode f is ForEachVariableStatementSyntax forEachVariableStatement ? forEachVariableStatement.Variable : null, // Return null to bail out. modifierGetter: f => default, - possibleDeclarationComputer: d => ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Local)), + possibleDeclarationComputer: d => ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)), cancellationToken); return result.Type != null; } @@ -301,7 +301,7 @@ private static bool IsTypeParameterDeclaration(SyntaxToken token, SemanticModel token.Parent.IsKind(SyntaxKind.TypeParameterList)) { result = new NameDeclarationInfo( - ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.TypeParameter)), + ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.TypeParameter)), Accessibility.NotApplicable, new DeclarationModifiers(), type: null, @@ -368,28 +368,28 @@ private static bool IsPossibleTypeToken(SyntaxToken token) => SyntaxKind.CloseBracketToken) || token.Parent.IsKind(SyntaxKind.PredefinedType); - private static ImmutableArray GetPossibleMemberDeclarations(DeclarationModifiers modifiers) + private static ImmutableArray GetPossibleMemberDeclarations(DeclarationModifiers modifiers) { if (modifiers.IsConst || modifiers.IsReadOnly) { - return ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Field)); + return ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Field)); } var possibleTypes = ImmutableArray.Create( - new SymbolOrTypeOrMethodKind(SymbolKind.Field), - new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); + new SymbolKindOrTypeKind(SymbolKind.Field), + new SymbolKindOrTypeKind(SymbolKind.Property), + new SymbolKindOrTypeKind(MethodKind.Ordinary)); if (modifiers.IsAbstract || modifiers.IsVirtual || modifiers.IsSealed || modifiers.IsOverride) { - possibleTypes = possibleTypes.Remove(new SymbolOrTypeOrMethodKind(SymbolKind.Field)); + possibleTypes = possibleTypes.Remove(new SymbolKindOrTypeKind(SymbolKind.Field)); } if (modifiers.IsAsync || modifiers.IsPartial) { // Fields and properties cannot be async or partial. - possibleTypes = possibleTypes.Remove(new SymbolOrTypeOrMethodKind(SymbolKind.Field)); - possibleTypes = possibleTypes.Remove(new SymbolOrTypeOrMethodKind(SymbolKind.Property)); + possibleTypes = possibleTypes.Remove(new SymbolKindOrTypeKind(SymbolKind.Field)); + possibleTypes = possibleTypes.Remove(new SymbolKindOrTypeKind(SymbolKind.Property)); } return possibleTypes; diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs index 6fe477f52a01d..4f30effdd734f 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider_BuiltInStyles.cs @@ -23,7 +23,7 @@ static DeclarationNameCompletionProvider() private static NamingRule CreateGetAsyncRule() { - var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); + var kinds = ImmutableArray.Create(new SymbolKindOrTypeKind(MethodKind.Ordinary)); var modifiers = ImmutableArray.Create(new ModifierKind(ModifierKindEnum.IsAsync)); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "endswithasync", kinds, ImmutableArray.Create(), modifiers), @@ -33,7 +33,7 @@ private static NamingRule CreateGetAsyncRule() private static NamingRule CreateCamelCaseFieldsAndParametersRule() { - var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(SymbolKind.Field), new SymbolOrTypeOrMethodKind(SymbolKind.Parameter), new SymbolOrTypeOrMethodKind(SymbolKind.Local)); + var kinds = ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Field), new SymbolKindOrTypeKind(SymbolKind.Parameter), new SymbolKindOrTypeKind(SymbolKind.Local)); var modifiers = ImmutableArray.Create(); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "camelcasefields", kinds, ImmutableArray.Create(), modifiers), @@ -43,7 +43,7 @@ private static NamingRule CreateCamelCaseFieldsAndParametersRule() private static NamingRule CreateEndWithAsyncRule() { - var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); + var kinds = ImmutableArray.Create(new SymbolKindOrTypeKind(MethodKind.Ordinary)); var modifiers = ImmutableArray.Create(new ModifierKind(ModifierKindEnum.IsAsync)); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "endswithasynct", kinds, ImmutableArray.Create(), modifiers), @@ -53,7 +53,7 @@ private static NamingRule CreateEndWithAsyncRule() private static NamingRule CreateMethodStartsWithGetRule() { - var kinds = ImmutableArray.Create(new SymbolOrTypeOrMethodKind(MethodKind.Ordinary)); + var kinds = ImmutableArray.Create(new SymbolKindOrTypeKind(MethodKind.Ordinary)); var modifiers = ImmutableArray.Create(); return new NamingRule( new SymbolSpecification(Guid.NewGuid(), "startswithget", kinds, ImmutableArray.Create(), modifiers), diff --git a/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs b/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs index d83d448143281..1ec35406a13b6 100644 --- a/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs +++ b/src/Features/CSharp/Portable/ConvertAutoPropertyToFullProperty/CSharpConvertAutoPropertyToFullPropertyCodeRefactoringProvider.cs @@ -87,7 +87,7 @@ private static ImmutableArray CreateNewRule( new SymbolSpecification( Guid.NewGuid(), "Field", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Field)), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field)), modifiers: modifiers), new NamingStyles.NamingStyle( Guid.NewGuid(), @@ -103,7 +103,7 @@ private string GenerateFieldName(IPropertySymbol property, ImmutableArray s_builtInRules = ImmutableArray.Create( new NamingRule(new SymbolSpecification( Guid.NewGuid(), "Property", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Property))), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Property))), new NamingStyles.NamingStyle(Guid.NewGuid(), capitalizationScheme: Capitalization.PascalCase), enforcementLevel: DiagnosticSeverity.Hidden), new NamingRule(new SymbolSpecification( Guid.NewGuid(), "Field", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Field))), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field))), new NamingStyles.NamingStyle(Guid.NewGuid(), capitalizationScheme: Capitalization.CamelCase), enforcementLevel: DiagnosticSeverity.Hidden), new NamingRule(new SymbolSpecification( Guid.NewGuid(), "FieldWithUnderscore", - ImmutableArray.Create(new SymbolSpecification.SymbolOrTypeOrMethodKind(SymbolKind.Field))), + ImmutableArray.Create(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Field))), new NamingStyles.NamingStyle(Guid.NewGuid(), prefix: "_", capitalizationScheme: Capitalization.CamelCase), enforcementLevel: DiagnosticSeverity.Hidden)); diff --git a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs index 475ad89c97277..4070c17f9adcc 100644 --- a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs +++ b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/SymbolSpecification/SymbolSpecificationViewModel.cs @@ -192,12 +192,12 @@ public SymbolKindViewModel(MethodKind methodKind, string name, SymbolSpecificati IsChecked = specification.ApplicableSymbolKindList.Any(k => k.MethodKind == methodKind); } - internal SymbolOrTypeOrMethodKind CreateSymbolOrTypeOrMethodKind() + internal SymbolKindOrTypeKind CreateSymbolOrTypeOrMethodKind() { return - _symbolKind.HasValue ? new SymbolOrTypeOrMethodKind(_symbolKind.Value) : - _typeKind.HasValue ? new SymbolOrTypeOrMethodKind(_typeKind.Value) : - _methodKind.HasValue ? new SymbolOrTypeOrMethodKind(_methodKind.Value) : + _symbolKind.HasValue ? new SymbolKindOrTypeKind(_symbolKind.Value) : + _typeKind.HasValue ? new SymbolKindOrTypeKind(_typeKind.Value) : + _methodKind.HasValue ? new SymbolKindOrTypeKind(_methodKind.Value) : throw ExceptionUtilities.Unreachable; } } diff --git a/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs b/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs index f928256d0b94b..85bccee13b2de 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/EditorConfig/EditorConfigNamingStyleParser_SymbolSpec.cs @@ -50,7 +50,7 @@ private static bool TryGetSymbolSpecNameForNamingRule( return false; } - private static ImmutableArray GetSymbolsApplicableKinds( + private static ImmutableArray GetSymbolsApplicableKinds( string symbolSpecName, IReadOnlyDictionary conventionsDictionary) { @@ -59,22 +59,22 @@ private static ImmutableArray GetSymbolsApplicableKind return ParseSymbolKindList(result as string ?? string.Empty); } - return ImmutableArray.Empty; + return ImmutableArray.Empty; } - private static readonly SymbolOrTypeOrMethodKind _class = new SymbolOrTypeOrMethodKind(TypeKind.Class); - private static readonly SymbolOrTypeOrMethodKind _struct = new SymbolOrTypeOrMethodKind(TypeKind.Struct); - private static readonly SymbolOrTypeOrMethodKind _interface = new SymbolOrTypeOrMethodKind(TypeKind.Interface); - private static readonly SymbolOrTypeOrMethodKind _enum = new SymbolOrTypeOrMethodKind(TypeKind.Enum); - private static readonly SymbolOrTypeOrMethodKind _property = new SymbolOrTypeOrMethodKind(SymbolKind.Property); - private static readonly SymbolOrTypeOrMethodKind _method = new SymbolOrTypeOrMethodKind(MethodKind.Ordinary); - private static readonly SymbolOrTypeOrMethodKind _localFunction = new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction); - private static readonly SymbolOrTypeOrMethodKind _field = new SymbolOrTypeOrMethodKind(SymbolKind.Field); - private static readonly SymbolOrTypeOrMethodKind _event = new SymbolOrTypeOrMethodKind(SymbolKind.Event); - private static readonly SymbolOrTypeOrMethodKind _delegate = new SymbolOrTypeOrMethodKind(TypeKind.Delegate); - private static readonly SymbolOrTypeOrMethodKind _parameter = new SymbolOrTypeOrMethodKind(SymbolKind.Parameter); - private static readonly SymbolOrTypeOrMethodKind _local = new SymbolOrTypeOrMethodKind(SymbolKind.Local); - private static readonly ImmutableArray _all = + private static readonly SymbolKindOrTypeKind _class = new SymbolKindOrTypeKind(TypeKind.Class); + private static readonly SymbolKindOrTypeKind _struct = new SymbolKindOrTypeKind(TypeKind.Struct); + private static readonly SymbolKindOrTypeKind _interface = new SymbolKindOrTypeKind(TypeKind.Interface); + private static readonly SymbolKindOrTypeKind _enum = new SymbolKindOrTypeKind(TypeKind.Enum); + private static readonly SymbolKindOrTypeKind _property = new SymbolKindOrTypeKind(SymbolKind.Property); + private static readonly SymbolKindOrTypeKind _method = new SymbolKindOrTypeKind(MethodKind.Ordinary); + private static readonly SymbolKindOrTypeKind _localFunction = new SymbolKindOrTypeKind(MethodKind.LocalFunction); + private static readonly SymbolKindOrTypeKind _field = new SymbolKindOrTypeKind(SymbolKind.Field); + private static readonly SymbolKindOrTypeKind _event = new SymbolKindOrTypeKind(SymbolKind.Event); + private static readonly SymbolKindOrTypeKind _delegate = new SymbolKindOrTypeKind(TypeKind.Delegate); + private static readonly SymbolKindOrTypeKind _parameter = new SymbolKindOrTypeKind(SymbolKind.Parameter); + private static readonly SymbolKindOrTypeKind _local = new SymbolKindOrTypeKind(SymbolKind.Local); + private static readonly ImmutableArray _all = ImmutableArray.Create( _class, _struct, @@ -89,11 +89,11 @@ private static ImmutableArray GetSymbolsApplicableKind _parameter, _local); - private static ImmutableArray ParseSymbolKindList(string symbolSpecApplicableKinds) + private static ImmutableArray ParseSymbolKindList(string symbolSpecApplicableKinds) { if (symbolSpecApplicableKinds == null) { - return ImmutableArray.Empty; + return ImmutableArray.Empty; } if (symbolSpecApplicableKinds.Trim() == "*") @@ -101,7 +101,7 @@ private static ImmutableArray ParseSymbolKindList(stri return _all; } - var builder = ArrayBuilder.GetInstance(); + var builder = ArrayBuilder.GetInstance(); foreach (var symbolSpecApplicableKind in symbolSpecApplicableKinds.Split(',').Select(x => x.Trim())) { switch (symbolSpecApplicableKind) diff --git a/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs b/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs index b0c51f11a73e4..dd40ff649f307 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/Serialization/SymbolSpecification.cs @@ -17,13 +17,13 @@ internal class SymbolSpecification public Guid ID { get; } public string Name { get; } - public ImmutableArray ApplicableSymbolKindList { get; } + public ImmutableArray ApplicableSymbolKindList { get; } public ImmutableArray ApplicableAccessibilityList { get; } public ImmutableArray RequiredModifierList { get; } public SymbolSpecification( Guid? id, string symbolSpecName, - ImmutableArray symbolKindList, + ImmutableArray symbolKindList, ImmutableArray accessibilityList = default, ImmutableArray modifiers = default) { @@ -44,22 +44,22 @@ public static SymbolSpecification CreateDefaultSymbolSpecification() id: Guid.NewGuid(), symbolSpecName: null, symbolKindList: ImmutableArray.Create( - new SymbolOrTypeOrMethodKind(SymbolKind.Namespace), - new SymbolOrTypeOrMethodKind(TypeKind.Class), - new SymbolOrTypeOrMethodKind(TypeKind.Struct), - new SymbolOrTypeOrMethodKind(TypeKind.Interface), - new SymbolOrTypeOrMethodKind(TypeKind.Delegate), - new SymbolOrTypeOrMethodKind(TypeKind.Enum), - new SymbolOrTypeOrMethodKind(TypeKind.Module), - new SymbolOrTypeOrMethodKind(TypeKind.Pointer), - new SymbolOrTypeOrMethodKind(TypeKind.TypeParameter), - new SymbolOrTypeOrMethodKind(SymbolKind.Property), - new SymbolOrTypeOrMethodKind(MethodKind.Ordinary), - new SymbolOrTypeOrMethodKind(MethodKind.LocalFunction), - new SymbolOrTypeOrMethodKind(SymbolKind.Field), - new SymbolOrTypeOrMethodKind(SymbolKind.Event), - new SymbolOrTypeOrMethodKind(SymbolKind.Parameter), - new SymbolOrTypeOrMethodKind(SymbolKind.Local)), + new SymbolKindOrTypeKind(SymbolKind.Namespace), + new SymbolKindOrTypeKind(TypeKind.Class), + new SymbolKindOrTypeKind(TypeKind.Struct), + new SymbolKindOrTypeKind(TypeKind.Interface), + new SymbolKindOrTypeKind(TypeKind.Delegate), + new SymbolKindOrTypeKind(TypeKind.Enum), + new SymbolKindOrTypeKind(TypeKind.Module), + new SymbolKindOrTypeKind(TypeKind.Pointer), + new SymbolKindOrTypeKind(TypeKind.TypeParameter), + new SymbolKindOrTypeKind(SymbolKind.Property), + new SymbolKindOrTypeKind(MethodKind.Ordinary), + new SymbolKindOrTypeKind(MethodKind.LocalFunction), + new SymbolKindOrTypeKind(SymbolKind.Field), + new SymbolKindOrTypeKind(SymbolKind.Event), + new SymbolKindOrTypeKind(SymbolKind.Parameter), + new SymbolKindOrTypeKind(SymbolKind.Local)), accessibilityList: ImmutableArray.Create( Accessibility.Public, Accessibility.Internal, @@ -78,9 +78,9 @@ internal bool AppliesTo(ISymbol symbol) } internal bool AppliesTo(SymbolKind symbolKind, Accessibility accessibility) - => this.AppliesTo(new SymbolOrTypeOrMethodKind(symbolKind), new DeclarationModifiers(), accessibility); + => this.AppliesTo(new SymbolKindOrTypeKind(symbolKind), new DeclarationModifiers(), accessibility); - internal bool AppliesTo(SymbolOrTypeOrMethodKind kind, DeclarationModifiers modifiers, Accessibility accessibility) + internal bool AppliesTo(SymbolKindOrTypeKind kind, DeclarationModifiers modifiers, Accessibility accessibility) { if (ApplicableSymbolKindList.Any() && !ApplicableSymbolKindList.Any(k => k.Equals(kind))) { @@ -240,22 +240,22 @@ internal static SymbolSpecification FromXElement(XElement symbolSpecificationEle accessibilityList: GetAccessibilityListFromXElement(symbolSpecificationElement.Element(nameof(ApplicableAccessibilityList))), modifiers: GetModifierListFromXElement(symbolSpecificationElement.Element(nameof(RequiredModifierList)))); - private static ImmutableArray GetSymbolKindListFromXElement(XElement symbolKindListElement) + private static ImmutableArray GetSymbolKindListFromXElement(XElement symbolKindListElement) { - var applicableSymbolKindList = ArrayBuilder.GetInstance(); + var applicableSymbolKindList = ArrayBuilder.GetInstance(); foreach (var symbolKindElement in symbolKindListElement.Elements(nameof(SymbolKind))) { - applicableSymbolKindList.Add(SymbolOrTypeOrMethodKind.AddSymbolKindFromXElement(symbolKindElement)); + applicableSymbolKindList.Add(SymbolKindOrTypeKind.AddSymbolKindFromXElement(symbolKindElement)); } foreach (var typeKindElement in symbolKindListElement.Elements(nameof(TypeKind))) { - applicableSymbolKindList.Add(SymbolOrTypeOrMethodKind.AddTypeKindFromXElement(typeKindElement)); + applicableSymbolKindList.Add(SymbolKindOrTypeKind.AddTypeKindFromXElement(typeKindElement)); } foreach (var methodKindElement in symbolKindListElement.Elements(nameof(MethodKind))) { - applicableSymbolKindList.Add(SymbolOrTypeOrMethodKind.AddMethodKindFromXElement(methodKindElement)); + applicableSymbolKindList.Add(SymbolKindOrTypeKind.AddMethodKindFromXElement(methodKindElement)); } return applicableSymbolKindList.ToImmutableAndFree(); @@ -287,27 +287,27 @@ private interface ISymbolMatcher bool MatchesSymbol(ISymbol symbol); } - public struct SymbolOrTypeOrMethodKind : IEquatable, ISymbolMatcher + public struct SymbolKindOrTypeKind : IEquatable, ISymbolMatcher { public SymbolKind? SymbolKind { get; } public TypeKind? TypeKind { get; } public MethodKind? MethodKind { get; } - public SymbolOrTypeOrMethodKind(SymbolKind symbolKind) : this() + public SymbolKindOrTypeKind(SymbolKind symbolKind) : this() { SymbolKind = symbolKind; TypeKind = null; MethodKind = null; } - public SymbolOrTypeOrMethodKind(TypeKind typeKind) : this() + public SymbolKindOrTypeKind(TypeKind typeKind) : this() { SymbolKind = null; TypeKind = typeKind; MethodKind = null; } - public SymbolOrTypeOrMethodKind(MethodKind methodKind) : this() + public SymbolKindOrTypeKind(MethodKind methodKind) : this() { SymbolKind = null; TypeKind = null; @@ -326,19 +326,19 @@ internal XElement CreateXElement() MethodKind.HasValue ? new XElement(nameof(MethodKind), MethodKind) : throw ExceptionUtilities.Unreachable; - internal static SymbolOrTypeOrMethodKind AddSymbolKindFromXElement(XElement symbolKindElement) - => new SymbolOrTypeOrMethodKind((SymbolKind)Enum.Parse(typeof(SymbolKind), symbolKindElement.Value)); + internal static SymbolKindOrTypeKind AddSymbolKindFromXElement(XElement symbolKindElement) + => new SymbolKindOrTypeKind((SymbolKind)Enum.Parse(typeof(SymbolKind), symbolKindElement.Value)); - internal static SymbolOrTypeOrMethodKind AddTypeKindFromXElement(XElement typeKindElement) - => new SymbolOrTypeOrMethodKind((TypeKind)Enum.Parse(typeof(TypeKind), typeKindElement.Value)); + internal static SymbolKindOrTypeKind AddTypeKindFromXElement(XElement typeKindElement) + => new SymbolKindOrTypeKind((TypeKind)Enum.Parse(typeof(TypeKind), typeKindElement.Value)); - internal static SymbolOrTypeOrMethodKind AddMethodKindFromXElement(XElement methodKindElement) - => new SymbolOrTypeOrMethodKind((MethodKind)Enum.Parse(typeof(MethodKind), methodKindElement.Value)); + internal static SymbolKindOrTypeKind AddMethodKindFromXElement(XElement methodKindElement) + => new SymbolKindOrTypeKind((MethodKind)Enum.Parse(typeof(MethodKind), methodKindElement.Value)); public override bool Equals(object obj) - => Equals((SymbolOrTypeOrMethodKind)obj); + => Equals((SymbolKindOrTypeKind)obj); - public bool Equals(SymbolOrTypeOrMethodKind other) + public bool Equals(SymbolKindOrTypeKind other) => this.SymbolKind == other.SymbolKind && this.TypeKind == other.TypeKind && this.MethodKind == other.MethodKind; public override int GetHashCode() From d3796947359a699e5572d86f28efce35e832696e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Mon, 16 Apr 2018 17:22:19 +0200 Subject: [PATCH 12/23] Adding tests for custom naming style to DeclarationNameCompletionProvider --- .../DeclarationNameCompletionProviderTests.cs | 143 +++++++++++++++++- 1 file changed, 140 insertions(+), 3 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs index f644f39fb19ab..ea00afcfc0868 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs @@ -1,14 +1,22 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Collections.Immutable; +using System.Linq; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Completion; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Completion.Providers; +using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders; using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces; +using Microsoft.CodeAnalysis.NamingStyles; +using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.Simplification; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Xunit; +using static Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles.SymbolSpecification; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionSetSources { @@ -259,7 +267,7 @@ void goo() [WorkItem(25214, "https://github.com/dotnet/roslyn/issues/25214")] [Fact, Trait(Traits.Feature, Traits.Features.Completion)] - public async void TypeImplementsLazyOfType1() + public async Task TypeImplementsLazyOfType1() { var markup = @" using System; @@ -279,7 +287,7 @@ public class Item { } [WorkItem(25214, "https://github.com/dotnet/roslyn/issues/25214")] [Fact, Trait(Traits.Feature, Traits.Features.Completion)] - public async void TypeImplementsLazyOfType2() + public async Task TypeImplementsLazyOfType2() { var markup = @" using System; @@ -544,7 +552,7 @@ void goo() } [Fact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestDescription() + public async Task TestDescriptionInsideClass() { var markup = @" public class MyClass @@ -557,6 +565,23 @@ public class MyClass await VerifyItemExistsAsync(markup, "GetMyClass", glyph: (int)Glyph.MethodPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); } + [Fact, Trait(Traits.Feature, Traits.Features.Completion)] + public async Task TestDescriptionInsideMethod() + { + var markup = @" +public class MyClass +{ + void M() + { + MyClass $$ + } +} +"; + await VerifyItemExistsAsync(markup, "myClass", glyph: (int)Glyph.Local, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemIsAbsentAsync(markup, "MyClass"); + await VerifyItemIsAbsentAsync(markup, "GetMyClass"); + } + [WorkItem(20273, "https://github.com/dotnet/roslyn/issues/20273")] [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task Alias1() @@ -1201,5 +1226,117 @@ public void Method() "; await VerifyItemExistsAsync(markup, "nullables"); } + + [Fact, Trait(Traits.Feature, Traits.Features.Completion)] + public async Task CustomNamingStyleInsideClass() + { + var workspace = WorkspaceFixture.GetWorkspace(); + var originalOptions = workspace.Options; + + try + { + workspace.Options = workspace.Options.WithChangedOption( + new OptionKey(SimplificationOptions.NamingPreferences, LanguageNames.CSharp), + NamesEndWithSuffixPreferences()); + + var markup = @" +class Configuration +{ + Configuration $$ +} +"; + await VerifyItemExistsAsync(markup, "ConfigurationField", glyph: (int)Glyph.FieldPublic, + expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemExistsAsync(markup, "ConfigurationProperty", glyph: (int)Glyph.PropertyPublic, + expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemExistsAsync(markup, "ConfigurationMethod", glyph: (int)Glyph.MethodPublic, + expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemIsAbsentAsync(markup, "ConfigurationLocalFunction"); + } + finally + { + workspace.Options = originalOptions; + } + } + + [Fact, Trait(Traits.Feature, Traits.Features.Completion)] + public async Task CustomNamingStyleInsideMethod() + { + var workspace = WorkspaceFixture.GetWorkspace(); + var originalOptions = workspace.Options; + + try + { + workspace.Options = workspace.Options.WithChangedOption( + new OptionKey(SimplificationOptions.NamingPreferences, LanguageNames.CSharp), + NamesEndWithSuffixPreferences()); + + var markup = @" +class Configuration +{ + void M() + { + Configuration $$ + } +} +"; + // We don't support naming preferences for locals... yet. + await VerifyItemExistsAsync(markup, "ConfigurationLocalFunction", glyph: (int)Glyph.MethodPublic, + expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemIsAbsentAsync(markup, "ConfigurationField"); + await VerifyItemIsAbsentAsync(markup, "ConfigurationMethod"); + await VerifyItemIsAbsentAsync(markup, "ConfigurationProperty"); + } + finally + { + workspace.Options = originalOptions; + } + } + + private static NamingStylePreferences NamesEndWithSuffixPreferences() + { + var specificationStyles = new[] + { + SpecificationStyle(new SymbolKindOrTypeKind(SymbolKind.Field), "Field"), + SpecificationStyle(new SymbolKindOrTypeKind(SymbolKind.Property), "Property"), + SpecificationStyle(new SymbolKindOrTypeKind(MethodKind.Ordinary), "Method"), + SpecificationStyle(new SymbolKindOrTypeKind(MethodKind.LocalFunction), "LocalFunction"), + }; + + return new NamingStylePreferences( + specificationStyles.Select(t => t.specification).ToImmutableArray(), + specificationStyles.Select(t => t.style).ToImmutableArray(), + specificationStyles.Select(t => CreateRule(t.specification, t.style)).ToImmutableArray()); + + (SymbolSpecification specification, NamingStyle style) SpecificationStyle(SymbolKindOrTypeKind kind, string suffix) + { + var symbolSpecification = new SymbolSpecification( + id: null, + symbolSpecName: suffix, + ImmutableArray.Create(kind), + ImmutableArray.Empty, + ImmutableArray.Empty); + + var namingStyle = new NamingStyle( + Guid.NewGuid(), + name: suffix, + capitalizationScheme: Capitalization.PascalCase, + prefix: "", + suffix: suffix, + wordSeparator: ""); + + return (symbolSpecification, namingStyle); + } + + SerializableNamingRule CreateRule(SymbolSpecification specification, NamingStyle style) + { + return new SerializableNamingRule() + { + SymbolSpecificationID = specification.ID, + NamingStyleID = style.ID, + EnforcementLevel = DiagnosticSeverity.Error + }; + } + } } } From a13fed92fd7de48933c14a319258b397c1501b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Tue, 17 Apr 2018 01:40:07 +0200 Subject: [PATCH 13/23] Adding upgrade path for naming preferences --- .../Serialization/NamingStylePreferences.cs | 42 +++++- .../NamingStylePreferencesUpgradeTests.cs | 141 ++++++++++++++++++ 2 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 src/Workspaces/CoreTest/CodeStyle/NamingStylePreferencesUpgradeTests.cs diff --git a/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs b/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs index 6e46530e7b7a5..e5d4a6302e0e2 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Immutable; +using System.Diagnostics; using System.Linq; using System.Xml.Linq; using Microsoft.CodeAnalysis.NamingStyles; @@ -62,11 +63,7 @@ internal XElement CreateXElement() internal static NamingStylePreferences FromXElement(XElement element) { - var serializationVersion = int.Parse(element.Attribute("SerializationVersion").Value); - if (serializationVersion != s_serializationVersion) - { - element = XElement.Parse(DefaultNamingPreferencesString); - } + element = GetUpgradedSerializationIfNecessary(element); return new NamingStylePreferences( element.Element(nameof(SymbolSpecifications)).Elements(nameof(SymbolSpecification)) @@ -108,7 +105,7 @@ public override int GetHashCode() => CreateXElement().ToString().GetHashCode(); private static readonly string _defaultNamingPreferencesString = $@" - + @@ -315,8 +312,8 @@ public override int GetHashCode() Property - Ordinary Event + Ordinary Public @@ -339,5 +336,36 @@ public override int GetHashCode() "; + + private static XElement GetUpgradedSerializationIfNecessary(XElement rootElement) + { + var serializationVersion = int.Parse(rootElement.Attribute("SerializationVersion").Value); + + if (serializationVersion == 4) + { + UpgradeSerialization_4To5(rootElement = new XElement(rootElement)); + serializationVersion = 5; + } + + // Add future version checks here. If the version is off by more than 1, these upgrades will run in sequence. + // The next one should check serializationVersion == 5 and update it to 6. + Debug.Assert(s_serializationVersion == 5, "After increasing the serialization version, add an upgrade path here."); + + return serializationVersion == s_serializationVersion + ? rootElement + : XElement.Parse(DefaultNamingPreferencesString); + } + + private static void UpgradeSerialization_4To5(XElement rootElement) + { + var methodElements = rootElement + .Descendants() + .Where(e => e.Name.LocalName == "SymbolKind" && e.Value == "Method").ToList(); + + foreach (var element in methodElements) + { + element.ReplaceWith(XElement.Parse("Ordinary")); + } + } } } diff --git a/src/Workspaces/CoreTest/CodeStyle/NamingStylePreferencesUpgradeTests.cs b/src/Workspaces/CoreTest/CodeStyle/NamingStylePreferencesUpgradeTests.cs new file mode 100644 index 0000000000000..dee87178fae6b --- /dev/null +++ b/src/Workspaces/CoreTest/CodeStyle/NamingStylePreferencesUpgradeTests.cs @@ -0,0 +1,141 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Xml.Linq; +using Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles; +using Microsoft.CodeAnalysis.Test.Utilities; +using Xunit; + +namespace Microsoft.CodeAnalysis.UnitTests.CodeStyle +{ + public class NamingStylePreferencesUpgradeTests + { + private static string ReserializePreferences(string serializedPreferences) + { + var preferences = NamingStylePreferences.FromXElement(XElement.Parse(serializedPreferences)); + return preferences.CreateXElement().ToString(); + } + + private static void AssertTrimmedEqual(string expected, string actual) + { + Assert.Equal(expected.Trim(), actual.Trim()); + } + + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public void TestPreserveDefaultPreferences() + { + AssertTrimmedEqual( + NamingStylePreferences.DefaultNamingPreferencesString, + ReserializePreferences(NamingStylePreferences.DefaultNamingPreferencesString)); + } + + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public void TestCannotUpgrade3To5() + { + var serializedPreferences = @" + + + + + Method + + + + + + + Property + Method + + + + + + + + + + + + +"; + + AssertTrimmedEqual( + NamingStylePreferences.DefaultNamingPreferencesString, + ReserializePreferences(serializedPreferences)); + } + + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public void TestUpgrade4To5() + { + var serializedPreferences = @" + + + + + Method + + + + + + + Property + Method + + + + + + + + + + + + +"; + + AssertTrimmedEqual( + serializedPreferences + .Replace("SerializationVersion=\"4\"", "SerializationVersion=\"5\"") + .Replace("Method", "Ordinary"), + ReserializePreferences(serializedPreferences)); + } + + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public void TestPreserveLatestVersion5() + { + var serializedPreferences = @" + + + + + Ordinary + + + + + + + Property + Ordinary + + + + + + + + + + + + +"; + + AssertTrimmedEqual( + serializedPreferences, + ReserializePreferences(serializedPreferences)); + } + } +} From e828dae3785f8ef741142aa7aaefc44b49143f7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Tue, 17 Apr 2018 14:23:56 +0200 Subject: [PATCH 14/23] Details --- .../DeclarationNameCompletionProviderTests.cs | 2 ++ .../DeclarationNameCompletionProvider.DeclarationInfo.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs index ea00afcfc0868..790ab75fa8354 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs @@ -1308,6 +1308,8 @@ private static NamingStylePreferences NamesEndWithSuffixPreferences() specificationStyles.Select(t => t.style).ToImmutableArray(), specificationStyles.Select(t => CreateRule(t.specification, t.style)).ToImmutableArray()); + // Local functions + (SymbolSpecification specification, NamingStyle style) SpecificationStyle(SymbolKindOrTypeKind kind, string suffix) { var symbolSpecification = new SymbolSpecification( diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs index 9314581a023d3..9f22ec8f9e6fb 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs @@ -266,6 +266,8 @@ private static bool IsVariableDeclaration(SyntaxToken token, SemanticModel seman cancellationToken); return result.Type != null; + // Local functions + ImmutableArray GetPossibleKinds() { // If we only have a type, this can still end up being a local function. From c0ca8d7d303180cce6ae2e2af10626016d5b23a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Tue, 17 Apr 2018 16:50:00 +0200 Subject: [PATCH 15/23] Test for correct order of naming suggestions --- .../DeclarationNameCompletionProviderTests.cs | 15 +++++++++++++++ .../AbstractCompletionProviderTests.cs | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs index 790ab75fa8354..0cbd561464b00 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs @@ -551,6 +551,21 @@ void goo() await VerifyNoItemsExistAsync(markup); } + [Fact, Trait(Traits.Feature, Traits.Features.Completion)] + public async Task TestCorrectOrder() + { + var markup = @" +public class MyClass +{ + MyClass $$ +} +"; + var items = await GetCompletionItemsAsync(markup, SourceCodeKind.Regular); + Assert.Equal( + new[] { "myClass", "my", "@class", "MyClass", "My", "Class", "GetMyClass", "GetMy", "GetClass" }, + items.Select(item => item.DisplayText)); + } + [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task TestDescriptionInsideClass() { diff --git a/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs b/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs index 0a9f8b5efe715..f5deb69985a2e 100644 --- a/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs +++ b/src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs @@ -816,5 +816,21 @@ protected async Task VerifyCommitCharactersAsync(string initialMarkup, string te } } } + + protected async Task> GetCompletionItemsAsync( + string markup, SourceCodeKind sourceCodeKind, bool usePreviousCharAsTrigger = false) + { + MarkupTestFile.GetPosition(markup.NormalizeLineEndings(), out var code, out int position); + var document = WorkspaceFixture.UpdateDocument(code, sourceCodeKind); + + var trigger = usePreviousCharAsTrigger + ? CompletionTrigger.CreateInsertionTrigger(insertedCharacter: code.ElementAt(position - 1)) + : CompletionTrigger.Invoke; + + var completionService = GetCompletionService(document.Project.Solution.Workspace); + var completionList = await GetCompletionListAsync(completionService, document, position, trigger); + + return completionList == null ? ImmutableArray.Empty : completionList.Items; + } } } From de35f13f6d0ca58f1e8dca017440c9723f03cb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Wed, 18 Apr 2018 16:01:17 +0200 Subject: [PATCH 16/23] Modifier exclusion for local vs local function declaration --- ...nProviderTests_NameDeclarationInfoTests.cs | 63 +++++++++++++++++++ ...nNameCompletionProvider.DeclarationInfo.cs | 22 ++++--- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs index 29d1fdd2f03bc..7cd40f6f4bbd2 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs @@ -497,6 +497,69 @@ await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(MethodKind.Ordinary)); } + [Theory, Trait(Traits.Feature, Traits.Features.Completion)] + [InlineData("int")] + [InlineData("C")] + [InlineData("List")] + public async Task ModifierExclusionInsideMethod_AfterConst(string type) + { + var markup = $@" +using System.Collections.Generic; +class C +{{ + void M() + {{ + const {type} $$ + }} +}} +"; + await VerifySymbolKinds(markup, + new SymbolKindOrTypeKind(SymbolKind.Local)); + } + + [Theory, Trait(Traits.Feature, Traits.Features.Completion)] + [InlineData("int")] + [InlineData("C")] + [InlineData("List")] + public async Task ModifierExclusionInsideMethod_AfterAsync(string type) + { + // This only works with a partially written name. + // Because async is not a keyword, the syntax tree when the name is missing is completely broken + // in that there can be multiple statements full of missing and skipped tokens depending on the type syntax. + var markup = $@" +using System.Collections.Generic; +class C +{{ + void M() + {{ + async {type} F$$ + }} +}} +"; + await VerifySymbolKinds(markup, + new SymbolKindOrTypeKind(MethodKind.LocalFunction)); + } + + [Theory, Trait(Traits.Feature, Traits.Features.Completion)] + [InlineData("int")] + [InlineData("C")] + [InlineData("List")] + public async Task ModifierExclusionInsideMethod_AfterUnsafe(string type) + { + var markup = $@" +using System.Collections.Generic; +class C +{{ + void M() + {{ + unsafe {type} $$ + }} +}} +"; + await VerifySymbolKinds(markup, + new SymbolKindOrTypeKind(MethodKind.LocalFunction)); + } + [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task LocalInsideMethod1() { diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs index 9f22ec8f9e6fb..f5eddacd0b545 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs @@ -262,19 +262,27 @@ private static bool IsVariableDeclaration(SyntaxToken token, SemanticModel seman v.Parent is UsingStatementSyntax ? default(SyntaxTokenList) : v.Parent is ForStatementSyntax ? default(SyntaxTokenList) : default(SyntaxTokenList?), // Return null to bail out. - possibleDeclarationComputer: d => GetPossibleKinds(), + possibleDeclarationComputer: GetPossibleKinds, cancellationToken); return result.Type != null; // Local functions - ImmutableArray GetPossibleKinds() + ImmutableArray GetPossibleKinds(DeclarationModifiers modifiers) { - // If we only have a type, this can still end up being a local function. - return token.IsKind(SyntaxKind.CommaToken) - ? ImmutableArray.Create( - new SymbolKindOrTypeKind(SymbolKind.Local)) - : ImmutableArray.Create( + if (token.IsKind(SyntaxKind.CommaToken)) + { + return ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)); + } + + // If we only have a type, this can still end up being a local function (depending on the modifiers). + + return + modifiers.IsConst + ? ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)) : + modifiers.IsAsync || modifiers.IsUnsafe + ? ImmutableArray.Create(new SymbolKindOrTypeKind(MethodKind.LocalFunction)) : + ImmutableArray.Create( new SymbolKindOrTypeKind(SymbolKind.Local), new SymbolKindOrTypeKind(MethodKind.LocalFunction)); } From 8304bf8ab170f75c89e613a791c7426806638608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Fri, 20 Apr 2018 12:19:29 +0200 Subject: [PATCH 17/23] Fixing logic for name suggestions inside using & for (they can't be a local function) --- ...nNameCompletionProvider.DeclarationInfo.cs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs index f5eddacd0b545..80bf967dda247 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs @@ -49,7 +49,8 @@ internal static async Task GetDeclarationInfo(Document docu if (IsParameterDeclaration(token, semanticModel, position, cancellationToken, out var result) || IsTypeParameterDeclaration(token, semanticModel, position, cancellationToken, out result) - || IsVariableDeclaration(token, semanticModel, position, cancellationToken, out result) + || IsLocalVariableDeclaration(token, semanticModel, position, cancellationToken, out result) + || IsEmbeddedVariableDeclaration(token, semanticModel, position, cancellationToken, out result) || IsForEachVariableDeclaration(token, semanticModel, position, cancellationToken, out result) || IsIncompleteMemberDeclaration(token, semanticModel, position, cancellationToken, out result) || IsFieldDeclaration(token, semanticModel, position, cancellationToken, out result) @@ -252,16 +253,14 @@ private static bool IsIncompleteMemberDeclaration(SyntaxToken token, SemanticMod return result.Type != null; } - private static bool IsVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, + private static bool IsLocalVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, int position, CancellationToken cancellationToken, out NameDeclarationInfo result) { result = IsFollowingTypeOrComma(token, semanticModel, typeSyntaxGetter: v => v.Type, - modifierGetter: v => - v.Parent is LocalDeclarationStatementSyntax localDeclaration ? localDeclaration.Modifiers : - v.Parent is UsingStatementSyntax ? default(SyntaxTokenList) : - v.Parent is ForStatementSyntax ? default(SyntaxTokenList) : - default(SyntaxTokenList?), // Return null to bail out. + modifierGetter: v => v.Parent is LocalDeclarationStatementSyntax localDeclaration + ? localDeclaration.Modifiers + : default(SyntaxTokenList?), // Return null to bail out. possibleDeclarationComputer: GetPossibleKinds, cancellationToken); return result.Type != null; @@ -288,6 +287,19 @@ ImmutableArray GetPossibleKinds(DeclarationModifiers modif } } + private static bool IsEmbeddedVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, + int position, CancellationToken cancellationToken, out NameDeclarationInfo result) + { + result = IsFollowingTypeOrComma(token, semanticModel, + typeSyntaxGetter: v => v.Type, + modifierGetter: v => v.Parent is UsingStatementSyntax || v.Parent is ForStatementSyntax + ? default(SyntaxTokenList) + : default(SyntaxTokenList?), // Return null to bail out. + possibleDeclarationComputer: d => ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)), + cancellationToken); + return result.Type != null; + } + private static bool IsForEachVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, int position, CancellationToken cancellationToken, out NameDeclarationInfo result) { From 393802e4f69bae309f229dcd0687a68e1f3a396b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Sun, 22 Apr 2018 15:27:44 +0200 Subject: [PATCH 18/23] Name suggestions for an actual fully-typed local function --- ...nProviderTests_NameDeclarationInfoTests.cs | 134 +++++++++++++++++- ...nNameCompletionProvider.DeclarationInfo.cs | 53 ++++--- 2 files changed, 161 insertions(+), 26 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs index 7cd40f6f4bbd2..fc12289b0792f 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests_NameDeclarationInfoTests.cs @@ -501,7 +501,7 @@ await VerifySymbolKinds(markup, [InlineData("int")] [InlineData("C")] [InlineData("List")] - public async Task ModifierExclusionInsideMethod_AfterConst(string type) + public async Task ModifierExclusionInsideMethod_Const(string type) { var markup = $@" using System.Collections.Generic; @@ -521,7 +521,49 @@ await VerifySymbolKinds(markup, [InlineData("int")] [InlineData("C")] [InlineData("List")] - public async Task ModifierExclusionInsideMethod_AfterAsync(string type) + public async Task ModifierExclusionInsideMethod_ConstLocalDeclaration(string type) + { + var markup = $@" +using System.Collections.Generic; +class C +{{ + void M() + {{ + const {type} v$$ = default; + }} +}} +"; + await VerifySymbolKinds(markup, + new SymbolKindOrTypeKind(SymbolKind.Local)); + } + + [Theory, Trait(Traits.Feature, Traits.Features.Completion)] + [InlineData("int")] + [InlineData("C")] + [InlineData("List")] + public async Task ModifierExclusionInsideMethod_ConstLocalFunction(string type) + { + var markup = $@" +using System.Collections.Generic; +class C +{{ + void M() + {{ + const {type} v$$() + {{ + }} + }} +}} +"; + await VerifySymbolKinds(markup, + new SymbolKindOrTypeKind(SymbolKind.Local)); + } + + [Theory, Trait(Traits.Feature, Traits.Features.Completion)] + [InlineData("int")] + [InlineData("C")] + [InlineData("List")] + public async Task ModifierExclusionInsideMethod_Async(string type) { // This only works with a partially written name. // Because async is not a keyword, the syntax tree when the name is missing is completely broken @@ -532,7 +574,27 @@ class C {{ void M() {{ - async {type} F$$ + async {type} v$$ + }} +}} +"; + await VerifySymbolKinds(markup, + new SymbolKindOrTypeKind(MethodKind.LocalFunction)); + } + + [Theory, Trait(Traits.Feature, Traits.Features.Completion)] + [InlineData("int")] + [InlineData("C")] + [InlineData("List")] + public async Task ModifierExclusionInsideMethod_AsyncLocalDeclaration(string type) + { + var markup = $@" +using System.Collections.Generic; +class C +{{ + void M() + {{ + async {type} v$$ = default; }} }} "; @@ -544,7 +606,29 @@ await VerifySymbolKinds(markup, [InlineData("int")] [InlineData("C")] [InlineData("List")] - public async Task ModifierExclusionInsideMethod_AfterUnsafe(string type) + public async Task ModifierExclusionInsideMethod_AsyncLocalFunction(string type) + { + var markup = $@" +using System.Collections.Generic; +class C +{{ + void M() + {{ + async {type} v$$() + {{ + }} + }} +}} +"; + await VerifySymbolKinds(markup, + new SymbolKindOrTypeKind(MethodKind.LocalFunction)); + } + + [Theory, Trait(Traits.Feature, Traits.Features.Completion)] + [InlineData("int")] + [InlineData("C")] + [InlineData("List")] + public async Task ModifierExclusionInsideMethod_Unsafe(string type) { var markup = $@" using System.Collections.Generic; @@ -560,6 +644,48 @@ await VerifySymbolKinds(markup, new SymbolKindOrTypeKind(MethodKind.LocalFunction)); } + [Theory, Trait(Traits.Feature, Traits.Features.Completion)] + [InlineData("int")] + [InlineData("C")] + [InlineData("List")] + public async Task ModifierExclusionInsideMethod_UnsafeLocalDeclaration(string type) + { + var markup = $@" +using System.Collections.Generic; +class C +{{ + void M() + {{ + unsafe {type} v$$ = default; + }} +}} +"; + await VerifySymbolKinds(markup, + new SymbolKindOrTypeKind(MethodKind.LocalFunction)); + } + + [Theory, Trait(Traits.Feature, Traits.Features.Completion)] + [InlineData("int")] + [InlineData("C")] + [InlineData("List")] + public async Task ModifierExclusionInsideMethod_UnsafeLocalFunction(string type) + { + var markup = $@" +using System.Collections.Generic; +class C +{{ + void M() + {{ + unsafe {type} v$$() + {{ + }} + }} +}} +"; + await VerifySymbolKinds(markup, + new SymbolKindOrTypeKind(MethodKind.LocalFunction)); + } + [Fact, Trait(Traits.Feature, Traits.Features.Completion)] public async Task LocalInsideMethod1() { diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs index 80bf967dda247..c030012c06048 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs @@ -49,6 +49,7 @@ internal static async Task GetDeclarationInfo(Document docu if (IsParameterDeclaration(token, semanticModel, position, cancellationToken, out var result) || IsTypeParameterDeclaration(token, semanticModel, position, cancellationToken, out result) + || IsLocalFunctionDeclaration(token, semanticModel, position, cancellationToken, out result) || IsLocalVariableDeclaration(token, semanticModel, position, cancellationToken, out result) || IsEmbeddedVariableDeclaration(token, semanticModel, position, cancellationToken, out result) || IsForEachVariableDeclaration(token, semanticModel, position, cancellationToken, out result) @@ -253,38 +254,34 @@ private static bool IsIncompleteMemberDeclaration(SyntaxToken token, SemanticMod return result.Type != null; } + private static bool IsLocalFunctionDeclaration(SyntaxToken token, SemanticModel semanticModel, + int position, CancellationToken cancellationToken, out NameDeclarationInfo result) + { + result = IsLastTokenOfType(token, semanticModel, + typeSyntaxGetter: f => f.ReturnType, + modifierGetter: f => f.Modifiers, + possibleDeclarationComputer: GetPossibleLocalDeclarations, + cancellationToken); + return result.Type != null; + } + private static bool IsLocalVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, int position, CancellationToken cancellationToken, out NameDeclarationInfo result) { + // If we only have a type, this can still end up being a local function (depending on the modifiers). + var possibleDeclarationComputer = token.IsKind(SyntaxKind.CommaToken) + ? (Func>) + (_ => ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local))) + : GetPossibleLocalDeclarations; + result = IsFollowingTypeOrComma(token, semanticModel, typeSyntaxGetter: v => v.Type, modifierGetter: v => v.Parent is LocalDeclarationStatementSyntax localDeclaration ? localDeclaration.Modifiers : default(SyntaxTokenList?), // Return null to bail out. - possibleDeclarationComputer: GetPossibleKinds, + possibleDeclarationComputer, cancellationToken); return result.Type != null; - - // Local functions - - ImmutableArray GetPossibleKinds(DeclarationModifiers modifiers) - { - if (token.IsKind(SyntaxKind.CommaToken)) - { - return ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)); - } - - // If we only have a type, this can still end up being a local function (depending on the modifiers). - - return - modifiers.IsConst - ? ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)) : - modifiers.IsAsync || modifiers.IsUnsafe - ? ImmutableArray.Create(new SymbolKindOrTypeKind(MethodKind.LocalFunction)) : - ImmutableArray.Create( - new SymbolKindOrTypeKind(SymbolKind.Local), - new SymbolKindOrTypeKind(MethodKind.LocalFunction)); - } } private static bool IsEmbeddedVariableDeclaration(SyntaxToken token, SemanticModel semanticModel, @@ -417,6 +414,18 @@ private static ImmutableArray GetPossibleMemberDeclaration return possibleTypes; } + private static ImmutableArray GetPossibleLocalDeclarations(DeclarationModifiers modifiers) + { + return + modifiers.IsConst + ? ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)) : + modifiers.IsAsync || modifiers.IsUnsafe + ? ImmutableArray.Create(new SymbolKindOrTypeKind(MethodKind.LocalFunction)) : + ImmutableArray.Create( + new SymbolKindOrTypeKind(SymbolKind.Local), + new SymbolKindOrTypeKind(MethodKind.LocalFunction)); + } + private static DeclarationModifiers GetDeclarationModifiers(SyntaxTokenList modifiers) { var declarationModifiers = new DeclarationModifiers(); From 014dadde7e4d7264b8cd6f5506718044ea0283db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Fri, 11 May 2018 22:26:05 +0200 Subject: [PATCH 19/23] Adding test with a higher than latest serialization version --- .../NamingStylePreferencesUpgradeTests.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Workspaces/CoreTest/CodeStyle/NamingStylePreferencesUpgradeTests.cs b/src/Workspaces/CoreTest/CodeStyle/NamingStylePreferencesUpgradeTests.cs index dee87178fae6b..726ecaeff03b7 100644 --- a/src/Workspaces/CoreTest/CodeStyle/NamingStylePreferencesUpgradeTests.cs +++ b/src/Workspaces/CoreTest/CodeStyle/NamingStylePreferencesUpgradeTests.cs @@ -137,5 +137,41 @@ public void TestPreserveLatestVersion5() serializedPreferences, ReserializePreferences(serializedPreferences)); } + + [Fact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public void TestCannotDowngradeHigherThanLatestVersion5() + { + var serializedPreferences = @" + + + + + Ordinary + + + + + + + Property + Ordinary + + + + + + + + + + + + +"; + + AssertTrimmedEqual( + NamingStylePreferences.DefaultNamingPreferencesString, + ReserializePreferences(serializedPreferences)); + } } } From 3f00166bc327658ae7717e6d61ee5e62e27ecdf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Mon, 28 May 2018 16:09:41 +0200 Subject: [PATCH 20/23] Fix after merge --- .../DeclarationNameCompletionProvider.DeclarationInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs index 17f0be7b8d8f8..e037c152d7ce2 100644 --- a/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs +++ b/src/Features/CSharp/Portable/Completion/CompletionProviders/DeclarationNameCompletionProvider.DeclarationInfo.cs @@ -78,7 +78,7 @@ private static bool IsTupleTypeElement( semanticModel, tupleElement => tupleElement.Type, _ => default(SyntaxTokenList), - _ => ImmutableArray.Create(SymbolKind.Local), cancellationToken); + _ => ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)), cancellationToken); return result.Type != null; } @@ -100,7 +100,7 @@ private static bool IsTupleLiteralElement( semanticModel, GetNodeDenotingTheTypeOfTupleArgument, _ => default(SyntaxTokenList), - _ => ImmutableArray.Create(SymbolKind.Local), cancellationToken); + _ => ImmutableArray.Create(new SymbolKindOrTypeKind(SymbolKind.Local)), cancellationToken); return result.Type != null; } From d9262c2f26907b1b459f52f78d7cddb2009216e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Mon, 28 May 2018 19:40:03 +0200 Subject: [PATCH 21/23] Adding new roaming location to prevent syncing the new serialization format into an older version --- ...amingVisualStudioProfileOptionPersister.cs | 37 +++++++++++++++---- .../Serialization/NamingStylePreferences.cs | 2 + .../Simplification/SimplificationOptions.cs | 6 ++- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/VisualStudio/Core/Def/Implementation/Options/RoamingVisualStudioProfileOptionPersister.cs b/src/VisualStudio/Core/Def/Implementation/Options/RoamingVisualStudioProfileOptionPersister.cs index 6223aaa010a6c..a403e6897a751 100644 --- a/src/VisualStudio/Core/Def/Implementation/Options/RoamingVisualStudioProfileOptionPersister.cs +++ b/src/VisualStudio/Core/Def/Implementation/Options/RoamingVisualStudioProfileOptionPersister.cs @@ -80,6 +80,31 @@ private System.Threading.Tasks.Task OnSettingChangedAsync(object sender, Propert return SpecializedTasks.EmptyTask; } + private object GetFirstOrDefaultValue(OptionKey optionKey, IEnumerable roamingSerializations) + { + // There can be more than 1 roaming location in the order of their priority. + // When fetching a value, we iterate all of them until we find the first one that exists. + // When persisting a value, we always use the first location. + // This functionality exists for breaking changes to persistence of some options. In such a case, there + // will be a new location added to the beginning with a new name. When fetching a value, we might find the old + // location (and can upgrade the value accordingly) but we only write to the new location so that + // we don't interfere with older versions. This will essentially "fork" the user's options at the time of upgrade. + + foreach (var roamingSerialization in roamingSerializations) + { + var storageKey = roamingSerialization.GetKeyNameForLanguage(optionKey.Language); + + RecordObservedValueToWatchForChanges(optionKey, storageKey); + + if (_settingManager.TryGetValue(storageKey, out object value) == GetValueResult.Success) + { + return value; + } + } + + return optionKey.Option.DefaultValue; + } + public bool TryFetch(OptionKey optionKey, out object value) { if (_settingManager == null) @@ -90,19 +115,15 @@ public bool TryFetch(OptionKey optionKey, out object value) } // Do we roam this at all? - var roamingSerialization = optionKey.Option.StorageLocations.OfType().SingleOrDefault(); + var roamingSerializations = optionKey.Option.StorageLocations.OfType(); - if (roamingSerialization == null) + if (!roamingSerializations.Any()) { value = null; return false; } - var storageKey = roamingSerialization.GetKeyNameForLanguage(optionKey.Language); - - RecordObservedValueToWatchForChanges(optionKey, storageKey); - - value = _settingManager.GetValueOrDefault(storageKey, optionKey.Option.DefaultValue); + value = GetFirstOrDefaultValue(optionKey, roamingSerializations); // VS's ISettingsManager has some quirks around storing enums. Specifically, // it *can* persist and retrieve enums, but only if you properly call @@ -222,7 +243,7 @@ public bool TryPersist(OptionKey optionKey, object value) } // Do we roam this at all? - var roamingSerialization = optionKey.Option.StorageLocations.OfType().SingleOrDefault(); + var roamingSerialization = optionKey.Option.StorageLocations.OfType().FirstOrDefault(); if (roamingSerialization == null) { diff --git a/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs b/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs index e5d4a6302e0e2..b2ded70b0d239 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/Serialization/NamingStylePreferences.cs @@ -349,6 +349,8 @@ private static XElement GetUpgradedSerializationIfNecessary(XElement rootElement // Add future version checks here. If the version is off by more than 1, these upgrades will run in sequence. // The next one should check serializationVersion == 5 and update it to 6. + // It is also important to create a new roaming location in SimplificationOptions.NamingPreferences + // so that we never store the new format in an older version. Debug.Assert(s_serializationVersion == 5, "After increasing the serialization version, add an upgrade path here."); return serializationVersion == s_serializationVersion diff --git a/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs b/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs index fb8606040d4c4..824392386d263 100644 --- a/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs +++ b/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs @@ -101,8 +101,10 @@ public static class SimplificationOptions /// and the level to which those rules should be enforced. /// internal static PerLanguageOption NamingPreferences { get; } = new PerLanguageOption(nameof(SimplificationOptions), nameof(NamingPreferences), defaultValue: NamingStylePreferences.Default, - storageLocations: new OptionStorageLocation[]{ + storageLocations: new OptionStorageLocation[] { new NamingStylePreferenceEditorConfigStorageLocation(), - new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.NamingPreferences")}); + new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.NamingPreferences[5]"), + new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.NamingPreferences") + }); } } From 352226e4ede98f38f9224b3c4282c795e1100e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Kon=C3=AD=C4=8Dek?= Date: Tue, 29 May 2018 22:07:41 +0200 Subject: [PATCH 22/23] Removing outdated comment & adding missing test case --- .../DeclarationNameCompletionProviderTests.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs index d8f47b41cfeb5..80200ff772dc4 100644 --- a/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Completion/CompletionProviders/DeclarationNameCompletionProviderTests.cs @@ -1478,6 +1478,7 @@ await VerifyItemExistsAsync(markup, "ConfigurationProperty", glyph: (int)Glyph.P expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); await VerifyItemExistsAsync(markup, "ConfigurationMethod", glyph: (int)Glyph.MethodPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); + await VerifyItemIsAbsentAsync(markup, "ConfigurationLocal"); await VerifyItemIsAbsentAsync(markup, "ConfigurationLocalFunction"); } finally @@ -1507,7 +1508,8 @@ void M() } } "; - // We don't support naming preferences for locals... yet. + await VerifyItemExistsAsync(markup, "ConfigurationLocal", glyph: (int)Glyph.Local, + expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); await VerifyItemExistsAsync(markup, "ConfigurationLocalFunction", glyph: (int)Glyph.MethodPublic, expectedDescriptionOrNull: CSharpFeaturesResources.Suggested_name); await VerifyItemIsAbsentAsync(markup, "ConfigurationField"); @@ -1527,6 +1529,7 @@ private static NamingStylePreferences NamesEndWithSuffixPreferences() SpecificationStyle(new SymbolKindOrTypeKind(SymbolKind.Field), "Field"), SpecificationStyle(new SymbolKindOrTypeKind(SymbolKind.Property), "Property"), SpecificationStyle(new SymbolKindOrTypeKind(MethodKind.Ordinary), "Method"), + SpecificationStyle(new SymbolKindOrTypeKind(SymbolKind.Local), "Local"), SpecificationStyle(new SymbolKindOrTypeKind(MethodKind.LocalFunction), "LocalFunction"), }; From ed4f34ce4d36f0cc7afc9bc93713f976bdb8e9bf Mon Sep 17 00:00:00 2001 From: Neme12 Date: Thu, 31 May 2018 21:01:42 +0200 Subject: [PATCH 23/23] Switching to form without brackets --- .../Core/Portable/Simplification/SimplificationOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs b/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs index 824392386d263..11b8b35ac15fb 100644 --- a/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs +++ b/src/Workspaces/Core/Portable/Simplification/SimplificationOptions.cs @@ -103,7 +103,7 @@ public static class SimplificationOptions internal static PerLanguageOption NamingPreferences { get; } = new PerLanguageOption(nameof(SimplificationOptions), nameof(NamingPreferences), defaultValue: NamingStylePreferences.Default, storageLocations: new OptionStorageLocation[] { new NamingStylePreferenceEditorConfigStorageLocation(), - new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.NamingPreferences[5]"), + new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.NamingPreferences5"), new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.NamingPreferences") }); }