Skip to content

Commit b353688

Browse files
authored
Completion: fix for unfinished record field decl (#16893)
* Completion: fix for unfinished record field decl * Fantomas * Release notes
1 parent 5a19ccf commit b353688

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
* Parser: fix pattern range for idents with trivia ([PR #16824](https://github.com/dotnet/fsharp/pull/16824))
2222
* Fix broken code completion after a record type declaration ([PR #16813](https://github.com/dotnet/fsharp/pull/16813))
2323
* Enforce AttributeTargets on enums ([PR #16887](https://github.com/dotnet/fsharp/pull/16887))
24+
* Completion: fix for unfinished record field decl ([PR #16893](https://github.com/dotnet/fsharp/pull/16893))
2425
* Enforce AttributeTargets on delegates ([PR #16891](https://github.com/dotnet/fsharp/pull/16891))
2526

27+
2628
### Added
2729

2830
* 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))

src/Compiler/Service/ServiceParsedInputOps.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,11 +1646,12 @@ module ParsedInput =
16461646

16471647
member _.VisitRecordDefn(_, fields, range) =
16481648
fields
1649-
|> List.tryPick (fun (SynField(idOpt = idOpt; range = fieldRange)) ->
1650-
match idOpt with
1651-
| Some id when rangeContainsPos id.idRange pos ->
1649+
|> List.tryPick (fun (SynField(idOpt = idOpt; range = fieldRange; fieldType = fieldType)) ->
1650+
match idOpt, fieldType with
1651+
| Some id, _ when rangeContainsPos id.idRange pos ->
16521652
Some(CompletionContext.RecordField(RecordContext.Declaration true))
16531653
| _ when rangeContainsPos fieldRange pos -> Some(CompletionContext.RecordField(RecordContext.Declaration false))
1654+
| _, SynType.FromParseError _ -> Some(CompletionContext.RecordField(RecordContext.Declaration false))
16541655
| _ -> None)
16551656
// No completions in a record outside of all fields, except in attributes, which is established earlier in VisitAttributeApplication
16561657
|> Option.orElseWith (fun _ ->

tests/service/CompletionTests.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,11 @@ let ``Underscore dot lambda - method completion`` () =
8080
let myFancyFunc (x:string) =
8181
x
8282
|> _.ToL"""
83-
assertHasItemWithNames ["ToLower"] info
83+
assertHasItemWithNames ["ToLower"] info
84+
85+
[<Test>]
86+
let ``Type decl - Record - Field type 01`` () =
87+
let info = getCompletionInfo "type Record = { Field: }" (2, 23) """
88+
type Record = { Field: }
89+
"""
90+
assertHasItemWithNames ["string"] info

0 commit comments

Comments
 (0)