Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/CSharpLanguageServer/Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ let unwindProtect cleanupFn op =
let ClassificationTypeMap = Map [
(ClassificationTypeNames.ClassName, "class");
(ClassificationTypeNames.Comment, "comment");
(ClassificationTypeNames.ConstantName, "property");
(ClassificationTypeNames.ControlKeyword, "keyword");
(ClassificationTypeNames.DelegateName, "class");
(ClassificationTypeNames.EnumMemberName, "enumMember");
(ClassificationTypeNames.EnumName, "enum");
(ClassificationTypeNames.EventName, "event");
Expand Down Expand Up @@ -64,18 +66,22 @@ let ClassificationModifierMap = Map [
(ClassificationTypeNames.StaticSymbol, "static")
]

// flip f takes its (first) two arguments in the reverse order of f, just like
// the function with the same name in Haskell.
let flip f x y = f y x

let SemanticTokenTypeMap =
ClassificationTypeMap
|> Map.values
|> Seq.distinct
|> fun types -> Seq.zip types (Seq.initInfinite (id >> uint32)) // There is no `flip` in F#, sadly
|> flip Seq.zip (Seq.initInfinite uint32)
|> Map.ofSeq

let SemanticTokenModifierMap =
ClassificationModifierMap
|> Map.values
|> Seq.distinct
|> fun modifiers -> Seq.zip modifiers (Seq.initInfinite (id >> uint32))
|> flip Seq.zip (Seq.initInfinite uint32)
|> Map.ofSeq

let SemanticTokenTypes =
Expand All @@ -91,12 +97,12 @@ let SemanticTokenModifiers =
let GetSemanticTokenIdFromClassification (classification: string) =
ClassificationTypeMap
|> Map.tryFind classification
|> Option.bind (fun t -> Map.tryFind t SemanticTokenTypeMap)
|> Option.bind (flip Map.tryFind SemanticTokenTypeMap)

let GetSemanticTokenModifierFlagFromClassification (classification: string) =
ClassificationModifierMap
|> Map.tryFind classification
|> Option.bind (fun m -> Map.tryFind m SemanticTokenModifierMap)
|> Option.bind (flip Map.tryFind SemanticTokenModifierMap)
|> Option.defaultValue 0u
|> int32
|> (<<<) 1u