From 1eae2829457795aaa087e42ad501790d66917a33 Mon Sep 17 00:00:00 2001 From: Vasily Kirichenko Date: Mon, 10 Apr 2017 18:53:23 +0300 Subject: [PATCH] fix range with step operator coloring (#2826) --- src/fsharp/vs/service.fs | 3 +- .../LanguageService/Tokenizer.fs | 53 ++++++++++++++----- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/fsharp/vs/service.fs b/src/fsharp/vs/service.fs index e11d29496..d66666a42 100644 --- a/src/fsharp/vs/service.fs +++ b/src/fsharp/vs/service.fs @@ -1579,7 +1579,8 @@ type TypeCheckInfo | CNR(_, Item.Value KeywordIntrinsicValue, ItemOccurence.Use, _, _, _, m) -> Some (m, SemanticClassificationType.IntrinsicFunction) | CNR(_, (Item.Value vref), _, _, _, _, m) when isFunction g vref.Type -> - if vref.DisplayName = "( .. )" then None // the range operator + if valRefEq g g.range_op_vref vref || valRefEq g g.range_step_op_vref vref then + None elif vref.IsPropertyGetterMethod || vref.IsPropertySetterMethod then Some (m, SemanticClassificationType.Property) elif IsOperatorName vref.DisplayName then diff --git a/vsintegration/src/FSharp.Editor/LanguageService/Tokenizer.fs b/vsintegration/src/FSharp.Editor/LanguageService/Tokenizer.fs index 17245bf98..8ac0dc7d4 100644 --- a/vsintegration/src/FSharp.Editor/LanguageService/Tokenizer.fs +++ b/vsintegration/src/FSharp.Editor/LanguageService/Tokenizer.fs @@ -288,21 +288,48 @@ module internal Tokenizer = let colorMap = Array.create textLine.Span.Length ClassificationTypeNames.Text let lineTokenizer = sourceTokenizer.CreateLineTokenizer(lineContents) let tokens = ResizeArray() + let mutable tokenInfoOption = None + let previousLexState = ref lexState - let scanAndColorNextToken(lineTokenizer: FSharpLineTokenizer, lexState: Ref) : Option = - let tokenInfoOption, nextLexState = lineTokenizer.ScanToken(lexState.Value) - lexState.Value <- nextLexState - if tokenInfoOption.IsSome then - let classificationType = compilerTokenToRoslynToken(tokenInfoOption.Value.ColorClass) - for i = tokenInfoOption.Value.LeftColumn to tokenInfoOption.Value.RightColumn do - Array.set colorMap i classificationType - tokens.Add tokenInfoOption.Value - tokenInfoOption + let processToken() = + let classificationType = compilerTokenToRoslynToken(tokenInfoOption.Value.ColorClass) + for i = tokenInfoOption.Value.LeftColumn to tokenInfoOption.Value.RightColumn do + Array.set colorMap i classificationType + tokens.Add tokenInfoOption.Value - let previousLexState = ref lexState - let mutable tokenInfoOption = scanAndColorNextToken(lineTokenizer, previousLexState) - while tokenInfoOption.IsSome do - tokenInfoOption <- scanAndColorNextToken(lineTokenizer, previousLexState) + let scanAndColorNextToken() = + let info, nextLexState = lineTokenizer.ScanToken(!previousLexState) + tokenInfoOption <- info + previousLexState := nextLexState + match info with + | Some info when info.Tag = FSharpTokenTag.INT32_DOT_DOT -> + tokenInfoOption <- + Some { LeftColumn = info.LeftColumn + RightColumn = info.RightColumn - 2 + ColorClass = FSharpTokenColorKind.Number + CharClass = FSharpTokenCharKind.Literal + FSharpTokenTriggerClass = info.FSharpTokenTriggerClass + Tag = info.Tag + TokenName = "INT32" + FullMatchedLength = info.FullMatchedLength - 2 } + processToken() + + tokenInfoOption <- + Some { LeftColumn = info.RightColumn - 1 + RightColumn = info.RightColumn + ColorClass = FSharpTokenColorKind.Operator + CharClass = FSharpTokenCharKind.Operator + FSharpTokenTriggerClass = info.FSharpTokenTriggerClass + Tag = FSharpTokenTag.DOT_DOT + TokenName = "DOT_DOT" + FullMatchedLength = 2 } + processToken() + + | Some _ -> processToken() + | _ -> () + + scanAndColorNextToken() + while tokenInfoOption.IsSome do scanAndColorNextToken() let mutable startPosition = 0 let mutable endPosition = startPosition -- GitLab