@@ -37,26 +37,26 @@ type private SourceTextData(lines: int) =
3737type internal FSharpColorizationService () =
3838
3939 static let DataCache = ConditionalWeakTable< SourceText, SourceTextData>()
40+
41+ static let compilerTokenToRoslynToken ( colorKind : FSharpTokenColorKind ) : string =
42+ match colorKind with
43+ | FSharpTokenColorKind.Comment -> ClassificationTypeNames.Comment
44+ | FSharpTokenColorKind.Identifier -> ClassificationTypeNames.Identifier
45+ | FSharpTokenColorKind.Keyword -> ClassificationTypeNames.Keyword
46+ | FSharpTokenColorKind.String -> ClassificationTypeNames.StringLiteral
47+ | FSharpTokenColorKind.Text -> ClassificationTypeNames.Text
48+ | FSharpTokenColorKind.UpperIdentifier -> ClassificationTypeNames.Identifier
49+ | FSharpTokenColorKind.Number -> ClassificationTypeNames.NumericLiteral
50+ | FSharpTokenColorKind.InactiveCode -> ClassificationTypeNames.ExcludedCode
51+ | FSharpTokenColorKind.PreprocessorKeyword -> ClassificationTypeNames.PreprocessorKeyword
52+ | FSharpTokenColorKind.Operator -> ClassificationTypeNames.Operator
53+ | FSharpTokenColorKind.TypeName -> ClassificationTypeNames.ClassName
54+ | FSharpTokenColorKind.Default | _ -> ClassificationTypeNames.Text
4055
4156 static let scanSourceLine ( sourceTokenizer : FSharpSourceTokenizer , textLine : TextLine , lineContents : string , lexState : FSharpTokenizerLexState ) : SourceLineData =
4257
4358 let colorMap = Array.create textLine.Span.Length ClassificationTypeNames.Text
4459 let lineTokenizer = sourceTokenizer.CreateLineTokenizer( lineContents)
45-
46- let compilerTokenToRoslynToken ( colorKind : FSharpTokenColorKind ) : string =
47- match colorKind with
48- | FSharpTokenColorKind.Comment -> ClassificationTypeNames.Comment
49- | FSharpTokenColorKind.Identifier -> ClassificationTypeNames.Identifier
50- | FSharpTokenColorKind.Keyword -> ClassificationTypeNames.Keyword
51- | FSharpTokenColorKind.String -> ClassificationTypeNames.StringLiteral
52- | FSharpTokenColorKind.Text -> ClassificationTypeNames.Text
53- | FSharpTokenColorKind.UpperIdentifier -> ClassificationTypeNames.Identifier
54- | FSharpTokenColorKind.Number -> ClassificationTypeNames.NumericLiteral
55- | FSharpTokenColorKind.InactiveCode -> ClassificationTypeNames.ExcludedCode
56- | FSharpTokenColorKind.PreprocessorKeyword -> ClassificationTypeNames.PreprocessorKeyword
57- | FSharpTokenColorKind.Operator -> ClassificationTypeNames.Operator
58- | FSharpTokenColorKind.TypeName -> ClassificationTypeNames.ClassName
59- | FSharpTokenColorKind.Default | _ -> ClassificationTypeNames.Text
6060
6161 let scanAndColorNextToken ( lineTokenizer : FSharpLineTokenizer , lexState : Ref < FSharpTokenizerLexState >) : Option < FSharpTokenInfo > =
6262 let tokenInfoOption , nextLexState = lineTokenizer.ScanToken( lexState.Value)
@@ -144,17 +144,14 @@ type internal FSharpColorizationService() =
144144 | None -> ()
145145 , cancellationToken)
146146
147- // FSROSLYNTODO: Due to issue 12732 on Roslyn side, semantic classification is tied to C#/VB only.
148- // Once that is exposed to F#, enable the below code path, and add tests accourdingly.
149- member this.AddSemanticClassificationsAsync ( _ , _ , _ , _ ) =
150- (*
147+ member this.AddSemanticClassificationsAsync ( document : Document , textSpan : TextSpan , result : List < ClassifiedSpan >, cancellationToken : CancellationToken ) =
151148 let computation = async {
152- try
153- let options = CommonRoslynHelpers.GetFSharpProjectOptionsForRoslynProject(document.Project)
149+ match FSharpLanguageService.GetOptions ( document.Project.Id ) with
150+ | Some ( options ) ->
154151 let! sourceText = document.GetTextAsync( cancellationToken) |> Async.AwaitTask
155152 let! parseResults = FSharpChecker.Instance.ParseFileInProject( document.Name, sourceText.ToString(), options)
156153 let! textVersion = document.GetTextVersionAsync( cancellationToken) |> Async.AwaitTask
157- let! checkResultsAnswer = FSharpChecker.Instance.CheckFileInProject(parseResults, document.Name , textVersion.GetHashCode(), textSpan.ToString(), options)
154+ let! checkResultsAnswer = FSharpChecker.Instance.CheckFileInProject( parseResults, document.FilePath , textVersion.GetHashCode(), textSpan.ToString(), options)
158155
159156 let extraColorizationData = match checkResultsAnswer with
160157 | FSharpCheckFileAnswer.Aborted -> failwith " Compilation isn't complete yet"
@@ -163,13 +160,10 @@ type internal FSharpColorizationService() =
163160 |> Seq.toList
164161
165162 result.AddRange( extraColorizationData)
166- with ex ->
167- Assert.Exception(ex)
168- raise(ex)
163+ | None -> ()
169164 }
170- Task.Run(fun () -> Async.RunSynchronously(computation, cancellationToken = cancellationToken))
171- *)
172- Task.CompletedTask
165+
166+ Task.Run( CommonRoslynHelpers.GetTaskAction( computation), cancellationToken)
173167
174168 // Do not perform classification if we don't have project options (#defines matter)
175169 member this.AdjustStaleClassification ( _ : SourceText , classifiedSpan : ClassifiedSpan ) : ClassifiedSpan = classifiedSpan
0 commit comments