Skip to content

Commit f166769

Browse files
committed
Fix issue whith completing x= in JSX.
When completing `x=`, if the following contains `name=...`, then the parser interprets it as `x=name`. Now detect that the cursor is after the label `x` but before `name`, and don;t interpret the situation as label completion.
1 parent b182164 commit f166769

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

analysis/src/Commands.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ let findJsxPropsCompletable ~jsxProps ~endPos ~posBeforeCursor ~posAfterCompName
2525
| prop :: rest ->
2626
if prop.posStart <= posBeforeCursor && posBeforeCursor < prop.posEnd then
2727
Some (PartialParser.Cjsx (jsxProps.componentPath, prop.name, allLabels))
28+
else if
29+
prop.posEnd <= posBeforeCursor
30+
&& posBeforeCursor < Loc.start prop.exp.pexp_loc
31+
then None
2832
else if prop.exp.pexp_loc |> Loc.hasPos ~pos:posBeforeCursor then None
2933
else loop rest
3034
| [] ->
@@ -99,7 +103,7 @@ let extractJsxProps ~text ~(compName : Longident.t Location.loc) ~args =
99103
( PartialParser.positionToOffset text ePosStart,
100104
PartialParser.positionToOffset text ePosEnd )
101105
with
102-
| Some offsetStart, Some offsetEnd ->
106+
| Some offsetStart, Some offsetEnd when not eProp.pexp_loc.loc_ghost ->
103107
let label = String.sub text lastOffset (offsetStart - lastOffset) in
104108
let labelPos =
105109
match extractLabelPos ~pos:lastPos ~i:0 label with

analysis/tests/src/Jsx.res

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,15 @@ let _ =
9898
name=""
9999
/>
100100

101-
102101
let _ =
103102
<div
104103
// ^com x=Outer.Inner.
104+
name="" />
105+
106+
107+
let _ =
108+
<div
109+
// ^com x=
105110
name=""
106111
/>
107112

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,11 @@ Completable: Cpath Value[Outer, Inner, h]
396396
"documentation": null
397397
}]
398398

399-
Complete tests/src/Jsx.res 102:5
400-
posCursor:[103:15] posNoWhite:[103:14] Found expr:[102:3->104:9]
401-
JSX <div:[102:3->102:6] x[103:1->103:2]=...[103:3->104:8]> _children:None
402-
posCursor:[103:15] posNoWhite:[103:14] Found expr:[103:3->104:8]
403-
Pexp_ident Outer.Inner.name:[103:3->104:8]
399+
Complete tests/src/Jsx.res 101:5
400+
posCursor:[102:15] posNoWhite:[102:14] Found expr:[101:3->103:9]
401+
JSX <div:[101:3->101:6] x[102:1->102:2]=...[102:3->103:8]> _children:None
402+
posCursor:[102:15] posNoWhite:[102:14] Found expr:[102:3->103:8]
403+
Pexp_ident Outer.Inner.name:[102:3->103:8]
404404
Id breaks up. New path:Outer.Inner.
405405
Completable: Cpath Value[Outer, Inner, ""]
406406
[{
@@ -411,3 +411,8 @@ Completable: Cpath Value[Outer, Inner, ""]
411411
"documentation": null
412412
}]
413413

414+
Complete tests/src/Jsx.res 107:5
415+
posCursor:[108:3] posNoWhite:[108:2] Found expr:[107:3->109:9]
416+
JSX <div:[107:3->107:6] x[108:1->108:2]=...[109:4->109:8]> _children:None
417+
[]
418+

0 commit comments

Comments
 (0)