Skip to content

Commit

Permalink
Merge pull request #70 from tcx4c70/feat/semantic-token
Browse files Browse the repository at this point in the history
Refactor and improvement of semantic token
  • Loading branch information
razzmatazz authored Feb 28, 2023
2 parents 0493c92 + f0bbc21 commit 65a753e
Showing 1 changed file with 10 additions and 4 deletions.
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

0 comments on commit 65a753e

Please # to comment.