Skip to content
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
15 changes: 14 additions & 1 deletion src/Compiler/Checking/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -889,14 +889,14 @@ 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
| Item.ILField _
| 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 _
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 1 addition & 16 deletions tests/service/CompletionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)


[<Test>]
let ``Expr - record - field 01 - anon module`` () =
let info = getCompletionInfo "{ Fi }" (4, 3) """
Expand Down Expand Up @@ -62,12 +55,4 @@ 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
assertHasItemWithNames ["Field"; "record"] info
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
)

[<Fact>]
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" ])