From 2e9719ae14657512f88372b69096b5c072e16a7e Mon Sep 17 00:00:00 2001 From: kerams Date: Wed, 21 Jun 2023 10:48:54 +0200 Subject: [PATCH 1/2] Prioritize anonymous record fields in completions (#15451) --- src/Compiler/Service/FSharpCheckerResults.fs | 2 +- tests/service/CompletionTests.fs | 17 +---------------- .../CompletionProviderTests.fs | 10 ++++++++++ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index 559a1fdbb15..4a4aefa818d 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -889,6 +889,7 @@ type internal TypeCheckInfo match minfos with | [] -> CompletionItemKind.Method false | minfo :: _ -> CompletionItemKind.Method minfo.IsExtensionMember + | Item.AnonRecdField _ | Item.RecdField _ | Item.Property _ -> CompletionItemKind.Property | Item.Event _ -> CompletionItemKind.Event @@ -896,7 +897,6 @@ type internal TypeCheckInfo | Item.Value _ -> CompletionItemKind.Field | Item.CustomOperation _ -> CompletionItemKind.CustomOperation // These items are not given a completion kind. This could be reviewed - | Item.AnonRecdField _ | Item.ActivePatternResult _ | Item.CustomOperation _ | Item.CtorGroup _ diff --git a/tests/service/CompletionTests.fs b/tests/service/CompletionTests.fs index 0759b5b4f8c..9aca58a6b5b 100644 --- a/tests/service/CompletionTests.fs +++ b/tests/service/CompletionTests.fs @@ -17,13 +17,6 @@ let assertHasItemWithNames names (completionInfo: DeclarationListInfo) = for name in names do Assert.That(Set.contains name itemNames, name) -let assertHasExactlyNamesAndNothingElse names (completionInfo: DeclarationListInfo) = - let itemNames = getCompletionItemNames completionInfo |> set - let expectedNames = Set.ofList names - - Assert.That(itemNames, Is.EqualTo expectedNames) - - [] let ``Expr - record - field 01 - anon module`` () = let info = getCompletionInfo "{ Fi }" (4, 3) """ @@ -62,12 +55,4 @@ let record = { Field = 1 } { } """ - assertHasItemWithNames ["Field"; "record"] info - -[] -let ``Expr - array of anonymous records`` () = - let info = getCompletionInfo "x[0]." (3, 6) """ -let x = [ {| Name = "foo" |} ] -x[0]. -""" - assertHasExactlyNamesAndNothingElse ["Name"; "Equals"; "GetHashCode"; "GetType"; "ToString"] info + assertHasItemWithNames ["Field"; "record"] info \ No newline at end of file diff --git a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs index 4e52874d8b3..8173eb6e2ce 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs @@ -1450,3 +1450,13 @@ let t2 (x: {| D: NestdRecTy; E: {| a: string |} |}) = {| x with E.a = "a"; D.B = "let t2 (x: {| D: NestdRecTy; E: {| a: string |} |}) = {| x with E.a = \"a\"; D.", [ "B"; "C" ] ) + + [] + let ``Anonymous record fields have higher priority than methods`` () = + let fileContents = + """ +let x = [ {| Goo = 1; Foo = "foo" |} ] +x[0]. +""" + + VerifyCompletionListExactly(fileContents, "x[0].", [ "Foo"; "Goo"; "Equals"; "GetHashCode"; "GetType"; "ToString" ]) From e82744c2860bae4232c3ef27ab241c8a1b61f481 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Wed, 21 Jun 2023 14:46:54 +0200 Subject: [PATCH 2/2] Add typar to member when parent type contains the same letter. (#15445) Co-authored-by: Tomas Grosup --- src/Compiler/Checking/NicePrint.fs | 15 ++++++++++++++- .../generic-member.fsx | 9 +++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/generic-member.fsx diff --git a/src/Compiler/Checking/NicePrint.fs b/src/Compiler/Checking/NicePrint.fs index db54e06faf6..50a2ca2b44d 100644 --- a/src/Compiler/Checking/NicePrint.fs +++ b/src/Compiler/Checking/NicePrint.fs @@ -1266,8 +1266,21 @@ module PrintTastMemberOrVals = layoutTyconRef denv vref.MemberApparentEntity ^^ SepL.dot ^^ nameL else nameL + + let memberHasSameTyparNameAsParentTypeTypars = + let parentTyparNames = + vref.DeclaringEntity.TyparsNoRange + |> Seq.choose (fun tp -> if tp.typar_id.idText = unassignedTyparName then None else Some tp.typar_id.idText) + |> set + niceMethodTypars + |> Seq.exists (fun tp -> parentTyparNames.Contains tp.typar_id.idText) + let typarOrderMismatch = isTyparOrderMismatch niceMethodTypars argInfos - let nameL = if denv.showTyparBinding || typarOrderMismatch then layoutTyparDecls denv nameL true niceMethodTypars else nameL + let nameL = + if denv.showTyparBinding || typarOrderMismatch || memberHasSameTyparNameAsParentTypeTypars then + layoutTyparDecls denv nameL true niceMethodTypars + else + nameL let nameL = layoutAccessibility denv vref.Accessibility nameL nameL diff --git a/tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/generic-member.fsx b/tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/generic-member.fsx new file mode 100644 index 00000000000..06a8a25c01a --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Signatures/TestCasesForGenerationRoundTrip/generic-member.fsx @@ -0,0 +1,9 @@ +module V + +type 'a Foo = + { + Bar: 'a array + D: int + } + member _.Make1<'b> (array: 'a array) : 'a Foo = failwith "meh" + member _.Make2<'a> (array: 'a array) : 'a Foo = failwith "meh"