-
Notifications
You must be signed in to change notification settings - Fork 463
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
Skip trailing comma in explicit partial application #6949
Merged
cknitt
merged 5 commits into
rescript-lang:master
from
shulhi:fix-trailing-comma-in-partial-function-dotdotdot
Aug 15, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4146,7 +4146,13 @@ and print_pexp_apply ~state expr cmt_tbl = | |
let partial, attrs = ParsetreeViewer.process_partial_app_attribute attrs in | ||
let args = | ||
if partial then | ||
let dummy = Ast_helper.Exp.constant (Ast_helper.Const.int 0) in | ||
let loc = | ||
{Asttypes.txt = "res.partial"; Asttypes.loc = expr.pexp_loc} | ||
in | ||
let attr = (loc, Parsetree.PTyp (Ast_helper.Typ.any ())) in | ||
let dummy = | ||
Ast_helper.Exp.constant ~attrs:[attr] (Ast_helper.Const.int 0) | ||
in | ||
args @ [(Asttypes.Labelled "...", dummy)] | ||
else args | ||
in | ||
|
@@ -4730,6 +4736,18 @@ and print_arguments ~state ?(partial = false) | |
in | ||
Doc.concat [Doc.lparen; arg_doc; Doc.rparen] | ||
| args -> | ||
(* Avoid printing trailing comma when there is ... in function application *) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it matters whether to check if |
||
let has_partial_attr, printed_args = | ||
List.fold_right | ||
(fun arg (flag, acc) -> | ||
let _, expr = arg in | ||
let has_partial_attr = | ||
ParsetreeViewer.has_partial_attribute expr.Parsetree.pexp_attributes | ||
in | ||
let doc = print_argument ~state arg cmt_tbl in | ||
(flag || has_partial_attr, doc :: acc)) | ||
args (false, []) | ||
in | ||
Doc.group | ||
(Doc.concat | ||
[ | ||
|
@@ -4738,13 +4756,9 @@ and print_arguments ~state ?(partial = false) | |
(Doc.concat | ||
[ | ||
Doc.soft_line; | ||
Doc.join | ||
~sep:(Doc.concat [Doc.comma; Doc.line]) | ||
(List.map | ||
(fun arg -> print_argument ~state arg cmt_tbl) | ||
args); | ||
Doc.join ~sep:(Doc.concat [Doc.comma; Doc.line]) printed_args; | ||
]); | ||
(if partial then Doc.nil else Doc.trailing_comma); | ||
(if partial || has_partial_attr then Doc.nil else Doc.trailing_comma); | ||
Doc.soft_line; | ||
Doc.rparen; | ||
]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the dummy attribute, I added
res.partial
so it can be pattern matched with the attribute rather than the label.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at previous code, it doesn't look like the choice of the
expression
here matters. It only cares about the label, so tagging partial attribute here allows us to pattern match on the attribute rather than the label.