Skip to content

Commit 5995f45

Browse files
committed
only expand options on optional arguments, not all labelled arguments
1 parent 619d7ec commit 5995f45

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

analysis/src/CompletionBackEnd.ml

+14-4
Original file line numberDiff line numberDiff line change
@@ -1461,9 +1461,11 @@ let getArgs ~env (t : Types.type_expr) ~full =
14611461
match t.desc with
14621462
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) ->
14631463
getArgsLoop ~full ~env ~currentArgumentPosition t1
1464-
| Tarrow ((Labelled l | Optional l), tArg, tRet, _) ->
1464+
| Tarrow (Labelled l, tArg, tRet, _) ->
14651465
(SharedTypes.Completable.Labelled l, tArg)
14661466
:: getArgsLoop ~full ~env ~currentArgumentPosition tRet
1467+
| Tarrow (Optional l, tArg, tRet, _) ->
1468+
(Optional l, tArg) :: getArgsLoop ~full ~env ~currentArgumentPosition tRet
14671469
| Tarrow (Nolabel, tArg, tRet, _) ->
14681470
(Unlabelled {argumentPosition = currentArgumentPosition}, tArg)
14691471
:: getArgsLoop ~full ~env
@@ -1945,15 +1947,22 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
19451947
| None -> []
19461948
in
19471949
let targetLabel =
1948-
labels |> List.find_opt (fun (label, _) -> label = argumentLabel)
1950+
labels
1951+
|> List.find_opt (fun (label, _) ->
1952+
match argumentLabel with
1953+
| Unlabelled _ -> label = argumentLabel
1954+
| Labelled name | Optional name -> (
1955+
match label with
1956+
| (Labelled n | Optional n) when name = n -> true
1957+
| _ -> false))
19491958
in
19501959
match targetLabel with
19511960
| None -> []
1952-
| Some (Labelled _, typ) ->
1961+
| Some (Optional _, typ) ->
19531962
typ
19541963
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
19551964
~expandOption:true
1956-
| Some (Unlabelled _, typ) ->
1965+
| Some ((Unlabelled _ | Labelled _), typ) ->
19571966
typ
19581967
|> completeTypedValue ~env ~envWhereCompletionStarted ~full ~prefix
19591968
~expandOption:false)
@@ -1974,6 +1983,7 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
19741983
|> List.filter_map (fun arg ->
19751984
match arg with
19761985
| SharedTypes.Completable.Labelled name, a -> Some (name, a)
1986+
| Optional name, a -> Some (name, a)
19771987
| _ -> None)
19781988
| None -> []
19791989
in

analysis/src/SharedTypes.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ module Completable = struct
505505
type argumentLabel =
506506
| Unlabelled of {argumentPosition: int}
507507
| Labelled of string
508+
| Optional of string
508509

509510
type contextPath =
510511
| CPString
@@ -592,7 +593,8 @@ module Completable = struct
592593
^ "("
593594
^ (match argumentLabel with
594595
| Unlabelled {argumentPosition} -> "$" ^ string_of_int argumentPosition
595-
| Labelled name -> "~" ^ name)
596+
| Labelled name -> "~" ^ name
597+
| Optional name -> "~" ^ name ^ "=?")
596598
^ (if prefix <> "" then "=" ^ prefix else "")
597599
^ ")"
598600
end

0 commit comments

Comments
 (0)