Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing completion suggestions for collections of anonymous records #14976

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Compiler/Service/ServiceDeclarationLists.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ type DeclarationListInfo(declarations: DeclarationListItem[], isForType: bool, i
// Make a 'Declarations' object for a set of selected items
static member Create(infoReader:InfoReader, ad, m: range, denv, getAccessibility: Item -> FSharpAccessibility, items: CompletionItem list, currentNamespace: string[] option, isAttributeApplicationContext: bool) =
let g = infoReader.g
let isForType = items |> List.exists (fun x -> x.Type.IsSome)
let isForType = items |> List.exists (fun x -> x.Type.IsSome || (x.Item |> function Item.AnonRecdField _ -> true | _ -> false))
let items = items |> RemoveExplicitlySuppressedCompletionItems g

let tyconRefOptEq tref1 tref2 =
Expand Down
14 changes: 14 additions & 0 deletions tests/service/CompletionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ 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)


[<Test>]
let ``Expr - record - field 01 - anon module`` () =
Expand Down Expand Up @@ -57,3 +63,11 @@ let record = { Field = 1 }
{ }
"""
assertHasItemWithNames ["Field"; "record"] info

[<Test>]
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