Skip to content

Commit

Permalink
Tag items in tooltips consistenly with respect to document classifica…
Browse files Browse the repository at this point in the history
…tion (such colors, much wow) (dotnet#9563)
  • Loading branch information
cartermp authored and nosami committed Feb 22, 2021
1 parent a92b164 commit 3eab3f4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 64 deletions.
67 changes: 34 additions & 33 deletions Common/RoslynHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 4 additions & 1 deletion LanguageService/Tokenizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 33 additions & 30 deletions QuickInfo/Views.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Layout.TaggedText>,
documentation:#seq<Layout.TaggedText>,
navigation:QuickInfoNavigation
Expand Down Expand Up @@ -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)

0 comments on commit 3eab3f4

Please sign in to comment.