From af816832511f82458447505806a5aae44726664b Mon Sep 17 00:00:00 2001 From: Vasily Kirichenko Date: Wed, 7 Dec 2016 22:14:15 +0300 Subject: [PATCH] fixed: CommonHelpers.tryClassifyAtPosition return wrong result at the end position --- vsintegration/src/FSharp.Editor/CommonHelpers.fs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/CommonHelpers.fs b/vsintegration/src/FSharp.Editor/CommonHelpers.fs index ab7f3f45711..012d514406c 100644 --- a/vsintegration/src/FSharp.Editor/CommonHelpers.fs +++ b/vsintegration/src/FSharp.Editor/CommonHelpers.fs @@ -59,7 +59,7 @@ module CommonHelpers = | FSharpTokenColorKind.PreprocessorKeyword -> ClassificationTypeNames.PreprocessorKeyword | FSharpTokenColorKind.Operator -> ClassificationTypeNames.Operator | FSharpTokenColorKind.TypeName -> ClassificationTypeNames.ClassName - | FSharpTokenColorKind.Default + | FSharpTokenColorKind.Default | _ -> ClassificationTypeNames.Text let private scanSourceLine(sourceTokenizer: FSharpSourceTokenizer, textLine: TextLine, lineContents: string, lexState: FSharpTokenizerLexState) : SourceLineData = @@ -70,7 +70,11 @@ module CommonHelpers = let tokenInfoOption, nextLexState = lineTokenizer.ScanToken(lexState.Value) lexState.Value <- nextLexState if tokenInfoOption.IsSome then - let classificationType = compilerTokenToRoslynToken(tokenInfoOption.Value.ColorClass) + let classificationType = + if tokenInfoOption.Value.CharClass = FSharpTokenCharKind.WhiteSpace then + ClassificationTypeNames.WhiteSpace + else + compilerTokenToRoslynToken(tokenInfoOption.Value.ColorClass) for i = tokenInfoOption.Value.LeftColumn to tokenInfoOption.Value.RightColumn do Array.set colorMap i classificationType tokenInfoOption @@ -165,7 +169,12 @@ module CommonHelpers = let classifiedSpanOption = getColorizationData(documentKey, sourceText, textLine.Span, Some(filePath), defines, cancellationToken) - |> Seq.tryFind(fun classifiedSpan -> classifiedSpan.TextSpan.Contains(position)) + |> Seq.tryFind(fun classifiedSpan -> + classifiedSpan.ClassificationType <> ClassificationTypeNames.WhiteSpace && + (classifiedSpan.TextSpan.Contains(position) || + // TextSpan.Contains returns `false` for `position` equals its right bound, + // so we have to check if it contains `position - 1`. + (position > 0 && classifiedSpan.TextSpan.Contains(position - 1)))) match classifiedSpanOption with | Some(classifiedSpan) ->