Skip to content

Fix JSX prop autocomplete special case #984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}]

Loading