From d45496088592dacf52eef47b456ca2d2da87532c Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Tue, 23 Jun 2020 15:36:27 -0700 Subject: [PATCH] Better classification: such colors, much wow (#9511) * First go at updated classifications * More complete classification * More accurate classification that roughly matches glyph computations * Proper measure classification and tests * remove ze comments * Add clarifying comment * Distinguish property setter args from named argument labels * Color local values, don't color properties and property-like things that way * Dont't do the dumb * We can't distinguish between params and locals right now * Updates per feedback from myself * do discards right * Accessible colors for disposables + some fixes * Remove exports for things we don't do anymore * Softer green * Reduce diff --- Classification/ClassificationDefinitions.fs | 120 +++++++------------- 1 file changed, 44 insertions(+), 76 deletions(-) diff --git a/Classification/ClassificationDefinitions.fs b/Classification/ClassificationDefinitions.fs index 749c3ceed7a..1dea67f4f35 100644 --- a/Classification/ClassificationDefinitions.fs +++ b/Classification/ClassificationDefinitions.fs @@ -21,36 +21,45 @@ open FSharp.Compiler.SourceCodeServices [] module internal FSharpClassificationTypes = - let [] Function = "FSharp.Function" let [] MutableVar = "FSharp.MutableVar" - let [] Printf = "FSharp.Printf" - let [] ReferenceType = ClassificationTypeNames.ClassName - let [] Module = ClassificationTypeNames.ModuleName - let [] ValueType = ClassificationTypeNames.StructName - let [] Keyword = ClassificationTypeNames.Keyword - let [] Enum = ClassificationTypeNames.EnumName - let [] Property = "FSharp.Property" - let [] Interface = ClassificationTypeNames.InterfaceName - let [] TypeArgument = ClassificationTypeNames.TypeParameterName - let [] Operator = ClassificationTypeNames.Operator let [] Disposable = "FSharp.Disposable" let getClassificationTypeName = function - | SemanticClassificationType.ReferenceType -> ReferenceType - | SemanticClassificationType.Module -> Module - | SemanticClassificationType.ValueType -> ValueType - | SemanticClassificationType.Function -> Function + | SemanticClassificationType.MutableRecordField | SemanticClassificationType.MutableVar -> MutableVar - | SemanticClassificationType.Printf -> Printf + | SemanticClassificationType.DisposableValue + | SemanticClassificationType.DisposableType -> Disposable + | SemanticClassificationType.NameSpace -> ClassificationTypeNames.NamespaceName + | SemanticClassificationType.Exception + | SemanticClassificationType.Module + | SemanticClassificationType.Type + | SemanticClassificationType.TypeDef + | SemanticClassificationType.ConstructorForReferenceType + | SemanticClassificationType.Printf + | SemanticClassificationType.ReferenceType -> ClassificationTypeNames.ClassName + | SemanticClassificationType.ConstructorForValueType + | SemanticClassificationType.ValueType -> ClassificationTypeNames.StructName | SemanticClassificationType.ComputationExpression - | SemanticClassificationType.IntrinsicFunction -> Keyword + | SemanticClassificationType.IntrinsicFunction -> ClassificationTypeNames.Keyword | SemanticClassificationType.UnionCase - | SemanticClassificationType.Enumeration -> Enum - | SemanticClassificationType.Property -> Property - | SemanticClassificationType.Interface -> Interface - | SemanticClassificationType.TypeArgument -> TypeArgument - | SemanticClassificationType.Operator -> Operator - | SemanticClassificationType.Disposable -> Disposable + | SemanticClassificationType.Enumeration -> ClassificationTypeNames.EnumName + | SemanticClassificationType.Field + | SemanticClassificationType.UnionCaseField -> ClassificationTypeNames.FieldName + | SemanticClassificationType.Interface -> ClassificationTypeNames.InterfaceName + | SemanticClassificationType.TypeArgument -> ClassificationTypeNames.TypeParameterName + | SemanticClassificationType.Operator -> ClassificationTypeNames.Operator + | SemanticClassificationType.Function + | SemanticClassificationType.Method -> ClassificationTypeNames.MethodName + | SemanticClassificationType.ExtensionMethod -> ClassificationTypeNames.ExtensionMethodName + | SemanticClassificationType.Literal -> ClassificationTypeNames.ConstantName + | SemanticClassificationType.Property + | SemanticClassificationType.RecordFieldAsFunction + | SemanticClassificationType.RecordField -> ClassificationTypeNames.PropertyName // TODO - maybe pick something that isn't white by default like Property? + | SemanticClassificationType.NamedArgument -> ClassificationTypeNames.LabelName + | SemanticClassificationType.Event -> ClassificationTypeNames.EventName + | SemanticClassificationType.Delegate -> ClassificationTypeNames.DelegateName + | SemanticClassificationType.Value -> ClassificationTypeNames.Identifier + | SemanticClassificationType.LocalValue -> ClassificationTypeNames.LocalName module internal ClassificationDefinitions = @@ -73,13 +82,11 @@ module internal ClassificationDefinitions = let themeService = serviceProvider.GetService(typeof) :?> IVsColorThemeService themeService.CurrentTheme.ThemeId - let colorData = // name, (light, dark) - [ FSharpClassificationTypes.Function, (Colors.Black, Color.FromRgb(220uy, 220uy, 220uy)) - FSharpClassificationTypes.MutableVar, (Color.FromRgb(160uy, 128uy, 0uy), Color.FromRgb(255uy, 210uy, 28uy)) - FSharpClassificationTypes.Printf, (Color.FromRgb(43uy, 145uy, 175uy), Color.FromRgb(78uy, 220uy, 176uy)) - FSharpClassificationTypes.Property, (Colors.Black, Color.FromRgb(220uy, 220uy, 220uy)) - FSharpClassificationTypes.Disposable, (Color.FromRgb(43uy, 145uy, 175uy), Color.FromRgb(78uy, 220uy, 176uy)) ] - + let customColorData = // name, (light, dark) + [ + FSharpClassificationTypes.MutableVar, (Color.FromRgb(160uy, 128uy, 0uy), Color.FromRgb(255uy, 210uy, 28uy)) + FSharpClassificationTypes.Disposable, (Colors.Green, Color.FromRgb(2uy, 183uy, 43uy)) + ] let setColors _ = let fontAndColorStorage = serviceProvider.GetService(typeof) :?> IVsFontAndColorStorage @@ -90,15 +97,16 @@ module internal ClassificationDefinitions = let formatMap = classificationformatMapService.GetClassificationFormatMap(category = "text") try formatMap.BeginBatchUpdate() - for ctype, (light, dark) in colorData do + for ctype, (light, dark) in customColorData do // we don't touch the changes made by the user if fontAndColorStorage.GetItem(ctype, Array.zeroCreate 1) <> VSConstants.S_OK then let ict = classificationTypeRegistry.GetClassificationType(ctype) let oldProps = formatMap.GetTextProperties(ict) - let newProps = match getCurrentThemeId() with - | LightTheme -> oldProps.SetForeground light - | DarkTheme -> oldProps.SetForeground dark - | UnknownTheme -> oldProps + let newProps = + match getCurrentThemeId() with + | LightTheme -> oldProps.SetForeground light + | DarkTheme -> oldProps.SetForeground dark + | UnknownTheme -> oldProps formatMap.SetTextProperties(ict, newProps) fontAndColorStorage.CloseCategory() |> ignore finally formatMap.EndBatchUpdate() @@ -108,7 +116,7 @@ module internal ClassificationDefinitions = interface IDisposable with member __.Dispose() = VSColorTheme.remove_ThemeChanged handler member __.GetColor(ctype) = - let light, dark = colorData |> Map.ofList |> Map.find ctype + let light, dark = customColorData |> Map.ofList |> Map.find ctype match getCurrentThemeId() with | LightTheme -> Nullable light | DarkTheme -> Nullable dark @@ -116,32 +124,13 @@ module internal ClassificationDefinitions = interface ISetThemeColors with member this.SetColors() = setColors() - - [] - let FSharpFunctionClassificationType : ClassificationTypeDefinition = null - [] let FSharpMutableVarClassificationType : ClassificationTypeDefinition = null - [] - let FSharpPrintfClassificationType : ClassificationTypeDefinition = null - - [] - let FSharpPropertyClassificationType : ClassificationTypeDefinition = null [] let FSharpDisposableClassificationType : ClassificationTypeDefinition = null - [)>] - [] - [] - [] - [] - type internal FSharpFunctionTypeFormat() as self = - inherit ClassificationFormatDefinition() - - do self.DisplayName <- SR.FSharpFunctionsOrMethodsClassificationType() - [)>] [] [] @@ -153,27 +142,6 @@ module internal ClassificationDefinitions = do self.DisplayName <- SR.FSharpMutableVarsClassificationType() self.ForegroundColor <- theme.GetColor FSharpClassificationTypes.MutableVar - [)>] - [] - [] - [] - [] - type internal FSharpPrintfTypeFormat [](theme: ThemeColors) as self = - inherit ClassificationFormatDefinition() - - do self.DisplayName <- SR.FSharpPrintfFormatClassificationType() - self.ForegroundColor <- theme.GetColor FSharpClassificationTypes.Printf - - [)>] - [] - [] - [] - [] - type internal FSharpPropertyFormat() as self = - inherit ClassificationFormatDefinition() - - do self.DisplayName <- SR.FSharpPropertiesClassificationType() - [)>] [] []