Skip to content

Commit 2d8d942

Browse files
authored
Fix JSX prop autocomplete special case (#984)
* ensure there is an equal sign present when triggering special cased JSX prop completion * changelog
1 parent 3375705 commit 2d8d942

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
- Fix highlighting of other languages being affected by rescript-vscode. https://github.com/rescript-lang/rescript-vscode/pull/973
1818
- Use canonicalized URIs/paths for jump to definition. https://github.com/rescript-lang/rescript-vscode/pull/982
19+
- Fix JSX prop special case in end of JSX element. https://github.com/rescript-lang/rescript-vscode/pull/984
1920

2021
#### :nail_care: Polish
2122

analysis/src/CompletionJsx.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,10 @@ let findJsxPropsCompletable ~jsxProps ~endPos ~posBeforeCursor
909909
nested = [];
910910
}))
911911
else None)
912-
else if rest = [] && beforeChildrenStart && charAtCursor = '>' then (
912+
else if
913+
rest = [] && beforeChildrenStart && charAtCursor = '>'
914+
&& firstCharBeforeCursorNoWhite = Some '='
915+
then (
913916
(* This is a special case for: <SomeComponent someProp=> (completing directly after the '=').
914917
The completion comes at the end of the component, after the equals sign, but before any
915918
children starts, and '>' marks that it's at the end of the component JSX.

analysis/tests/src/CompletionJsx.res

+10
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,13 @@ module MultiPropComp = {
7979

8080
// <MultiPropComp name time= age
8181
// ^com
82+
83+
module Info = {
84+
@react.component
85+
let make = (~_type: [#warning | #info]) => {
86+
React.string((_type :> string))
87+
}
88+
}
89+
90+
// <Info _type={#warning} >
91+
// ^com

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

+15
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,18 @@ Path MultiPropComp.make
600600
"insertTextFormat": 2
601601
}]
602602

603+
Complete src/CompletionJsx.res 89:26
604+
posCursor:[89:26] posNoWhite:[89:24] Found expr:[89:4->89:27]
605+
JSX <Info:[89:4->89:8] _type[89:9->89:14]=...[89:16->89:24]> _children:89:26
606+
Completable: Cjsx([Info], "", [_type])
607+
Package opens Pervasives.JsxModules.place holder
608+
Resolved opens 1 pervasives
609+
Path Info.make
610+
[{
611+
"label": "key",
612+
"kind": 4,
613+
"tags": [],
614+
"detail": "string",
615+
"documentation": null
616+
}]
617+

0 commit comments

Comments
 (0)