Skip to content

Commit

Permalink
expand options where it makes sense
Browse files Browse the repository at this point in the history
  • Loading branch information
zth committed Dec 29, 2022
1 parent 85c4304 commit 1b65fea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 7 additions & 2 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1509,8 +1509,10 @@ let rec extractType ~env ~package (t : Types.type_expr) =
| Ttuple expressions -> Some (Tuple (env, expressions))
| _ -> None

let completeTypedValue t ~env ~full ~prefix =
let rec completeTypedValue t ~env ~full ~prefix ~expandOption =
match t |> extractType ~env ~package:full.package with
| Some (Toption (env, typ)) when expandOption ->
typ |> completeTypedValue ~env ~full ~prefix ~expandOption:false
| Some (Tbool env) ->
let items =
[
Expand Down Expand Up @@ -1938,7 +1940,10 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
in
match targetLabel with
| None -> []
| Some (_, typ) -> typ |> completeTypedValue ~env ~full ~prefix)
| Some (Labelled _, typ) ->
typ |> completeTypedValue ~env ~full ~prefix ~expandOption:true
| Some (Unlabelled _, typ) ->
typ |> completeTypedValue ~env ~full ~prefix ~expandOption:false)
| CnamedArg (cp, prefix, identsSeen) ->
let labels =
match
Expand Down
12 changes: 9 additions & 3 deletions analysis/tests/src/expected/CompletionFunctionArguments.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ posCursor:[14:25] posNoWhite:[14:24] Found expr:[14:11->14:26]
Pexp_apply ...[14:11->14:17] (~isOff14:19->14:24=...__ghost__[0:-1->0:-1])
Completable: Value[someFn](~isOff)
[{
"label": "None",
"label": "true",
"kind": 4,
"tags": [],
"detail": "bool",
"documentation": null
}, {
"label": "Some(_)",
"label": "false",
"kind": 4,
"tags": [],
"detail": "bool",
Expand Down Expand Up @@ -138,5 +138,11 @@ Complete src/CompletionFunctionArguments.res 56:44
posCursor:[56:44] posNoWhite:[56:43] Found expr:[56:11->56:45]
Pexp_apply ...[56:11->56:30] (~configOpt256:32->56:42=...[56:43->56:44])
Completable: Value[someFnTakingVariant](~configOpt2=O)
[]
[{
"label": "One",
"kind": 4,
"tags": [],
"detail": "One\n\n",
"documentation": null
}]

0 comments on commit 1b65fea

Please sign in to comment.