diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md index dde1ee4031f..b5a86a6540f 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md @@ -21,8 +21,10 @@ * Parser: fix pattern range for idents with trivia ([PR #16824](https://github.com/dotnet/fsharp/pull/16824)) * Fix broken code completion after a record type declaration ([PR #16813](https://github.com/dotnet/fsharp/pull/16813)) * Enforce AttributeTargets on enums ([PR #16887](https://github.com/dotnet/fsharp/pull/16887)) +* Completion: fix for unfinished record field decl ([PR #16893](https://github.com/dotnet/fsharp/pull/16893)) * Enforce AttributeTargets on delegates ([PR #16891](https://github.com/dotnet/fsharp/pull/16891)) + ### Added * The stackguard depth for ILPdbWriter.unshadowScopes can be modified via the environment variable `FSHARP_ILPdb_UnshadowScopes_StackGuardDepth`([PR #16583](https://github.com/dotnet/fsharp/pull/16583)) diff --git a/src/Compiler/Service/ServiceParsedInputOps.fs b/src/Compiler/Service/ServiceParsedInputOps.fs index 90062e81c68..d739526a025 100644 --- a/src/Compiler/Service/ServiceParsedInputOps.fs +++ b/src/Compiler/Service/ServiceParsedInputOps.fs @@ -1646,11 +1646,12 @@ module ParsedInput = member _.VisitRecordDefn(_, fields, range) = fields - |> List.tryPick (fun (SynField(idOpt = idOpt; range = fieldRange)) -> - match idOpt with - | Some id when rangeContainsPos id.idRange pos -> + |> List.tryPick (fun (SynField(idOpt = idOpt; range = fieldRange; fieldType = fieldType)) -> + match idOpt, fieldType with + | Some id, _ when rangeContainsPos id.idRange pos -> Some(CompletionContext.RecordField(RecordContext.Declaration true)) | _ when rangeContainsPos fieldRange pos -> Some(CompletionContext.RecordField(RecordContext.Declaration false)) + | _, SynType.FromParseError _ -> Some(CompletionContext.RecordField(RecordContext.Declaration false)) | _ -> None) // No completions in a record outside of all fields, except in attributes, which is established earlier in VisitAttributeApplication |> Option.orElseWith (fun _ -> diff --git a/tests/service/CompletionTests.fs b/tests/service/CompletionTests.fs index f973c434377..c3859e0b82f 100644 --- a/tests/service/CompletionTests.fs +++ b/tests/service/CompletionTests.fs @@ -80,4 +80,11 @@ let ``Underscore dot lambda - method completion`` () = let myFancyFunc (x:string) = x |> _.ToL""" - assertHasItemWithNames ["ToLower"] info \ No newline at end of file + assertHasItemWithNames ["ToLower"] info + +[] +let ``Type decl - Record - Field type 01`` () = + let info = getCompletionInfo "type Record = { Field: }" (2, 23) """ +type Record = { Field: } +""" + assertHasItemWithNames ["string"] info