Skip to content

Commit

Permalink
Fix JSX prop autocomplete special case (#984)
Browse files Browse the repository at this point in the history
* ensure there is an equal sign present when triggering special cased JSX prop completion

* changelog
  • Loading branch information
zth committed May 25, 2024
1 parent 3375705 commit 2d8d942
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

#### :nail_care: Polish

Expand Down
5 changes: 4 additions & 1 deletion analysis/src/CompletionJsx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,10 @@ let findJsxPropsCompletable ~jsxProps ~endPos ~posBeforeCursor
nested = [];
}))
else None)
else if rest = [] && beforeChildrenStart && charAtCursor = '>' then (
else if
rest = [] && beforeChildrenStart && charAtCursor = '>'
&& firstCharBeforeCursorNoWhite = Some '='
then (
(* This is a special case for: <SomeComponent someProp=> (completing directly after the '=').
The completion comes at the end of the component, after the equals sign, but before any
children starts, and '>' marks that it's at the end of the component JSX.
Expand Down
10 changes: 10 additions & 0 deletions analysis/tests/src/CompletionJsx.res
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,13 @@ module MultiPropComp = {

// <MultiPropComp name time= age
// ^com

module Info = {
@react.component
let make = (~_type: [#warning | #info]) => {
React.string((_type :> string))
}
}

// <Info _type={#warning} >
// ^com
15 changes: 15 additions & 0 deletions analysis/tests/src/expected/CompletionJsx.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,18 @@ Path MultiPropComp.make
"insertTextFormat": 2
}]

Complete src/CompletionJsx.res 89:26
posCursor:[89:26] posNoWhite:[89:24] Found expr:[89:4->89:27]
JSX <Info:[89:4->89:8] _type[89:9->89:14]=...[89:16->89:24]> _children:89:26
Completable: Cjsx([Info], "", [_type])
Package opens Pervasives.JsxModules.place holder
Resolved opens 1 pervasives
Path Info.make
[{
"label": "key",
"kind": 4,
"tags": [],
"detail": "string",
"documentation": null
}]

0 comments on commit 2d8d942

Please sign in to comment.