Skip to content

Commit

Permalink
fixed: CommonHelpers.tryClassifyAtPosition return wrong result at the…
Browse files Browse the repository at this point in the history
… end position
  • Loading branch information
vasily-kirichenko committed Dec 7, 2016
1 parent 9b5d15d commit af81683
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions vsintegration/src/FSharp.Editor/CommonHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down Expand Up @@ -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) ->
Expand Down

0 comments on commit af81683

Please sign in to comment.