From 18fc7a9e341e59e9f1060fd15dbf41b629ae8fda Mon Sep 17 00:00:00 2001 From: kerams Date: Tue, 20 Jun 2023 17:25:39 +0200 Subject: [PATCH] Prioritize anonymous record fields in completions --- 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" ])