@@ -24,7 +24,7 @@ open Microsoft.VisualStudio.FSharp.LanguageService
2424type internal FSharpDocumentDiagnosticAnalyzer () =
2525 inherit DocumentDiagnosticAnalyzer()
2626
27- let fSharpErrorToRoslynDiagnostic ( document : Document , sourceText : SourceText , error : FSharpErrorInfo ) =
27+ static member ConvertError ( filePath : string , sourceText : SourceText , error : FSharpErrorInfo ) =
2828 let id = " FS" + error.ErrorNumber.ToString()
2929 let emptyString = LocalizableString.op_ Implicit( " " )
3030 let description = LocalizableString.op_ Implicit( error.Message)
@@ -33,10 +33,24 @@ type internal FSharpDocumentDiagnosticAnalyzer() =
3333
3434 let linePositionSpan = LinePositionSpan( LinePosition( error.StartLineAlternate - 1 , error.StartColumn), LinePosition( error.EndLineAlternate - 1 , error.EndColumn))
3535 let textSpan = sourceText.Lines.GetTextSpan( linePositionSpan)
36- let correctedTextSpan = if textSpan.End < sourceText.Length then textSpan else TextSpan.FromBounds( sourceText.Length - 1 , sourceText.Length)
3736
3837 // F# compiler report errors at end of file if parsing fails. It should be corrected to match Roslyn boundaries
39- Diagnostic.Create( descriptor, Location.Create( document.FilePath, correctedTextSpan , linePositionSpan))
38+ let correctedTextSpan = if textSpan.End < sourceText.Length then textSpan else TextSpan.FromBounds( sourceText.Length - 1 , sourceText.Length)
39+
40+ Diagnostic.Create( descriptor, Location.Create( filePath, correctedTextSpan , linePositionSpan))
41+
42+ static member GetDiagnostics ( filePath : string , sourceText : SourceText , options : FSharpProjectOptions , addSemanticErrors : bool ) =
43+ let parseResults = FSharpChecker.Instance.ParseFileInProject( filePath, sourceText.ToString(), options) |> Async.RunSynchronously
44+ let errors =
45+ if addSemanticErrors then
46+ let checkResultsAnswer = FSharpChecker.Instance.CheckFileInProject( parseResults, filePath, 0 , sourceText.ToString(), options) |> Async.RunSynchronously
47+ match checkResultsAnswer with
48+ | FSharpCheckFileAnswer.Aborted -> failwith " Compilation isn't complete yet"
49+ | FSharpCheckFileAnswer.Succeeded( results) -> results.Errors
50+ else
51+ parseResults.Errors
52+
53+ ( errors |> Seq.map( fun ( error ) -> FSharpDocumentDiagnosticAnalyzer.ConvertError( filePath, sourceText, error))) .ToImmutableArray()
4054
4155
4256 // We are constructing our own descriptors at run-time. Compiler service is already doing error formatting and localization.
@@ -50,9 +64,7 @@ type internal FSharpDocumentDiagnosticAnalyzer() =
5064 let computation = async {
5165 let! sourceText = document.GetTextAsync( cancellationToken) |> Async.AwaitTask
5266 let options = CommonRoslynHelpers.GetFSharpProjectOptionsForRoslynProject( document.Project)
53- let! parseResults = FSharpChecker.Instance.ParseFileInProject( document.Name, sourceText.ToString(), options)
54-
55- return ( parseResults.Errors |> Seq.map( fun ( error ) -> fSharpErrorToRoslynDiagnostic( document, sourceText, error))). ToImmutableArray()
67+ return FSharpDocumentDiagnosticAnalyzer.GetDiagnostics( document.FilePath, sourceText, options, false )
5668 }
5769
5870 Async.StartAsTask( computation, TaskCreationOptions.None, cancellationToken)
@@ -63,14 +75,7 @@ type internal FSharpDocumentDiagnosticAnalyzer() =
6375 let computation = async {
6476 let! sourceText = document.GetTextAsync( cancellationToken) |> Async.AwaitTask
6577 let options = CommonRoslynHelpers.GetFSharpProjectOptionsForRoslynProject( document.Project)
66- let! parseResults = FSharpChecker.Instance.ParseFileInProject( document.Name, sourceText.ToString(), options)
67- let! checkResultsAnswer = FSharpChecker.Instance.CheckFileInProject( parseResults, document.Name, 0 , sourceText.ToString(), options)
68-
69- let errors = match checkResultsAnswer with
70- | FSharpCheckFileAnswer.Aborted -> failwith " Compilation isn't complete yet"
71- | FSharpCheckFileAnswer.Succeeded( results) -> results.Errors
72-
73- return ( errors |> Seq.map( fun ( error ) -> fSharpErrorToRoslynDiagnostic( document, sourceText, error))). ToImmutableArray()
78+ return FSharpDocumentDiagnosticAnalyzer.GetDiagnostics( document.FilePath, sourceText, options, true )
7479 }
7580
7681 Async.StartAsTask( computation, TaskCreationOptions.None, cancellationToken)
0 commit comments