-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Format] Fix isStartOfName to recognize attributes #76804
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d8598a3
[Format] Fix isStartOfName to recognize attributes
ilya-biryukov 6ba6f35
Update tests
ilya-biryukov be3b337
Update clang/lib/Format/TokenAnnotator.cpp
ilya-biryukov 8060996
Remove the unused #include of gmock
ilya-biryukov 18d06c2
Merge branch 'main' into format3
ilya-biryukov 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 hidden or 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 hidden or 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 hidden or 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.
Even if that would not be needed anymore to achieve the expected formatting, these are AttributeMacros, and should be declared as such.
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.
They are attribute macros indeed, the problem is that we actually need more. The ones used with fields are at least:
We could also consider including the annotations for functions, but the patch only broke formatting for variables, so it's not strictly necessary to unblock the release.
If we want to also include the ones that are used with functions (they are not strictly necessary because
clang-format
does a decent job there without config), we would need to add at least these:I am not sure how to best approach it and would appreciate some guidance here. Should we have all these attribute macros inside
AttributeMacros
or should we aim for clang-format formatting them reasonably without configuration?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.
@HazardyKnusperkeks friendly ping. Any thoughts on including a few more attributes into the (the first list of 4 elements) vs landing this change and relying on implicit formatting of those as function names?
I am happy to choose one of the two options arbitrarily, but I don't have enough context on
clang-format
to understand which approach is preferable, so I would love to get an opinion from someone in theclang-format
community.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.
FWIW, not recognizing
foo
inint foo BAR
as start-of-name looks like a big enough regression (which seems to be the main reason behind the line-braking behavior change), independent of whatever we do with the list of attribute-macros, I believe we should still make sure annotations forfoo
are correct rather urgently. so I am actually still in favor of landing this patch as-is, rather than trying to fix final formatting in a bunch of special cases by updatingAtrributeMacros
list.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.
I'm open in all directions.
When clang-format does format attribute macros out of the box correctly, that is nice. But I wouldn't put (too much) work into it, if declaring them to clang-format as what they are fixes all misformatting.
Thus I would keep the entries in
AttributeMacros
.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.
I think we should postpone the inclusion of those names into
AtrributeMacros
and land the patch as is.It seems that there is agreement among everyone that having this formatting without explicit
AtrributeMacros
is desirable, so landing as is is a no-brainer.Whether we should add common macro names into
AttributeMacros
is more contentious, so I think we may need more data to back up our decision to go either way. I have some examples where not having those names in the config leads to undesirable formatting, but I would share them in a follow-up conversation.