-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Format function argument separator comments #5211
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinux
Windows
|
f3f2a6e
to
93b9a3e
Compare
a3330e9
to
3e00c0f
Compare
93b9a3e
to
6cc0256
Compare
let slash = if arguments.posonlyargs.is_empty() { | ||
// If there are no positional only arguments the default handling below is wrong | ||
None | ||
} else if let Some(preceding_end) = arguments.posonlyargs.last().map(Ranged::end) { |
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.
Can we remove this branch? The else
branch returns None
and the else if
can never be true
if posonlyargs
is empty.
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.
good catch, this was remnant of the defaults list time
}; | ||
|
||
// If we have a vararg we have a node that the comments attach to | ||
let star = if arguments.kwonlyargs.is_empty() || arguments.vararg.is_some() { |
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.
Nit: arguments.kewonlyargs.is_empty
is already handled by the else
branch (the only case where .first()
returns None
)
/// ^^^^^^ keyword only arguments (kwargs) | ||
/// ``` | ||
pub(crate) fn assign_argument_separator_comment_placement( | ||
slash: Option<(TextSize, TextRange, TextSize)>, |
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.
Nit: Define a struct with named fields. It's hard to guess the meaning of the text positions and range.
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.
refactored the entire code
## Summary This is a complete rewrite of the handling of `/` and `*` comment handling in function signatures. The key problem is that slash and star don't have a note. We now parse out the positions of slash and star and their respective preceding and following note. I've left code comments for each possible case of function signature structure and comment placement ## Test Plan I extended the function statement fixtures with cases that i found. If you have more weird edge cases your input would be appreciated.
fa2db93
to
3862051
Compare
Summary
This is a complete rewrite of the handling of
/
and*
comment handling in function signatures. The key problem is that slash and star don't have a note. We now parse out the positions of slash and star and their respective preceding and following note. I've left code comments for each possible case of function signature structure and comment placementTest Plan
I extended the function statement fixtures with cases that i found. If you have more weird edge cases your input would be appreciated.