diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs index d67858fa25ce893714def0bd87bc5a87bcb228e0..4e3338b1578ade401c9c4310c1c80d8fa0551706 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests.cs @@ -77,6 +77,20 @@ public async Task TestPascalCaseMethod_PropertyAccessorsAreIgnored() @"class C { public int P { [|get|]; set; } +}", + options: MethodNamesArePascalCase); + } + + [WpfFact, Trait(Traits.Feature, Traits.Features.NamingStyle)] + public async Task TestPascalCaseMethod_IndexerNameIsIgnored() + { + await TestMissingAsync( +@"class C +{ + public int [|this|][int index] + { + get { return 1; } + } }", options: MethodNamesArePascalCase); } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests_OptionSets.cs b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests_OptionSets.cs index f2f74f29a0385f6a02778b713c204215a79323ec..4a1dce430c4cf335ac6c94462bfb60df45fcb7b2 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests_OptionSets.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/NamingStyles/NamingStylesTests_OptionSets.cs @@ -27,16 +27,14 @@ public partial class NamingStylesTests : AbstractCSharpDiagnosticProviderBasedUs return options; } - [WpfFact, Trait(Traits.Feature, Traits.Features.NamingStyle)] private string ClassNamesArePascalCaseOptionString() { var symbolSpecification = new SymbolSpecification( - Guid.NewGuid(), - "Name", + Guid.NewGuid(), + "Name", SpecializedCollections.SingletonEnumerable(new SymbolSpecification.SymbolKindOrTypeKind(TypeKind.Class)).ToList(), SpecializedCollections.EmptyList(), - SpecializedCollections.EmptyList(), - SpecializedCollections.EmptyList()); + SpecializedCollections.EmptyList()); var namingStyle = new NamingStyle(); namingStyle.CapitalizationScheme = Capitalization.PascalCase; @@ -50,7 +48,6 @@ private string ClassNamesArePascalCaseOptionString() namingRule.SymbolSpecificationID = symbolSpecification.ID; namingRule.NamingStyleID = namingStyle.ID; namingRule.EnforcementLevel = DiagnosticSeverity.Error; - namingRule.Title = "Title"; var info = new SerializableNamingStylePreferencesInfo(); info.SymbolSpecifications.Add(symbolSpecification); @@ -60,7 +57,6 @@ private string ClassNamesArePascalCaseOptionString() return info.CreateXElement().ToString(); } - [WpfFact, Trait(Traits.Feature, Traits.Features.NamingStyle)] private string MethodNamesArePascalCaseOptionString() { var symbolSpecification = new SymbolSpecification( @@ -68,8 +64,7 @@ private string MethodNamesArePascalCaseOptionString() "Name", SpecializedCollections.SingletonEnumerable(new SymbolSpecification.SymbolKindOrTypeKind(SymbolKind.Method)).ToList(), SpecializedCollections.EmptyList(), - SpecializedCollections.EmptyList(), - SpecializedCollections.EmptyList()); + SpecializedCollections.EmptyList()); var namingStyle = new NamingStyle(); namingStyle.CapitalizationScheme = Capitalization.PascalCase; @@ -83,7 +78,6 @@ private string MethodNamesArePascalCaseOptionString() namingRule.SymbolSpecificationID = symbolSpecification.ID; namingRule.NamingStyleID = namingStyle.ID; namingRule.EnforcementLevel = DiagnosticSeverity.Error; - namingRule.Title = "Title"; var info = new SerializableNamingStylePreferencesInfo(); info.SymbolSpecifications.Add(symbolSpecification); diff --git a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingRule.cs b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingRule.cs index 0fda0455ab163da63ad9736981a4f476622bf918..c8bc2a0e5217b5b61ec7bfccaa308083447dbac3 100644 --- a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingRule.cs +++ b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingRule.cs @@ -1,44 +1,26 @@ // 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.Collections.Immutable; -using System.Diagnostics; -using System.Linq; -using Microsoft.CodeAnalysis.SymbolCategorization; namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles { internal class NamingRule { - public readonly string Title; - public readonly ImmutableArray Children; public readonly SymbolSpecification SymbolSpecification; public readonly NamingStyle NamingStyle; public readonly DiagnosticSeverity EnforcementLevel; - public NamingRule(string title, ImmutableArray children, SymbolSpecification symbolSpecification, NamingStyle namingStyle, DiagnosticSeverity enforcementLevel) + public NamingRule(SymbolSpecification symbolSpecification, NamingStyle namingStyle, DiagnosticSeverity enforcementLevel) { - Title = title; - Children = children; SymbolSpecification = symbolSpecification; NamingStyle = namingStyle; EnforcementLevel = enforcementLevel; } - public bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizationService) - { - return SymbolSpecification.AppliesTo(symbol, categorizationService); - } - - internal NamingRule GetBestMatchingRule(ISymbol symbol, ISymbolCategorizationService categorizationService) - { - Debug.Assert(SymbolSpecification.AppliesTo(symbol, categorizationService)); - var matchingChild = Children.FirstOrDefault(r => r.AppliesTo(symbol, categorizationService)); - return matchingChild?.GetBestMatchingRule(symbol, categorizationService) ?? this; - } + public bool AppliesTo(ISymbol symbol) + => SymbolSpecification.AppliesTo(symbol); public bool IsNameCompliant(string name, out string failureReason) - { - return NamingStyle.IsNameCompliant(name, out failureReason); - } + => NamingStyle.IsNameCompliant(name, out failureReason); } } \ No newline at end of file diff --git a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingStyleDiagnosticAnalyzerBase.cs b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingStyleDiagnosticAnalyzerBase.cs index 868140a137419733c6fc9cf799e17afa00220b7e..2346cff7cfe19fdba7b64d81cf156608c94f1e06 100644 --- a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingStyleDiagnosticAnalyzerBase.cs +++ b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingStyleDiagnosticAnalyzerBase.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Xml.Linq; using Microsoft.CodeAnalysis.Simplification; -using Microsoft.CodeAnalysis.SymbolCategorization; namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles { @@ -47,8 +46,6 @@ public override void Initialize(AnalysisContext context) private void CompilationStartAction(CompilationStartAnalysisContext context) { var workspace = (context.Options as WorkspaceAnalyzerOptions)?.Workspace; - var categorizationService = workspace.Services.GetService(); - var optionSet = (context.Options as WorkspaceAnalyzerOptions)?.Workspace.Options; var currentValue = optionSet.GetOption(SimplificationOptions.NamingPreferences, context.Compilation.Language); @@ -62,15 +59,15 @@ private void CompilationStartAction(CompilationStartAnalysisContext context) var viewModel = SerializableNamingStylePreferencesInfo.FromXElement(XElement.Parse(currentValue)); var preferencesInfo = viewModel.GetPreferencesInfo(); context.RegisterSymbolAction( - symbolContext => SymbolAction(symbolContext, preferencesInfo, categorizationService), + symbolContext => SymbolAction(symbolContext, preferencesInfo), _symbolKinds); } } - private void SymbolAction(SymbolAnalysisContext context, NamingStylePreferencesInfo preferences, ISymbolCategorizationService categorizationService) + private void SymbolAction(SymbolAnalysisContext context, NamingStylePreferencesInfo preferences) { NamingRule applicableRule; - if (preferences.TryGetApplicableRule(context.Symbol, categorizationService, out applicableRule)) + if (preferences.TryGetApplicableRule(context.Symbol, out applicableRule)) { string failureReason; if (applicableRule.EnforcementLevel != DiagnosticSeverity.Hidden && @@ -78,7 +75,7 @@ private void SymbolAction(SymbolAnalysisContext context, NamingStylePreferencesI { var descriptor = new DiagnosticDescriptor(IDEDiagnosticIds.NamingRuleId, s_localizableTitleNamingStyle, - string.Format(FeaturesResources._0_naming_violation_1, applicableRule.Title, failureReason), + string.Format(FeaturesResources.Naming_rule_violation_0, failureReason), DiagnosticCategory.Style, applicableRule.EnforcementLevel, isEnabledByDefault: true); diff --git a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingStylePreferencesInfo.cs b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingStylePreferencesInfo.cs index 3c88e95460bfd370ded9f39130ec236080c31855..f0b4ee23d8a14b0f15de52fab406f3feb70db2ce 100644 --- a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingStylePreferencesInfo.cs +++ b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/NamingStylePreferencesInfo.cs @@ -1,9 +1,7 @@ // 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 Microsoft.CodeAnalysis.SymbolCategorization; namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles { @@ -16,7 +14,7 @@ public NamingStylePreferencesInfo(ImmutableArray namingRules) NamingRules = namingRules; } - internal bool TryGetApplicableRule(ISymbol symbol, ISymbolCategorizationService categorizationService, out NamingRule applicableRule) + internal bool TryGetApplicableRule(ISymbol symbol, out NamingRule applicableRule) { if (NamingRules == null) { @@ -29,24 +27,38 @@ internal bool TryGetApplicableRule(ISymbol symbol, ISymbolCategorizationService applicableRule = null; return false; } - - var matchingRule = NamingRules.FirstOrDefault(r => r.AppliesTo(symbol, categorizationService)); - if (matchingRule == null) + + foreach (var namingRule in NamingRules) { - applicableRule = null; - return false; + if (namingRule.AppliesTo(symbol)) + { + applicableRule = namingRule; + return true; + } } - applicableRule = matchingRule.GetBestMatchingRule(symbol, categorizationService); - return true; + applicableRule = null; + return false; } private bool IsSymbolNameAnalyzable(ISymbol symbol) { - var methodSymbol = symbol as IMethodSymbol; - if (methodSymbol != null && methodSymbol.MethodKind != MethodKind.Ordinary) + if (symbol.Kind == SymbolKind.Method) { - return false; + var methodSymbol = symbol as IMethodSymbol; + if (methodSymbol != null && methodSymbol.MethodKind != MethodKind.Ordinary) + { + return false; + } + } + + if (symbol.Kind == SymbolKind.Property) + { + var propertySymbol = symbol as IPropertySymbol; + if (propertySymbol != null && propertySymbol.IsIndexer) + { + return false; + } } return true; diff --git a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/INamingStyle.cs b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/INamingStyle.cs deleted file mode 100644 index 39af0887a354c7bf1720950ee21bc7be59465f46..0000000000000000000000000000000000000000 --- a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/INamingStyle.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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.Generic; - -namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles -{ - internal interface INamingStyle - { - Guid ID { get; } - string CreateName(IEnumerable words); - IEnumerable MakeCompliant(string name); - bool IsNameCompliant(string name, out string failureReason); - } -} \ No newline at end of file diff --git a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/NamingStyle.cs b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/NamingStyle.cs index 25f645ed62a8a65bc08774a7531a1f6f3380ce72..4a42348fa9d14566506d5168f16726430c49f658 100644 --- a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/NamingStyle.cs +++ b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/NamingStyle.cs @@ -8,7 +8,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles { - internal class NamingStyle : INamingStyle + internal class NamingStyle { public Guid ID { get; set; } public string Name { get; set; } @@ -116,7 +116,7 @@ public bool IsNameCompliant(string name, out string failureReason) { if (!char.IsLower(words.First()[0])) { - failureReason = FeaturesResources.The_first_word_0_must_begin_with_a_lower_case_character; + failureReason = string.Format(FeaturesResources.The_first_word_0_must_begin_with_a_lower_case_character, words.First()); } var violations = words.Skip(1).Where(w => !char.IsUpper(w[0])); @@ -296,9 +296,9 @@ internal XElement CreateXElement() return new XElement(nameof(NamingStyle), new XAttribute(nameof(ID), ID), new XAttribute(nameof(Name), Name), - new XAttribute(nameof(Prefix), Prefix), - new XAttribute(nameof(Suffix), Suffix), - new XAttribute(nameof(WordSeparator), WordSeparator), + new XAttribute(nameof(Prefix), Prefix ?? string.Empty), + new XAttribute(nameof(Suffix), Suffix ?? string.Empty), + new XAttribute(nameof(WordSeparator), WordSeparator ?? string.Empty), new XAttribute(nameof(CapitalizationScheme), CapitalizationScheme)); } diff --git a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SerializableNamingRule.cs b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SerializableNamingRule.cs index aacf071e29a122f3debfaceead5b0052adefb8a6..8ce40c04e3881fc1a4fcf1911c4e37f79a15f49b 100644 --- a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SerializableNamingRule.cs +++ b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SerializableNamingRule.cs @@ -10,22 +10,13 @@ namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles { internal class SerializableNamingRule { - public string Title; - public List Children; public Guid SymbolSpecificationID; public Guid NamingStyleID; public DiagnosticSeverity EnforcementLevel; - internal SerializableNamingRule() - { - Children = new List(); - } - public NamingRule GetRule(SerializableNamingStylePreferencesInfo info) { return new NamingRule( - Title, - Children.Select(c => c.GetRule(info)).ToImmutableArray(), info.GetSymbolSpecification(SymbolSpecificationID), info.GetNamingStyle(NamingStyleID), EnforcementLevel); @@ -34,33 +25,19 @@ public NamingRule GetRule(SerializableNamingStylePreferencesInfo info) internal XElement CreateXElement() { var element = new XElement(nameof(SerializableNamingRule), - new XAttribute(nameof(Title), Title), new XAttribute(nameof(SymbolSpecificationID), SymbolSpecificationID), new XAttribute(nameof(NamingStyleID), NamingStyleID), new XAttribute(nameof(EnforcementLevel), EnforcementLevel)); - foreach (var child in Children) - { - element.Add(child.CreateXElement()); - } - return element; } internal static SerializableNamingRule FromXElement(XElement namingRuleElement) { var result = new SerializableNamingRule(); - result.Title = namingRuleElement.Attribute(nameof(Title)).Value; result.EnforcementLevel = (DiagnosticSeverity)Enum.Parse(typeof(DiagnosticSeverity), namingRuleElement.Attribute(nameof(EnforcementLevel)).Value); result.NamingStyleID = Guid.Parse(namingRuleElement.Attribute(nameof(NamingStyleID)).Value); result.SymbolSpecificationID = Guid.Parse(namingRuleElement.Attribute(nameof(SymbolSpecificationID)).Value); - - result.Children = new List(); - foreach (var childElement in namingRuleElement.Elements(nameof(SerializableNamingRule))) - { - result.Children.Add(FromXElement(childElement)); - } - return result; } } diff --git a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SerializableNamingStylePreferencesInfo.cs b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SerializableNamingStylePreferencesInfo.cs index dea7cdca43ba15cf2edb693ef16268e90dd57ced..d4ce99e56f45bb87ce2bf706ad4b68097769bd17 100644 --- a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SerializableNamingStylePreferencesInfo.cs +++ b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SerializableNamingStylePreferencesInfo.cs @@ -1,5 +1,6 @@ // 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 Microsoft.CodeAnalysis.Simplification; using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -19,7 +20,7 @@ internal class SerializableNamingStylePreferencesInfo public List SymbolSpecifications; public List NamingStyles; public List NamingRules; - private readonly static int _serializationVersion = 1; + private readonly static int _serializationVersion = 3; internal SerializableNamingStylePreferencesInfo() { @@ -92,6 +93,12 @@ internal static SerializableNamingStylePreferencesInfo FromXElement(XElement nam { var namingPreferencesInfo = new SerializableNamingStylePreferencesInfo(); + var serializationVersion = int.Parse(namingPreferencesInfoElement.Attribute("SerializationVersion").Value); + if (serializationVersion != _serializationVersion) + { + namingPreferencesInfoElement = XElement.Parse(SimplificationOptions.NamingPreferences.DefaultValue); + } + namingPreferencesInfo.SetSymbolSpecificationListFromXElement(namingPreferencesInfoElement.Element(nameof(SymbolSpecifications))); namingPreferencesInfo.SetNamingStyleListFromXElement(namingPreferencesInfoElement.Element(nameof(NamingStyles))); namingPreferencesInfo.SetNamingRuleTreeFromXElement(namingPreferencesInfoElement.Element(nameof(NamingRules))); diff --git a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SymbolSpecification.cs b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SymbolSpecification.cs index 1f340f61f27039273a4a3a3e678235b0a2c13192..e21f73fd704e6bbb560630b68029bbdba4ee388f 100644 --- a/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SymbolSpecification.cs +++ b/src/Features/Core/Portable/Diagnostics/Analyzers/NamingStyles/Serialization/SymbolSpecification.cs @@ -6,7 +6,6 @@ using System.Xml.Linq; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Shared.Extensions; -using Microsoft.CodeAnalysis.SymbolCategorization; namespace Microsoft.CodeAnalysis.Diagnostics.Analyzers.NamingStyles { @@ -14,10 +13,10 @@ internal class SymbolSpecification { public Guid ID { get; private set; } public string Name { get; private set; } + public IList ApplicableSymbolKindList { get; private set; } public IList ApplicableAccessibilityList { get; private set; } public IList RequiredModifierList { get; private set; } - public IList RequiredCustomTagList { get; private set; } internal SymbolSpecification() { @@ -51,27 +50,28 @@ internal SymbolSpecification() }; RequiredModifierList = new List(); - - RequiredCustomTagList = new List(); } - public SymbolSpecification(Guid id, string symbolSpecName, IList symbolKindList, IList accessibilityKindList, IList modifierList, IList customTagList) + public SymbolSpecification(Guid id, string symbolSpecName, + IList symbolKindList, + IList accessibilityKindList, + IList modifiers) { ID = id; Name = symbolSpecName; ApplicableAccessibilityList = accessibilityKindList; - RequiredModifierList = modifierList; + RequiredModifierList = modifiers; ApplicableSymbolKindList = symbolKindList; - RequiredCustomTagList = customTagList; } - internal bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizationService) + internal bool AppliesTo(ISymbol symbol) { if (ApplicableSymbolKindList.Any() && !ApplicableSymbolKindList.Any(k => k.AppliesTo(symbol))) { return false; } + // Modifiers must match exactly if (!RequiredModifierList.All(m => m.MatchesSymbol(symbol))) { return false; @@ -82,25 +82,17 @@ internal bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizat return false; } - // TODO: More efficient to find the categorizers that are relevant and only check those - var applicableCategories = categorizationService.GetCategorizers().SelectMany(c => c.Categorize(symbol)); - if (!RequiredCustomTagList.All(t => applicableCategories.Contains(t))) - { - return false; - } - return true; } internal XElement CreateXElement() { - return new XElement(nameof(SymbolSpecification), + return new XElement(nameof(SymbolSpecification), new XAttribute(nameof(ID), ID), new XAttribute(nameof(Name), Name), CreateSymbolKindsXElement(), CreateAccessibilitiesXElement(), - CreateModifiersXElement(), - CreateCustomTagsXElement()); + CreateModifiersXElement()); } private XElement CreateSymbolKindsXElement() @@ -139,18 +131,6 @@ private XElement CreateModifiersXElement() return modifiersElement; } - private XElement CreateCustomTagsXElement() - { - var customTagsElement = new XElement(nameof(RequiredCustomTagList)); - - foreach (var customTag in RequiredCustomTagList) - { - customTagsElement.Add(new XElement("CustomTag", customTag)); - } - - return customTagsElement; - } - internal static SymbolSpecification FromXElement(XElement symbolSpecificationElement) { var result = new SymbolSpecification(); @@ -160,32 +140,33 @@ internal static SymbolSpecification FromXElement(XElement symbolSpecificationEle result.PopulateSymbolKindListFromXElement(symbolSpecificationElement.Element(nameof(ApplicableSymbolKindList))); result.PopulateAccessibilityListFromXElement(symbolSpecificationElement.Element(nameof(ApplicableAccessibilityList))); result.PopulateModifierListFromXElement(symbolSpecificationElement.Element(nameof(RequiredModifierList))); - result.PopulateCustomTagListFromXElement(symbolSpecificationElement.Element(nameof(RequiredCustomTagList))); return result; } private void PopulateSymbolKindListFromXElement(XElement symbolKindListElement) { - ApplicableSymbolKindList = new List(); + var applicableSymbolKindList = new List(); foreach (var symbolKindElement in symbolKindListElement.Elements(nameof(SymbolKind))) { - ApplicableSymbolKindList.Add(SymbolKindOrTypeKind.AddSymbolKindFromXElement(symbolKindElement)); + applicableSymbolKindList.Add(SymbolKindOrTypeKind.AddSymbolKindFromXElement(symbolKindElement)); } foreach (var typeKindElement in symbolKindListElement.Elements(nameof(TypeKind))) { - ApplicableSymbolKindList.Add(SymbolKindOrTypeKind.AddTypeKindFromXElement(typeKindElement)); + applicableSymbolKindList.Add(SymbolKindOrTypeKind.AddTypeKindFromXElement(typeKindElement)); } + ApplicableSymbolKindList = applicableSymbolKindList; } private void PopulateAccessibilityListFromXElement(XElement accessibilityListElement) { - ApplicableAccessibilityList = new List(); + var applicableAccessibilityList = new List(); foreach (var accessibilityElement in accessibilityListElement.Elements(nameof(AccessibilityKind))) { - ApplicableAccessibilityList.Add(AccessibilityKind.FromXElement(accessibilityElement)); + applicableAccessibilityList.Add(AccessibilityKind.FromXElement(accessibilityElement)); } + ApplicableAccessibilityList = applicableAccessibilityList; } private void PopulateModifierListFromXElement(XElement modifierListElement) @@ -197,15 +178,6 @@ private void PopulateModifierListFromXElement(XElement modifierListElement) } } - private void PopulateCustomTagListFromXElement(XElement customTagListElement) - { - RequiredCustomTagList = new List(); - foreach (var customTag in customTagListElement.Elements("CustomTag")) - { - RequiredCustomTagList.Add(customTag.Value); - } - } - public class SymbolKindOrTypeKind { public SymbolKind? SymbolKind { get; set; } @@ -256,7 +228,7 @@ internal static SymbolKindOrTypeKind AddTypeKindFromXElement(XElement typeKindEl return new SymbolKindOrTypeKind((TypeKind)Enum.Parse(typeof(TypeKind), typeKindElement.Value)); } } - + public class AccessibilityKind { public Accessibility Accessibility { get; set; } @@ -384,7 +356,6 @@ internal static ModifierKind FromXElement(XElement modifierElement) return new ModifierKind((ModifierKindEnum)(ModifierKindEnum)Enum.Parse((Type)typeof(ModifierKindEnum), (string)modifierElement.Value)); } } - public enum ModifierKindEnum { IsAbstract, diff --git a/src/Features/Core/Portable/Features.csproj b/src/Features/Core/Portable/Features.csproj index a9b431c3c7b8ea323528150ddaa659655d89ba6d..fcc647da346dd632895973a2d0d2b0ca4dec20dc 100644 --- a/src/Features/Core/Portable/Features.csproj +++ b/src/Features/Core/Portable/Features.csproj @@ -296,10 +296,8 @@ - - @@ -664,10 +662,6 @@ - - - - diff --git a/src/Features/Core/Portable/FeaturesResources.Designer.cs b/src/Features/Core/Portable/FeaturesResources.Designer.cs index 97fa3d0ed1252f17086be0b2b654ff767dec384b..d2b79188d9ec80d1422fc1edef1914bb4b42a147 100644 --- a/src/Features/Core/Portable/FeaturesResources.Designer.cs +++ b/src/Features/Core/Portable/FeaturesResources.Designer.cs @@ -79,15 +79,6 @@ internal class FeaturesResources { } } - /// - /// Looks up a localized string similar to '{0}' naming violation - {1}. - /// - internal static string _0_naming_violation_1 { - get { - return ResourceManager.GetString("_0_naming_violation_1", resourceCulture); - } - } - /// /// Looks up a localized string similar to Accessing captured variable '{0}' that hasn't been accessed before in {1} will prevent the debug session from continuing.. /// @@ -347,6 +338,24 @@ internal class FeaturesResources { } } + /// + /// Looks up a localized string similar to All lowercase. + /// + internal static string All_lowercase { + get { + return ResourceManager.GetString("All_lowercase", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to All uppercase. + /// + internal static string All_uppercase { + get { + return ResourceManager.GetString("All_uppercase", resourceCulture); + } + } + /// /// Looks up a localized string similar to An active statement has been removed from its original method. You must revert your changes to continue or restart the debugging session.. /// @@ -495,6 +504,15 @@ internal class FeaturesResources { } } + /// + /// Looks up a localized string similar to Camel Case. + /// + internal static string Camel_Case { + get { + return ResourceManager.GetString("Camel_Case", resourceCulture); + } + } + /// /// Looks up a localized string similar to can't not construct final tree. /// @@ -1026,6 +1044,15 @@ internal class FeaturesResources { } } + /// + /// Looks up a localized string similar to First word capitalized. + /// + internal static string First_word_capitalized { + get { + return ResourceManager.GetString("First_word_capitalized", resourceCulture); + } + } + /// /// Looks up a localized string similar to Fix all occurrences. /// @@ -1948,6 +1975,15 @@ internal class FeaturesResources { } } + /// + /// Looks up a localized string similar to Naming rule violation: {0}. + /// + internal static string Naming_rule_violation_0 { + get { + return ResourceManager.GetString("Naming_rule_violation_0", resourceCulture); + } + } + /// /// Looks up a localized string similar to Naming Styles. /// @@ -2076,6 +2112,15 @@ internal class FeaturesResources { } } + /// + /// Looks up a localized string similar to Pascal Case. + /// + internal static string Pascal_Case { + get { + return ResourceManager.GetString("Pascal_Case", resourceCulture); + } + } + /// /// Looks up a localized string similar to <Pending>. /// diff --git a/src/Features/Core/Portable/FeaturesResources.resx b/src/Features/Core/Portable/FeaturesResources.resx index e1d7828af609c7296e68eff41e5be25d505b82f7..b4f50b482151999fcc7c8a411dd480e346c5dcaa 100644 --- a/src/Features/Core/Portable/FeaturesResources.resx +++ b/src/Features/Core/Portable/FeaturesResources.resx @@ -897,8 +897,8 @@ Do you want to continue? Fix Name Violation: {0} - - '{0}' naming violation - {1} + + Naming rule violation: {0} {0} is the rule title, {1} is the way in which the rule was violated @@ -1139,4 +1139,19 @@ This version used in: {2} Snippets + + All lowercase + + + All uppercase + + + Camel Case + + + First word capitalized + + + Pascal Case + \ No newline at end of file diff --git a/src/Features/Core/Portable/SymbolCategorization/ExportSymbolCategorizerAttribute.cs b/src/Features/Core/Portable/SymbolCategorization/ExportSymbolCategorizerAttribute.cs deleted file mode 100644 index 6c0c60f18ecb3e3f9cb0033f582a717fe32bc497..0000000000000000000000000000000000000000 --- a/src/Features/Core/Portable/SymbolCategorization/ExportSymbolCategorizerAttribute.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Composition; - -namespace Microsoft.CodeAnalysis.SymbolCategorization -{ - [MetadataAttribute] - [AttributeUsage(AttributeTargets.Class)] - internal sealed class ExportSymbolCategorizerAttribute : ExportAttribute - { - public ExportSymbolCategorizerAttribute() : base(typeof(ISymbolCategorizer)) - { - } - } -} \ No newline at end of file diff --git a/src/Features/Core/Portable/SymbolCategorization/ISymbolCategorizationService.cs b/src/Features/Core/Portable/SymbolCategorization/ISymbolCategorizationService.cs deleted file mode 100644 index 9561165e3278574692d4e74691a8ad367c1e7064..0000000000000000000000000000000000000000 --- a/src/Features/Core/Portable/SymbolCategorization/ISymbolCategorizationService.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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.Collections.Immutable; -using Microsoft.CodeAnalysis.Host; - -namespace Microsoft.CodeAnalysis.SymbolCategorization -{ - internal interface ISymbolCategorizationService : IWorkspaceService - { - ImmutableArray GetCategorizers(); - } -} diff --git a/src/Features/Core/Portable/SymbolCategorization/ISymbolCategorizer.cs b/src/Features/Core/Portable/SymbolCategorization/ISymbolCategorizer.cs deleted file mode 100644 index 753838ccf7f666943dbf35d2c715607d12e7a456..0000000000000000000000000000000000000000 --- a/src/Features/Core/Portable/SymbolCategorization/ISymbolCategorizer.cs +++ /dev/null @@ -1,19 +0,0 @@ -// 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.Collections.Immutable; - -namespace Microsoft.CodeAnalysis.SymbolCategorization -{ - internal interface ISymbolCategorizer - { - /// - /// Returns the set of categories that this categorizer is capable of producing. - /// - ImmutableArray SupportedCategories { get; } - - /// - /// Returns the set of categories that apply to the given symbol. - /// - ImmutableArray Categorize(ISymbol symbol); - } -} diff --git a/src/Features/Core/Portable/SymbolCategorization/SymbolCategorizationService.cs b/src/Features/Core/Portable/SymbolCategorization/SymbolCategorizationService.cs deleted file mode 100644 index bdc02099a2f43e6ad302fba6827aa62f45c078b7..0000000000000000000000000000000000000000 --- a/src/Features/Core/Portable/SymbolCategorization/SymbolCategorizationService.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Composition; -using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.Host.Mef; - -namespace Microsoft.CodeAnalysis.SymbolCategorization -{ - [ExportWorkspaceServiceFactory(typeof(ISymbolCategorizationService)), Shared] - internal class SymbolCategorizationServiceFactory : IWorkspaceServiceFactory - { - private readonly SymbolCategorizationService service; - - [ImportingConstructor] - public SymbolCategorizationServiceFactory([ImportMany] IEnumerable symbolCategorizers) - { - service = new SymbolCategorizationService(symbolCategorizers); - } - - public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices) - { - return service; - } - - internal class SymbolCategorizationService : ISymbolCategorizationService - { - private ImmutableArray _symbolCategorizers; - - public SymbolCategorizationService(IEnumerable symbolCategorizers) - { - this._symbolCategorizers = symbolCategorizers.ToImmutableArray(); - } - - public ImmutableArray GetCategorizers() - { - return _symbolCategorizers; - } - } - } -} diff --git a/src/Features/Core/Portable/SymbolCategorization/ThreadLocalSymbolCategorizer.cs b/src/Features/Core/Portable/SymbolCategorization/ThreadLocalSymbolCategorizer.cs deleted file mode 100644 index 736e316a753932d900381e87ec4778f2d04d61dd..0000000000000000000000000000000000000000 --- a/src/Features/Core/Portable/SymbolCategorization/ThreadLocalSymbolCategorizer.cs +++ /dev/null @@ -1,30 +0,0 @@ -// 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.Collections.Immutable; -using System.Linq; - -namespace Microsoft.CodeAnalysis.SymbolCategorization -{ - // Motivating example for ISymbolCategorizer - // [ExportSymbolCategorizer, Shared] - internal class ThreadLocalSymbolCategorizer : ISymbolCategorizer - { - private const string _threadLocalCategoryName = "[ThreadStatic]"; - private readonly ImmutableArray matchingCategoryArray = new[] { _threadLocalCategoryName }.ToImmutableArray(); - - public ImmutableArray SupportedCategories - { - get - { - return matchingCategoryArray; - } - } - - public ImmutableArray Categorize(ISymbol symbol) - { - return symbol.GetAttributes().Any(a => a.AttributeClass.MetadataName.Contains("ThreadStatic")) - ? matchingCategoryArray - : ImmutableArray.Empty; - } - } -} diff --git a/src/VisualStudio/CSharp/Impl/CSharpVisualStudio.csproj b/src/VisualStudio/CSharp/Impl/CSharpVisualStudio.csproj index c8be592c71278c1e36d1f23ab3715af4d0ab1f54..519a8d1f58e23cfa2b70eed6b2920cf5642b0b8f 100644 --- a/src/VisualStudio/CSharp/Impl/CSharpVisualStudio.csproj +++ b/src/VisualStudio/CSharp/Impl/CSharpVisualStudio.csproj @@ -92,6 +92,7 @@ + diff --git a/src/VisualStudio/CSharp/Impl/Options/NamingStylesOptionPage.cs b/src/VisualStudio/CSharp/Impl/Options/NamingStylesOptionPage.cs index d6fc8105aface5872604f853fee4633626fd02a4..9753353c4be8c10540f94fa2273fbfb294268e7a 100644 --- a/src/VisualStudio/CSharp/Impl/Options/NamingStylesOptionPage.cs +++ b/src/VisualStudio/CSharp/Impl/Options/NamingStylesOptionPage.cs @@ -1,19 +1,42 @@ // 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.ComponentModel; using System.Runtime.InteropServices; +using System.Windows; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Notification; +using Microsoft.VisualStudio.ComponentModelHost; using Microsoft.VisualStudio.LanguageServices.Implementation.Options; -using Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences; +using Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style; namespace Microsoft.VisualStudio.LanguageServices.CSharp.Options { [Guid(Guids.CSharpOptionPageNamingStyleIdString)] internal class NamingStylesOptionPage : AbstractOptionPage { + private NamingStyleOptionPageControl _grid; + private INotificationService _notificationService; + protected override AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider) { - return new NamingStylesOptionPageControl(serviceProvider, LanguageNames.CSharp); + var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); + var workspace = componentModel.GetService(); + _notificationService = workspace.Services.GetService(); + + _grid = new NamingStyleOptionPageControl(serviceProvider, _notificationService, LanguageNames.CSharp); + return _grid; + } + + protected override void OnDeactivate(CancelEventArgs e) + { + if (_grid.ContainsErrors()) + { + e.Cancel = true; + _notificationService.SendNotification(ServicesVSResources.Some_naming_rules_are_incomplete_Please_complete_or_remove_them); + } + + base.OnDeactivate(e); } } } diff --git a/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs b/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs index aea1d35be251a1400e9b9cb31a76f4e74d32b7b2..cdd5777d6be98e35364ff6c064de715b8108dad4 100644 --- a/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs +++ b/src/VisualStudio/Core/Def/ServicesVSResources.Designer.cs @@ -451,15 +451,6 @@ internal class ServicesVSResources { } } - /// - /// Looks up a localized string similar to Custom Tags (must match all). - /// - internal static string Custom_Tags_must_match_all { - get { - return ResourceManager.GetString("Custom_Tags_must_match_all", resourceCulture); - } - } - /// /// Looks up a localized string similar to Debugger. /// @@ -977,6 +968,24 @@ internal class ServicesVSResources { } } + /// + /// Looks up a localized string similar to Manage specifications. + /// + internal static string Manage_specifications { + get { + return ResourceManager.GetString("Manage_specifications", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Manage styles. + /// + internal static string Manage_styles { + get { + return ResourceManager.GetString("Manage_styles", resourceCulture); + } + } + /// /// Looks up a localized string similar to Maximum number of documents are open.. /// @@ -1488,6 +1497,15 @@ internal class ServicesVSResources { } } + /// + /// Looks up a localized string similar to Reorder. + /// + internal static string Reorder { + get { + return ResourceManager.GetString("Reorder", resourceCulture); + } + } + /// /// Looks up a localized string similar to Required Prefix:. /// @@ -1569,6 +1587,15 @@ internal class ServicesVSResources { } } + /// + /// Looks up a localized string similar to Severity. + /// + internal static string Severity { + get { + return ResourceManager.GetString("Severity", resourceCulture); + } + } + /// /// Looks up a localized string similar to Severity:. /// @@ -1632,6 +1659,33 @@ internal class ServicesVSResources { } } + /// + /// Looks up a localized string similar to Some naming rules are incomplete. Please complete or remove them.. + /// + internal static string Some_naming_rules_are_incomplete_Please_complete_or_remove_them { + get { + return ResourceManager.GetString("Some_naming_rules_are_incomplete_Please_complete_or_remove_them", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Specification. + /// + internal static string Specification { + get { + return ResourceManager.GetString("Specification", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Style. + /// + internal static string Style { + get { + return ResourceManager.GetString("Style", resourceCulture); + } + } + /// /// Looks up a localized string similar to Summary:. /// @@ -1769,6 +1823,15 @@ internal class ServicesVSResources { } } + /// + /// Looks up a localized string similar to This item cannot be deleted because it is used by an existing Naming Rule.. + /// + internal static string This_item_cannot_be_deleted_because_it_is_used_by_an_existing_Naming_Rule { + get { + return ResourceManager.GetString("This_item_cannot_be_deleted_because_it_is_used_by_an_existing_Naming_Rule", resourceCulture); + } + } + /// /// Looks up a localized string similar to This workspace only supports opening documents on the UI thread.. /// diff --git a/src/VisualStudio/Core/Def/ServicesVSResources.resx b/src/VisualStudio/Core/Def/ServicesVSResources.resx index c8b561f00710edb3488cd013856e0debf5f10ede..2472c011a6332c90901b98643840bc59abaaca63 100644 --- a/src/VisualStudio/Core/Def/ServicesVSResources.resx +++ b/src/VisualStudio/Core/Def/ServicesVSResources.resx @@ -567,9 +567,6 @@ Use the dropdown to view and switch to other projects this file may belong to. Pascal Case Name - - Custom Tags (must match all) - Severity: @@ -762,4 +759,28 @@ Additional information: {1} Prefer inlined variable declaration + + Some naming rules are incomplete. Please complete or remove them. + + + Manage specifications + + + Manage styles + + + Reorder + + + Severity + + + Specification + + + Style + + + This item cannot be deleted because it is used by an existing Naming Rule. + \ No newline at end of file diff --git a/src/VisualStudio/Core/Impl/Options/AbstractOptionPage.cs b/src/VisualStudio/Core/Impl/Options/AbstractOptionPage.cs index 239c5b275e73a7e946677dbe00c2e0f984d68ba5..73ad4bc826864ca13690713705895ae5551196a0 100644 --- a/src/VisualStudio/Core/Impl/Options/AbstractOptionPage.cs +++ b/src/VisualStudio/Core/Impl/Options/AbstractOptionPage.cs @@ -10,14 +10,14 @@ internal abstract class AbstractOptionPage : UIElementDialogPage { protected abstract AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider); - private AbstractOptionPageControl _pageControl; + protected AbstractOptionPageControl pageControl; private bool _needsLoadOnNextActivate = true; private void EnsureOptionPageCreated() { - if (_pageControl == null) + if (pageControl == null) { - _pageControl = CreateOptionPage(this.Site); + pageControl = CreateOptionPage(this.Site); } } @@ -26,7 +26,7 @@ protected override System.Windows.UIElement Child get { EnsureOptionPageCreated(); - return _pageControl; + return pageControl; } } @@ -35,7 +35,7 @@ protected override void OnActivate(System.ComponentModel.CancelEventArgs e) if (_needsLoadOnNextActivate) { EnsureOptionPageCreated(); - _pageControl.LoadSettings(); + pageControl.LoadSettings(); _needsLoadOnNextActivate = false; } @@ -61,7 +61,7 @@ public override void LoadSettingsFromStorage() public override void SaveSettingsToStorage() { EnsureOptionPageCreated(); - _pageControl.SaveSettings(); + pageControl.SaveSettings(); // Make sure we load the next time the page is activated, in case if options changed // programmatically between now and the next time the page is activated @@ -72,9 +72,9 @@ protected override void OnClosed(EventArgs e) { base.OnClosed(e); - if (_pageControl != null) + if (pageControl != null) { - _pageControl.Close(); + pageControl.Close(); } } } diff --git a/src/VisualStudio/Core/Impl/Options/AbstractOptionPageControl.cs b/src/VisualStudio/Core/Impl/Options/AbstractOptionPageControl.cs index 8be6f6a79daa369a32205852a2a423f358aa7425..28b18745a34dd41b7abaaa648ae1adf1bb116901 100644 --- a/src/VisualStudio/Core/Impl/Options/AbstractOptionPageControl.cs +++ b/src/VisualStudio/Core/Impl/Options/AbstractOptionPageControl.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -19,11 +20,20 @@ public abstract class AbstractOptionPageControl : UserControl public AbstractOptionPageControl(IServiceProvider serviceProvider) { - var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); + InitializeStyles(); + + if (DesignerProperties.GetIsInDesignMode(this)) + { + return; + } + var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); var workspace = componentModel.GetService(); this.OptionService = workspace.Services.GetService(); + } + private void InitializeStyles() + { var groupBoxStyle = new System.Windows.Style(typeof(GroupBox)); groupBoxStyle.Setters.Add(new Setter(GroupBox.PaddingProperty, new Thickness() { Left = 7, Right = 7, Top = 7 })); groupBoxStyle.Setters.Add(new Setter(GroupBox.MarginProperty, new Thickness() { Bottom = 3 })); diff --git a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/EnforcementLevel.cs b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/EnforcementLevel.cs index f233e9ac7d3f0594238626e57dc9878b05211d27..6585bbf6fa86f8f584970f57ff9a7a3057d3c12f 100644 --- a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/EnforcementLevel.cs +++ b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/EnforcementLevel.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +// 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 Microsoft.CodeAnalysis; using Microsoft.VisualStudio.Imaging; using Microsoft.VisualStudio.Imaging.Interop; diff --git a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/IManageNamingStylesInfoDialogViewModel.cs b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/IManageNamingStylesInfoDialogViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..f29692c0b1bbf2aac8488a35fcd12b33e66e9194 --- /dev/null +++ b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/IManageNamingStylesInfoDialogViewModel.cs @@ -0,0 +1,15 @@ +// 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.Collections.ObjectModel; + +namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences +{ + internal interface IManageNamingStylesInfoDialogViewModel + { + ObservableCollection Items { get; } + string DialogTitle { get; } + void AddItem(); + void RemoveItem(INamingStylesInfoDialogViewModel item); + void EditItem(INamingStylesInfoDialogViewModel item); + } +} diff --git a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/NamingRuleTreeItemViewModel.InteractionPatternProvider.cs b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/INamingStylesInfoDialogViewModel.cs similarity index 52% rename from src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/NamingRuleTreeItemViewModel.InteractionPatternProvider.cs rename to src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/INamingStylesInfoDialogViewModel.cs index 1f119cb3d9c56ab66633adf8d564e67fcc114708..c8284d8256db28bc18a0f94d3f13e7a45b79ad42 100644 --- a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/NamingRuleTreeItemViewModel.InteractionPatternProvider.cs +++ b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/INamingStylesInfoDialogViewModel.cs @@ -1,14 +1,10 @@ // 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 Microsoft.Internal.VisualStudio.PlatformUI; - namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences { - partial class NamingRuleTreeItemViewModel : IInteractionPatternProvider + internal interface INamingStylesInfoDialogViewModel { - TPattern IInteractionPatternProvider.GetPattern() - { - return this as TPattern; - } + string ItemName { get; set; } + bool CanBeDeleted { get; set; } } -} +} \ No newline at end of file diff --git a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/ManageNamingStylesInfoDialog.xaml b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/ManageNamingStylesInfoDialog.xaml new file mode 100644 index 0000000000000000000000000000000000000000..6baf22848bc4157bea3d216a74736a2632799b2b --- /dev/null +++ b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/ManageNamingStylesInfoDialog.xaml @@ -0,0 +1,206 @@ + + + + + 9,2,9,2 + + + + + + + + 8 0 8 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/ManageNamingStylesInfoDialog.xaml.cs b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/ManageNamingStylesInfoDialog.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..aea8fc23b7e6e170bae958fa141e21ea63ed7986 --- /dev/null +++ b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/ManageNamingStylesInfoDialog.xaml.cs @@ -0,0 +1,58 @@ +// 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.Windows; +using System.Windows.Controls; +using Microsoft.CodeAnalysis.Notification; +using Microsoft.VisualStudio.PlatformUI; + +namespace Microsoft.VisualStudio.LanguageServices.Implementation.Options.Style.NamingPreferences +{ + /// + /// Interaction logic for NamingStyleDialog.xaml + /// + internal partial class ManageNamingStylesInfoDialog : DialogWindow + { + private readonly IManageNamingStylesInfoDialogViewModel _viewModel; + + public string OK => ServicesVSResources.OK; + public string Cancel => ServicesVSResources.Cancel; + public string CannotBeDeletedExplanation => ServicesVSResources.This_item_cannot_be_deleted_because_it_is_used_by_an_existing_Naming_Rule; + + internal ManageNamingStylesInfoDialog(IManageNamingStylesInfoDialogViewModel viewModel) + { + _viewModel = viewModel; + + InitializeComponent(); + DataContext = viewModel; + } + + private void AddButton_Click(object sender, RoutedEventArgs e) + { + _viewModel.AddItem(); + } + + private void RemoveButton_Click(object sender, RoutedEventArgs e) + { + var button = (Button)sender; + var item = button.DataContext as INamingStylesInfoDialogViewModel; + _viewModel.RemoveItem(item); + } + + private void EditButton_Click(object sender, RoutedEventArgs e) + { + var button = (Button)sender; + var item = button.DataContext as INamingStylesInfoDialogViewModel; + _viewModel.EditItem(item); + } + + private void OK_Click(object sender, RoutedEventArgs e) + { + DialogResult = true; + } + + private void Cancel_Click(object sender, RoutedEventArgs e) + { + DialogResult = false; + } + } +} diff --git a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/NamingRuleDialog.xaml b/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/NamingRuleDialog.xaml deleted file mode 100644 index 9237466cb9afcad2ecada2723ae43936f6658d03..0000000000000000000000000000000000000000 --- a/src/VisualStudio/Core/Impl/Options/Style/NamingPreferences/NamingRuleDialog.xaml +++ /dev/null @@ -1,141 +0,0 @@ - - - - 0, 5, 0, 2 - 9,2,9,2 - 9,2,9,2 - 2 - - - - - - - - - - - - - - - - - - - -