Skip to content

Commit d51db47

Browse files
committed
only wrap root values for JSX props in braces
1 parent f75dfaf commit d51db47

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,17 +1415,21 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover
14151415
match typ |> TypeUtils.resolveNested ~env ~full ~nested with
14161416
| None -> []
14171417
| Some (typ, env, completionContext) -> (
1418-
let isJsx =
1419-
match contextPath with
1420-
| CJsxPropValue _ | CPPipe {inJsx = true} -> true
1421-
| _ -> false
1418+
(* Wrap the insert text in braces when we're completing the root of a
1419+
JSX prop value. *)
1420+
let wrapInsertTextInBraces =
1421+
if List.length nested > 0 then false
1422+
else
1423+
match contextPath with
1424+
| CJsxPropValue _ -> true
1425+
| _ -> false
14221426
in
14231427
let items =
14241428
typ
14251429
|> completeTypedValue ~mode:Expression ~full ~prefix
14261430
~completionContext
14271431
|> List.map (fun (c : Completion.t) ->
1428-
if isJsx then
1432+
if wrapInsertTextInBraces then
14291433
{
14301434
c with
14311435
insertText =

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,23 @@ Completable: Cexpression CJsxPropValue [CompletionSupport, TestComponent] testAr
190190
"tags": [],
191191
"detail": "One\n\ntype testVariant = One | Two | Three(int)",
192192
"documentation": null,
193-
"insertText": "{One}",
193+
"insertText": "One",
194194
"insertTextFormat": 2
195195
}, {
196196
"label": "Two",
197197
"kind": 4,
198198
"tags": [],
199199
"detail": "Two\n\ntype testVariant = One | Two | Three(int)",
200200
"documentation": null,
201-
"insertText": "{Two}",
201+
"insertText": "Two",
202202
"insertTextFormat": 2
203203
}, {
204204
"label": "Three(_)",
205205
"kind": 4,
206206
"tags": [],
207207
"detail": "Three(int)\n\ntype testVariant = One | Two | Three(int)",
208208
"documentation": null,
209-
"insertText": "{Three(${1:_})}",
209+
"insertText": "Three(${1:_})",
210210
"insertTextFormat": 2
211211
}]
212212

0 commit comments

Comments
 (0)