From ad0a00bbb384ce432bc7ed4850beecb4414a32e1 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 26 Mar 2018 12:31:31 -0500 Subject: [PATCH] Export classification type definitions for new classification types Fixes #25716 --- .../ClassificationTypeDefinitions.cs | 56 ++++++++++++++++++- .../ClassificationTypeNamesTests.cs | 54 ++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/EditorFeatures/Test/Workspaces/ClassificationTypeNamesTests.cs diff --git a/src/EditorFeatures/Core/Implementation/Classification/ClassificationTypeDefinitions.cs b/src/EditorFeatures/Core/Implementation/Classification/ClassificationTypeDefinitions.cs index 891e66afe52..e5863ff88b4 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 00000000000..bc809a2cda8 --- /dev/null +++ b/src/EditorFeatures/Test/Workspaces/ClassificationTypeNamesTests.cs @@ -0,0 +1,54 @@ +// 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.ComponentModel; +using System.Linq; +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) + { + Assert.IsType(constantValue); + string classificationTypeName = (string)constantValue; + var exportProvider = TestExportProvider.ExportProviderWithCSharpAndVisualBasic; + var exports = exportProvider.GetExports(); + var export = exports.FirstOrDefault(x => x.Metadata.Name == classificationTypeName); + Assert.True(export != null, $"{nameof(ClassificationTypeNames)}.{fieldName} has value \"{classificationTypeName}\", but no matching {nameof(ClassificationTypeDefinition)} was exported."); + } + + public interface IClassificationTypeDefinitionMetadata + { + string Name + { + get; + } + + [DefaultValue(null)] + IEnumerable BaseDefinition + { + get; + } + } + } +} -- GitLab