Skip to content

Commit 3380fbe

Browse files
authored
Make semantic token mapping more accurate (#1434)
* Make semantic token mapping more accurate * more * revert NamedArgument; fix test --------- Co-authored-by: ijklam <[email protected]>
1 parent 06e0c4e commit 3380fbe

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/FsAutoComplete/LspHelpers.fs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -553,30 +553,31 @@ module ClassificationUtils =
553553
(* custom modifiers *)
554554
| Mutable = 0b100_0000_0000
555555
| Disposable = 0b1000_0000_0000
556+
| Extension = 0b1_0000_0000_0000
556557

557558

558559
let map (t: SemanticClassificationType) : SemanticTokenTypes * SemanticTokenModifier list =
559560
match t with
560561
| SemanticClassificationType.Operator -> SemanticTokenTypes.Operator, []
561562
| SemanticClassificationType.ReferenceType
563+
| SemanticClassificationType.ConstructorForReferenceType -> SemanticTokenTypes.Class, []
562564
| SemanticClassificationType.Type
563-
| SemanticClassificationType.TypeDef
564-
| SemanticClassificationType.ConstructorForReferenceType -> SemanticTokenTypes.Type, []
565+
| SemanticClassificationType.TypeDef -> SemanticTokenTypes.Type, []
565566
| SemanticClassificationType.ValueType
566567
| SemanticClassificationType.ConstructorForValueType -> SemanticTokenTypes.Struct, []
567-
| SemanticClassificationType.UnionCase
568-
| SemanticClassificationType.UnionCaseField -> SemanticTokenTypes.EnumMember, []
568+
| SemanticClassificationType.UnionCase -> SemanticTokenTypes.EnumMember, []
569+
| SemanticClassificationType.UnionCaseField -> SemanticTokenTypes.Parameter, []
569570
| SemanticClassificationType.Function
570-
| SemanticClassificationType.Method
571-
| SemanticClassificationType.ExtensionMethod -> SemanticTokenTypes.Function, []
571+
| SemanticClassificationType.IntrinsicFunction -> SemanticTokenTypes.Function, []
572+
| SemanticClassificationType.Method -> SemanticTokenTypes.Method, []
573+
| SemanticClassificationType.ExtensionMethod -> SemanticTokenTypes.Method, [ SemanticTokenModifier.Extension ]
572574
| SemanticClassificationType.Property -> SemanticTokenTypes.Property, []
573-
| SemanticClassificationType.MutableVar
574-
| SemanticClassificationType.MutableRecordField -> SemanticTokenTypes.Member, [ SemanticTokenModifier.Mutable ]
575+
| SemanticClassificationType.MutableVar -> SemanticTokenTypes.Variable, [ SemanticTokenModifier.Mutable ]
576+
| SemanticClassificationType.MutableRecordField -> SemanticTokenTypes.Property, [ SemanticTokenModifier.Mutable ]
575577
| SemanticClassificationType.Module -> SemanticTokenTypes.Module, []
576578
| SemanticClassificationType.Namespace -> SemanticTokenTypes.Namespace, []
577579
| SemanticClassificationType.Printf -> SemanticTokenTypes.Regexp, []
578580
| SemanticClassificationType.ComputationExpression -> SemanticTokenTypes.Cexpr, []
579-
| SemanticClassificationType.IntrinsicFunction -> SemanticTokenTypes.Function, []
580581
| SemanticClassificationType.Enumeration -> SemanticTokenTypes.Enum, []
581582
| SemanticClassificationType.Interface -> SemanticTokenTypes.Interface, []
582583
| SemanticClassificationType.TypeArgument -> SemanticTokenTypes.TypeParameter, []

test/FsAutoComplete.Tests.Lsp/HighlightingTests.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ let tests state =
148148
"tests"
149149
[ tokenIsOfType (0u, 29u) ClassificationUtils.SemanticTokenTypes.TypeParameter fullHighlights // the `^a` type parameter in the SRTP constraint
150150
tokenIsOfType (0u, 44u) ClassificationUtils.SemanticTokenTypes.Member fullHighlights // the `PeePee` member in the SRTP constraint
151-
tokenIsOfType (3u, 52u) ClassificationUtils.SemanticTokenTypes.Type fullHighlights // the `string` type annotation in the PooPoo srtp member
151+
tokenIsOfType (3u, 52u) ClassificationUtils.SemanticTokenTypes.Class fullHighlights // the `string` type annotation in the PooPoo srtp member
152152
tokenIsOfType (6u, 21u) ClassificationUtils.SemanticTokenTypes.EnumMember fullHighlights // the `PeePee` AP application in the `yeet` function definition
153-
tokenIsOfType (9u, 10u) ClassificationUtils.SemanticTokenTypes.Type fullHighlights //the `SomeJson` type alias should be a type
153+
tokenIsOfType (9u, 10u) ClassificationUtils.SemanticTokenTypes.Class fullHighlights //the `SomeJson` type alias should be a type
154154
tokenIsOfType (15u, 2u) ClassificationUtils.SemanticTokenTypes.Module fullHighlights ] ] // tests that module coloration isn't overwritten by function coloration when a module function is used, so Foo in Foo.x should be module-colored

0 commit comments

Comments
 (0)