Skip to content

Commit c0a3f89

Browse files
author
Omar Tawfik
committed
Convert tests
1 parent da01dc0 commit c0a3f89

34 files changed

+457
-1018
lines changed

vsintegration/src/FSharp.Editor/AssemblyInfo.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open Microsoft.VisualStudio.Shell
66

77
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("FSharp.ProjectSystem.FSharp, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")>]
88
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("VisualFSharp.Unittests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")>]
9+
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("VisualFSharp.Salsa, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")>]
910

1011
[<assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\FSharp.Editor.dll")>]
1112

vsintegration/src/FSharp.Editor/DocumentDiagnosticAnalyzer.fs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ open Microsoft.VisualStudio.FSharp.LanguageService
2424
type 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)

vsintegration/tests/Salsa/FSharpLanguageServiceTestable.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ open Microsoft.VisualStudio.OLE.Interop
1717
open Microsoft.FSharp.Compiler
1818
open Microsoft.FSharp.Compiler.SourceCodeServices
1919
open Microsoft.VisualStudio.FSharp.LanguageService
20+
open Microsoft.VisualStudio.FSharp.Editor
2021

2122
type internal FSharpLanguageServiceTestable() as this =
2223
static let colorizerGuid = new Guid("{A2976312-7D71-4BB4-A5F8-66A08EBF46C8}") // Guid for colorized user data on IVsTextBuffer

vsintegration/tests/Salsa/VisualFSharp.Salsa.fsproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
<Project>{a437a6ec-5323-47c2-8f86-e2cac54ff152}</Project>
111111
<Private>True</Private>
112112
</ProjectReference>
113+
<ProjectReference Include="..\..\src\FSharp.Editor\FSharp.Editor.fsproj">
114+
<Name>FSharp.Editor</Name>
115+
<Project>{65e0e82a-eace-4787-8994-888674c2fe87}</Project>
116+
<Private>True</Private>
117+
</ProjectReference>
113118
<ProjectReference Include="..\..\src\FSharp.LanguageService.Base\FSharp.LanguageService.Base.csproj">
114119
<Name>FSharp.LanguageService.Base</Name>
115120
<Project>{1c5c163c-37ea-4a3c-8ccc-0d34b74bf8ef}</Project>

0 commit comments

Comments
 (0)