Skip to content

Commit c4ed6a5

Browse files
committed
unwrap options of optional record fields when following typed path
1 parent e5defc7 commit c4ed6a5

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

analysis/src/CompletionBackEnd.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,9 @@ let rec resolveNested typ ~env ~package ~nested =
19251925
|> List.find_opt (fun (field : field) -> field.fname.txt = fieldName)
19261926
with
19271927
| None -> None
1928-
| Some {typ} -> typ |> resolveNested ~env ~package ~nested)
1928+
| Some {typ; optional} ->
1929+
let typ = if optional then Utils.unwrapIfOption typ else typ in
1930+
typ |> resolveNested ~env ~package ~nested)
19291931
| NRecordBody {seenFields}, Some (Trecord {env; typeExpr}) ->
19301932
Some (typeExpr, env, Some (Completable.RecordField {seenFields}))
19311933
| ( NVariantPayload {constructorName = "Some"; itemNum = 0},

analysis/tests/src/CompletionExpressions.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ let fnTakingOtherRecord = (r: otherRecord) => {
9999

100100
type recordWithOptionalField = {
101101
someField: int,
102-
someOptField?: string,
102+
someOptField?: bool,
103103
}
104104

105105
let fnTakingRecordWithOptionalField = (r: recordWithOptionalField) => {

analysis/tests/src/expected/CompletionExpressions.res.txt

+5-7
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,16 @@ posCursor:[108:57] posNoWhite:[108:56] Found expr:[108:11->108:60]
432432
Pexp_apply ...[108:11->108:42] (...[108:43->108:60])
433433
Completable: Cexpression CArgument Value[fnTakingRecordWithOptionalField]($0)->recordField(someOptField)
434434
[{
435-
"label": "None",
435+
"label": "true",
436436
"kind": 4,
437437
"tags": [],
438-
"detail": "string",
438+
"detail": "bool",
439439
"documentation": null
440440
}, {
441-
"label": "Some(_)",
441+
"label": "false",
442442
"kind": 4,
443443
"tags": [],
444-
"detail": "string",
445-
"documentation": null,
446-
"insertText": "Some(${1:_})",
447-
"insertTextFormat": 2
444+
"detail": "bool",
445+
"documentation": null
448446
}]
449447

0 commit comments

Comments
 (0)