From 885dbdedfef3c3dece56a0e6c2edacbd91900299 Mon Sep 17 00:00:00 2001 From: Gauthier Segay Date: Sat, 11 Nov 2023 16:23:42 +0100 Subject: [PATCH 1/4] * enable warning for unused values in FSharp.Editor.Tests * fix the code so it builds * reintroduce the parsing of options in CompletionProviderTests.fs / RoslynHelpers.fs despite the outcome seems a bit underwhelming --- .../BraceMatchingServiceTests.fs | 2 +- .../CompletionProviderTests.fs | 4 ++-- .../DocumentDiagnosticAnalyzerTests.fs | 22 +++++++++---------- .../EditorFormattingServiceTests.fs | 2 +- .../FSharp.Editor.Tests.fsproj | 2 ++ .../Helpers/RoslynHelpers.fs | 16 ++++++++------ .../QuickInfoProviderTests.fs | 2 +- 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/vsintegration/tests/FSharp.Editor.Tests/BraceMatchingServiceTests.fs b/vsintegration/tests/FSharp.Editor.Tests/BraceMatchingServiceTests.fs index 8699e6fd42f..69015b9c7b9 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/BraceMatchingServiceTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/BraceMatchingServiceTests.fs @@ -32,7 +32,7 @@ type BraceMatchingServiceTests() = |> Async.RunImmediateExceptOnUI with | None -> () - | Some (left, right) -> failwith $"Found match for brace '{marker}'" + | Some _ -> failwith $"Found match for brace '{marker}'" member private this.VerifyBraceMatch(fileContents: string, startMarker: string, endMarker: string, ?langVersion: string) = let sourceText = SourceText.From(fileContents) diff --git a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs index 71fb3b0c963..b14fba13faf 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs @@ -29,7 +29,7 @@ module CompletionProviderTests = let caretPosition = fileContents.IndexOf(marker) + marker.Length let document = - RoslynTestHelpers.CreateSolution(fileContents) + RoslynTestHelpers.CreateSolution(fileContents, extraFSharpProjectOtherOptions = Array.ofSeq opts) |> RoslynTestHelpers.GetSingleDocument let results = @@ -77,7 +77,7 @@ module CompletionProviderTests = let caretPosition = fileContents.IndexOf(marker) + marker.Length let document = - RoslynTestHelpers.CreateSolution(fileContents) + RoslynTestHelpers.CreateSolution(fileContents, extraFSharpProjectOtherOptions = Array.ofSeq opts) |> RoslynTestHelpers.GetSingleDocument let actual = diff --git a/vsintegration/tests/FSharp.Editor.Tests/DocumentDiagnosticAnalyzerTests.fs b/vsintegration/tests/FSharp.Editor.Tests/DocumentDiagnosticAnalyzerTests.fs index cf05a66cdd6..4d8eea57081 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/DocumentDiagnosticAnalyzerTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/DocumentDiagnosticAnalyzerTests.fs @@ -14,11 +14,11 @@ type DocumentDiagnosticAnalyzerTests() = let startMarker = "(*start*)" let endMarker = "(*end*)" - let getDiagnostics (fileContents: string) = + member private _.getDiagnostics (fileContents: string, ?additionalFlags) = let task = cancellableTask { let document = - RoslynTestHelpers.CreateSolution(fileContents) + RoslynTestHelpers.CreateSolution(fileContents, ?extraFSharpProjectOtherOptions=additionalFlags) |> RoslynTestHelpers.GetSingleDocument let! syntacticDiagnostics = FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(document, DiagnosticsType.Syntax) @@ -30,14 +30,14 @@ type DocumentDiagnosticAnalyzerTests() = task.Result member private this.VerifyNoErrors(fileContents: string, ?additionalFlags: string[]) = - let errors = getDiagnostics fileContents + let errors = this.getDiagnostics (fileContents, ?additionalFlags = additionalFlags) if not errors.IsEmpty then failwith $"There should be no errors generated: {errors}" member private this.VerifyErrorAtMarker(fileContents: string, expectedMarker: string, ?expectedMessage: string) = let errors = - getDiagnostics fileContents + this.getDiagnostics fileContents |> Seq.filter (fun e -> e.Severity = DiagnosticSeverity.Error) |> Seq.toArray @@ -68,7 +68,7 @@ type DocumentDiagnosticAnalyzerTests() = expectedSeverity: DiagnosticSeverity ) = let errors = - getDiagnostics fileContents + this.getDiagnostics fileContents |> Seq.filter (fun e -> e.Severity = expectedSeverity) |> Seq.toArray @@ -99,7 +99,7 @@ type DocumentDiagnosticAnalyzerTests() = ) = // TODO: once workaround (https://github.com/dotnet/fsharp/pull/15982) will not be needed, this should be reverted back to normal method (see PR) let errors = - getDiagnostics fileContents + this.getDiagnostics fileContents |> Seq.filter (fun e -> e.Severity = expectedSeverity) |> Seq.toArray @@ -133,7 +133,7 @@ type DocumentDiagnosticAnalyzerTests() = ?expectedMessage: string ) = let errors = - getDiagnostics fileContents + this.getDiagnostics fileContents |> Seq.filter (fun e -> e.Severity = DiagnosticSeverity.Error) |> Seq.toArray @@ -202,7 +202,7 @@ let b = [] type C(a : int) = new(a : string) = C(int a) - new(b) = match b with Some _ -> C(1) | _ -> C("") + new b = match b with Some _ -> C 1 | _ -> C "" """ ) @@ -213,7 +213,7 @@ type C(a : int) = [] type C(a : int) = new(a : string) = new C(int a) - new(b) = match b with Some _ -> new C(1) | _ -> new C("") + new b = match b with Some _ -> new C 1 | _ -> new C "" """ ) @@ -223,7 +223,7 @@ type C(a : int) = """ [] type O(o : int) = - new() = O(1) + new() = O 1 """ ) @@ -243,7 +243,7 @@ type O(o : int) = """ [] type O(o : int) = - new() = new O(1) then printfn "A" + new() = new O 1 then printfn "A" """ ) diff --git a/vsintegration/tests/FSharp.Editor.Tests/EditorFormattingServiceTests.fs b/vsintegration/tests/FSharp.Editor.Tests/EditorFormattingServiceTests.fs index beb93403e91..9442957325f 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/EditorFormattingServiceTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/EditorFormattingServiceTests.fs @@ -38,7 +38,7 @@ let def = )marker4 """ - let pasteTemplate = + let _pasteTemplate = """ let foo = diff --git a/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj b/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj index e8d25a75fb9..620e99d2255 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj +++ b/vsintegration/tests/FSharp.Editor.Tests/FSharp.Editor.Tests.fsproj @@ -7,6 +7,8 @@ false true $(NoWarn);FS3511 + $(OtherFlags) --warnon:1182 + true diff --git a/vsintegration/tests/FSharp.Editor.Tests/Helpers/RoslynHelpers.fs b/vsintegration/tests/FSharp.Editor.Tests/Helpers/RoslynHelpers.fs index 5b00301821b..60695b1d704 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/Helpers/RoslynHelpers.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/Helpers/RoslynHelpers.fs @@ -188,7 +188,7 @@ type TestHostWorkspaceServices(hostServices: HostServices, workspace: Workspace) with _ -> Unchecked.defaultof<'T> - override _.FindLanguageServices(filter) = Seq.empty + override _.FindLanguageServices(_filter) = Seq.empty override _.GetLanguageServices(languageName) = match languageName with @@ -275,7 +275,7 @@ type RoslynTestHelpers private () = static member SetEditorOptions (solution: Solution) options = solution.Workspace.Services.GetService().With(options) - static member CreateSolution(source, ?options: FSharpProjectOptions, ?editorOptions) = + static member CreateSolution(source, ?options: FSharpProjectOptions, ?extraFSharpProjectOtherOptions: string array, ?editorOptions) = let projId = ProjectId.CreateNewId() let docInfo = RoslynTestHelpers.CreateDocumentInfo projId "C:\\test.fs" source @@ -283,9 +283,14 @@ type RoslynTestHelpers private () = let projFilePath = "C:\\test.fsproj" let projInfo = RoslynTestHelpers.CreateProjectInfo projId projFilePath [ docInfo ] let solution = RoslynTestHelpers.CreateSolution [ projInfo ] + + let options = + let options = options |> Option.defaultValue RoslynTestHelpers.DefaultProjectOptions + match extraFSharpProjectOtherOptions with + | None | Some [||] -> options + | Some otherOptions -> { options with OtherOptions = Array.concat [|options.OtherOptions; otherOptions|] } options - |> Option.defaultValue RoslynTestHelpers.DefaultProjectOptions |> RoslynTestHelpers.SetProjectOptions projId solution if editorOptions.IsSome then @@ -351,10 +356,7 @@ type RoslynTestHelpers private () = |> Array.append customProjectOptions } - let solution = - match customEditorOptions with - | Some o -> RoslynTestHelpers.CreateSolution(code, options, o) - | None -> RoslynTestHelpers.CreateSolution(code, options) + let solution = RoslynTestHelpers.CreateSolution(code, options, ?editorOptions=customEditorOptions) solution |> RoslynTestHelpers.GetSingleDocument diff --git a/vsintegration/tests/FSharp.Editor.Tests/QuickInfoProviderTests.fs b/vsintegration/tests/FSharp.Editor.Tests/QuickInfoProviderTests.fs index aa8eb39bb53..abd08e2bf45 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/QuickInfoProviderTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/QuickInfoProviderTests.fs @@ -85,7 +85,7 @@ module QuickInfoProviderTests = | QuickInfo _ -> QuickInfo(desc, docs) | _ -> Desc desc - | ToolTipElement.CompositionError (error) -> Error + | ToolTipElement.CompositionError _ -> Error let executeQuickInfoTest (programText: string) testCases = let document = From 015303c3f29f2ef8de60ba540e34562aedc80045 Mon Sep 17 00:00:00 2001 From: Gauthier Segay Date: Sat, 11 Nov 2023 16:51:49 +0100 Subject: [PATCH 2/4] fantomas! --- .../DocumentDiagnosticAnalyzerTests.fs | 4 ++-- .../Helpers/RoslynHelpers.fs | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/vsintegration/tests/FSharp.Editor.Tests/DocumentDiagnosticAnalyzerTests.fs b/vsintegration/tests/FSharp.Editor.Tests/DocumentDiagnosticAnalyzerTests.fs index 4d8eea57081..27db356ec4b 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/DocumentDiagnosticAnalyzerTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/DocumentDiagnosticAnalyzerTests.fs @@ -14,11 +14,11 @@ type DocumentDiagnosticAnalyzerTests() = let startMarker = "(*start*)" let endMarker = "(*end*)" - member private _.getDiagnostics (fileContents: string, ?additionalFlags) = + member private _.getDiagnostics(fileContents: string, ?additionalFlags) = let task = cancellableTask { let document = - RoslynTestHelpers.CreateSolution(fileContents, ?extraFSharpProjectOtherOptions=additionalFlags) + RoslynTestHelpers.CreateSolution(fileContents, ?extraFSharpProjectOtherOptions = additionalFlags) |> RoslynTestHelpers.GetSingleDocument let! syntacticDiagnostics = FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(document, DiagnosticsType.Syntax) diff --git a/vsintegration/tests/FSharp.Editor.Tests/Helpers/RoslynHelpers.fs b/vsintegration/tests/FSharp.Editor.Tests/Helpers/RoslynHelpers.fs index 60695b1d704..9bedb277c9d 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/Helpers/RoslynHelpers.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/Helpers/RoslynHelpers.fs @@ -283,15 +283,19 @@ type RoslynTestHelpers private () = let projFilePath = "C:\\test.fsproj" let projInfo = RoslynTestHelpers.CreateProjectInfo projId projFilePath [ docInfo ] let solution = RoslynTestHelpers.CreateSolution [ projInfo ] - + let options = let options = options |> Option.defaultValue RoslynTestHelpers.DefaultProjectOptions + match extraFSharpProjectOtherOptions with - | None | Some [||] -> options - | Some otherOptions -> { options with OtherOptions = Array.concat [|options.OtherOptions; otherOptions|] } + | None + | Some [||] -> options + | Some otherOptions -> + { options with + OtherOptions = Array.concat [| options.OtherOptions; otherOptions |] + } - options - |> RoslynTestHelpers.SetProjectOptions projId solution + options |> RoslynTestHelpers.SetProjectOptions projId solution if editorOptions.IsSome then RoslynTestHelpers.SetEditorOptions solution editorOptions.Value @@ -356,7 +360,8 @@ type RoslynTestHelpers private () = |> Array.append customProjectOptions } - let solution = RoslynTestHelpers.CreateSolution(code, options, ?editorOptions=customEditorOptions) + let solution = + RoslynTestHelpers.CreateSolution(code, options, ?editorOptions = customEditorOptions) solution |> RoslynTestHelpers.GetSingleDocument From 9a2917568e1e27531f95231bcec975e784516d72 Mon Sep 17 00:00:00 2001 From: Gauthier Segay Date: Mon, 13 Nov 2023 14:49:11 +0100 Subject: [PATCH 3/4] Update CompletionProviderTests.fs add test tracking state of #16260 --- .../CompletionProviderTests.fs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs index 9f4af97fcbf..7e4978e42c6 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs @@ -1990,3 +1990,20 @@ match { A = 1; B = 2 } with """ VerifyCompletionList(fileContents, "| { f = ()", [ "A"; "B"; "C"; "D" ], []) + + [] + let ``issue #16260 [TO-BE-IMPROVED] operators are fumbling for now`` () = + let fileContents = + """ +module Ops = +let (|>>) a b = a + b +module Foo = + let (|>>) a b = a + b +Ops.Foo.() +Ops.Foo.( +Ops.( +Ops.() +""" + + VerifyCompletionList(fileContents, "Ops.Foo.(", [], ["|>>";"(|>>)"]) + VerifyCompletionList(fileContents, "Ops.(", [], ["|>>";"(|>>)"]) From 717b0ed5bc3dfba188f0633f32749f484390e6d0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:46:47 +0000 Subject: [PATCH 4/4] Automated command ran: fantomas Co-authored-by: psfinaki <5451366+psfinaki@users.noreply.github.com> --- .../tests/FSharp.Editor.Tests/CompletionProviderTests.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs index 7e4978e42c6..e94a5f69436 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs @@ -2005,5 +2005,5 @@ Ops.( Ops.() """ - VerifyCompletionList(fileContents, "Ops.Foo.(", [], ["|>>";"(|>>)"]) - VerifyCompletionList(fileContents, "Ops.(", [], ["|>>";"(|>>)"]) + VerifyCompletionList(fileContents, "Ops.Foo.(", [], [ "|>>"; "(|>>)" ]) + VerifyCompletionList(fileContents, "Ops.(", [], [ "|>>"; "(|>>)" ])