From 3eab3f4150116be169b740582e02b546ffd9ed7f Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Tue, 17 Nov 2020 15:49:22 -0800 Subject: [PATCH] Tag items in tooltips consistenly with respect to document classification (such colors, much wow) (#9563) --- Common/RoslynHelpers.fs | 67 ++++++++++++++++++------------------ LanguageService/Tokenizer.fs | 5 ++- QuickInfo/Views.fs | 63 +++++++++++++++++---------------- 3 files changed, 71 insertions(+), 64 deletions(-) diff --git a/Common/RoslynHelpers.fs b/Common/RoslynHelpers.fs index c219d571550..6a905dbab35 100644 --- a/Common/RoslynHelpers.fs +++ b/Common/RoslynHelpers.fs @@ -51,39 +51,40 @@ module RoslynHelpers = /// maps from `LayoutTag` of the F# Compiler to Roslyn `TextTags` for use in tooltips let roslynTag = function - | LayoutTag.ActivePatternCase - | LayoutTag.ActivePatternResult - | LayoutTag.UnionCase - | LayoutTag.Enum -> TextTags.Enum - | LayoutTag.Alias - | LayoutTag.Class - | LayoutTag.Union - | LayoutTag.Record - | LayoutTag.UnknownType -> TextTags.Class - | LayoutTag.Delegate -> TextTags.Delegate - | LayoutTag.Event -> TextTags.Event - | LayoutTag.Field -> TextTags.Field - | LayoutTag.Interface -> TextTags.Interface - | LayoutTag.Struct -> TextTags.Struct - | LayoutTag.Keyword -> TextTags.Keyword - | LayoutTag.Local -> TextTags.Local - | LayoutTag.Member - | LayoutTag.ModuleBinding - | LayoutTag.RecordField - | LayoutTag.Property -> TextTags.Property - | LayoutTag.Method -> TextTags.Method - | LayoutTag.Namespace -> TextTags.Namespace - | LayoutTag.Module -> TextTags.Module - | LayoutTag.LineBreak -> TextTags.LineBreak - | LayoutTag.Space -> TextTags.Space - | LayoutTag.NumericLiteral -> TextTags.NumericLiteral - | LayoutTag.Operator -> TextTags.Operator - | LayoutTag.Parameter -> TextTags.Parameter - | LayoutTag.TypeParameter -> TextTags.TypeParameter - | LayoutTag.Punctuation -> TextTags.Punctuation - | LayoutTag.StringLiteral -> TextTags.StringLiteral - | LayoutTag.Text - | LayoutTag.UnknownEntity -> TextTags.Text + | LayoutTag.ActivePatternCase + | LayoutTag.ActivePatternResult + | LayoutTag.UnionCase + | LayoutTag.Enum -> TextTags.Enum + | LayoutTag.Struct -> TextTags.Struct + | LayoutTag.TypeParameter -> TextTags.TypeParameter + | LayoutTag.Alias + | LayoutTag.Class + | LayoutTag.Union + | LayoutTag.Record + | LayoutTag.UnknownType // Default to class until/unless we use classification data + | LayoutTag.Module -> TextTags.Class + | LayoutTag.Interface -> TextTags.Interface + | LayoutTag.Keyword -> TextTags.Keyword + | LayoutTag.Member + | LayoutTag.Function + | LayoutTag.Method -> TextTags.Method + | LayoutTag.RecordField + | LayoutTag.Property -> TextTags.Property + | LayoutTag.Parameter // parameter? + | LayoutTag.Local -> TextTags.Local + | LayoutTag.Namespace -> TextTags.Namespace + | LayoutTag.Delegate -> TextTags.Delegate + | LayoutTag.Event -> TextTags.Event + | LayoutTag.Field -> TextTags.Field + | LayoutTag.LineBreak -> TextTags.LineBreak + | LayoutTag.Space -> TextTags.Space + | LayoutTag.NumericLiteral -> TextTags.NumericLiteral + | LayoutTag.Operator -> TextTags.Operator + | LayoutTag.StringLiteral -> TextTags.StringLiteral + | LayoutTag.Punctuation -> TextTags.Punctuation + | LayoutTag.Text + | LayoutTag.ModuleBinding // why no 'Identifier'? Does it matter? + | LayoutTag.UnknownEntity -> TextTags.Text let CollectTaggedText (list: List<_>) (t:TaggedText) = list.Add(TaggedText(roslynTag t.Tag, t.Text)) diff --git a/LanguageService/Tokenizer.fs b/LanguageService/Tokenizer.fs index ad85da00adf..2881818c446 100644 --- a/LanguageService/Tokenizer.fs +++ b/LanguageService/Tokenizer.fs @@ -244,7 +244,10 @@ module internal Tokenizer = | Protected -> KnownImageIds.ClassProtected | Private -> KnownImageIds.ClassPrivate | _ -> KnownImageIds.None - ImageId(KnownImageIds.ImageCatalogGuid, imageId) + if imageId = KnownImageIds.None then + None + else + Some(ImageId(KnownImageIds.ImageCatalogGuid, imageId)) let GetGlyphForSymbol (symbol: FSharpSymbol, kind: LexerSymbolKind) = match kind with diff --git a/QuickInfo/Views.fs b/QuickInfo/Views.fs index 96866890687..6274d9c9346 100644 --- a/QuickInfo/Views.fs +++ b/QuickInfo/Views.fs @@ -17,40 +17,41 @@ module internal QuickInfoViewProvider = | ActivePatternCase | ActivePatternResult | UnionCase - | Enum -> ClassificationTypeNames.EnumName // Roslyn-style classification name + | Enum -> ClassificationTypeNames.EnumName + | Struct -> ClassificationTypeNames.StructName + | TypeParameter -> ClassificationTypeNames.TypeParameterName | Alias | Class - | Module | Record - | Struct - | TypeParameter | Union - | UnknownType -> PredefinedClassificationTypeNames.Type - | Interface -> ClassificationTypeNames.InterfaceName // Roslyn-style classification name - | Keyword -> PredefinedClassificationTypeNames.Keyword - | Delegate - | Event - | Field - | Local + | UnknownType // Default to class until/unless we use classification data + | Module -> ClassificationTypeNames.ClassName + | Interface -> ClassificationTypeNames.InterfaceName + | Keyword -> ClassificationTypeNames.Keyword | Member - | Method - | ModuleBinding - | Namespace - | Parameter + | Function + | Method -> ClassificationTypeNames.MethodName | Property - | RecordField -> PredefinedClassificationTypeNames.Identifier + | RecordField -> ClassificationTypeNames.PropertyName + | Parameter + | Local -> ClassificationTypeNames.LocalName + | ModuleBinding -> ClassificationTypeNames.Identifier + | Namespace -> ClassificationTypeNames.NamespaceName + | Delegate -> ClassificationTypeNames.DelegateName + | Event -> ClassificationTypeNames.EventName + | Field -> ClassificationTypeNames.FieldName | LineBreak - | Space -> PredefinedClassificationTypeNames.WhiteSpace - | NumericLiteral -> PredefinedClassificationTypeNames.Number - | Operator -> PredefinedClassificationTypeNames.Operator - | StringLiteral -> PredefinedClassificationTypeNames.String - | Punctuation - | Text - | UnknownEntity -> PredefinedClassificationTypeNames.Other + | Space -> ClassificationTypeNames.WhiteSpace + | NumericLiteral -> ClassificationTypeNames.NumericLiteral + | Operator -> ClassificationTypeNames.Operator + | StringLiteral -> ClassificationTypeNames.StringLiteral + | Punctuation -> ClassificationTypeNames.Punctuation + | UnknownEntity + | Text -> ClassificationTypeNames.Text let provideContent ( - imageId:ImageId, + imageId:ImageId option, description:#seq, documentation:#seq, navigation:QuickInfoNavigation @@ -91,9 +92,11 @@ module internal QuickInfoViewProvider = flushContainer() ContainerElement(ContainerElementStyle.Stacked, finalCollection |> Seq.map box) - ContainerElement(ContainerElementStyle.Stacked, - ContainerElement(ContainerElementStyle.Wrapped, - ImageElement(imageId), - buildContainerElement description), - buildContainerElement documentation - ) + let innerElement = + match imageId with + | Some imageId -> + ContainerElement(ContainerElementStyle.Wrapped, ImageElement(imageId), buildContainerElement description) + | None -> + ContainerElement(ContainerElementStyle.Wrapped, buildContainerElement description) + + ContainerElement(ContainerElementStyle.Stacked, innerElement, buildContainerElement documentation)