diff --git a/src/EditorFeatures/Core/Implementation/Classification/ClassificationTypeDefinitions.cs b/src/EditorFeatures/Core/Implementation/Classification/ClassificationTypeDefinitions.cs index 891e66afe5273..e5863ff88b49e 100644 --- a/src/EditorFeatures/Core/Implementation/Classification/ClassificationTypeDefinitions.cs +++ b/src/EditorFeatures/Core/Implementation/Classification/ClassificationTypeDefinitions.cs @@ -1,7 +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 System.ComponentModel.Composition; -using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis.Classification; using Microsoft.VisualStudio.Language.StandardClassification; using Microsoft.VisualStudio.Text.Classification; @@ -73,6 +72,61 @@ internal sealed class ClassificationTypeDefinitions internal readonly ClassificationTypeDefinition UserTypeTypeParametersTypeDefinition; #endregion + #region Field Name + [Export] + [Name(ClassificationTypeNames.FieldName)] + [BaseDefinition(PredefinedClassificationTypeNames.Identifier)] + internal readonly ClassificationTypeDefinition FieldNameTypeDefinition; + #endregion + #region Enum Member Name + [Export] + [Name(ClassificationTypeNames.EnumMemberName)] + [BaseDefinition(PredefinedClassificationTypeNames.Identifier)] + internal readonly ClassificationTypeDefinition EnumMemberNameTypeDefinition; + #endregion + #region Constant Name + [Export] + [Name(ClassificationTypeNames.ConstantName)] + [BaseDefinition(PredefinedClassificationTypeNames.Identifier)] + internal readonly ClassificationTypeDefinition ConstantNameTypeDefinition; + #endregion + #region Local Name + [Export] + [Name(ClassificationTypeNames.LocalName)] + [BaseDefinition(PredefinedClassificationTypeNames.Identifier)] + internal readonly ClassificationTypeDefinition LocalNameTypeDefinition; + #endregion + #region Parameter Name + [Export] + [Name(ClassificationTypeNames.ParameterName)] + [BaseDefinition(PredefinedClassificationTypeNames.Identifier)] + internal readonly ClassificationTypeDefinition ParameterNameTypeDefinition; + #endregion + #region Method Name + [Export] + [Name(ClassificationTypeNames.MethodName)] + [BaseDefinition(PredefinedClassificationTypeNames.Identifier)] + internal readonly ClassificationTypeDefinition MethodNameTypeDefinition; + #endregion + #region Extension Method Name + [Export] + [Name(ClassificationTypeNames.ExtensionMethodName)] + [BaseDefinition(PredefinedClassificationTypeNames.Identifier)] + internal readonly ClassificationTypeDefinition ExtensionMethodNameTypeDefinition; + #endregion + #region Property Name + [Export] + [Name(ClassificationTypeNames.PropertyName)] + [BaseDefinition(PredefinedClassificationTypeNames.Identifier)] + internal readonly ClassificationTypeDefinition PropertyNameTypeDefinition; + #endregion + #region Event Name + [Export] + [Name(ClassificationTypeNames.EventName)] + [BaseDefinition(PredefinedClassificationTypeNames.Identifier)] + internal readonly ClassificationTypeDefinition EventNameTypeDefinition; + #endregion + #region XML Doc Comments - Attribute Name [Export] [Name(ClassificationTypeNames.XmlDocCommentAttributeName)] diff --git a/src/EditorFeatures/Test/Workspaces/ClassificationTypeNamesTests.cs b/src/EditorFeatures/Test/Workspaces/ClassificationTypeNamesTests.cs new file mode 100644 index 0000000000000..8c7734364498a --- /dev/null +++ b/src/EditorFeatures/Test/Workspaces/ClassificationTypeNamesTests.cs @@ -0,0 +1,37 @@ +// 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.Generic; +using System.Reflection; +using Microsoft.CodeAnalysis.Classification; +using Microsoft.VisualStudio.Text.Classification; +using Roslyn.Test.Utilities; +using Xunit; + +namespace Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces +{ + public class ClassificationTypeNamesTests + { + public static IEnumerable AllClassificationTypeNames + { + get + { + foreach (var field in typeof(ClassificationTypeNames).GetFields(BindingFlags.Static | BindingFlags.Public)) + { + yield return new object[] { field.Name, field.GetRawConstantValue() }; + } + } + } + + [Theory] + [MemberData(nameof(AllClassificationTypeNames))] + [WorkItem(25716, "https://github.com/dotnet/roslyn/issues/25716")] + public void ClassificationTypeExported(string fieldName, object constantValue) + { + var classificationTypeName = Assert.IsType(constantValue); + var exportProvider = TestExportProvider.ExportProviderWithCSharpAndVisualBasic; + var classificationTypeRegistryService = exportProvider.GetExport().Value; + var classificationType = classificationTypeRegistryService.GetClassificationType(classificationTypeName); + Assert.True(classificationType != null, $"{nameof(ClassificationTypeNames)}.{fieldName} has value \"{classificationTypeName}\", but no matching {nameof(ClassificationTypeDefinition)} was exported."); + } + } +}