-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: merge review suggestions from both clang tools #358
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
Open
2bndy5
wants to merge
1
commit into
main
Choose a base branch
from
join-tools-reviews
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: cpp-linter/cpp-linter-rs
Length of output: 4401
🏁 Script executed:
Repository: cpp-linter/cpp-linter-rs
Length of output: 133
🏁 Script executed:
Repository: cpp-linter/cpp-linter-rs
Length of output: 3857
🏁 Script executed:
# Look for imports to understand the diff library being used head -50 src/clang_tools/clang_format.rsRepository: cpp-linter/cpp-linter-rs
Length of output: 159
🏁 Script executed:
Repository: cpp-linter/cpp-linter-rs
Length of output: 140
🏁 Script executed:
Repository: cpp-linter/cpp-linter-rs
Length of output: 50
🏁 Script executed:
Repository: cpp-linter/cpp-linter-rs
Length of output: 324
🏁 Script executed:
Repository: cpp-linter/cpp-linter-rs
Length of output: 1074
🏁 Script executed:
Repository: cpp-linter/cpp-linter-rs
Length of output: 2190
🏁 Script executed:
Repository: cpp-linter/cpp-linter-rs
Length of output: 50
Use patched-file line ranges (hunk.after) when formatting the cached tidy output.
cmd.current_dir(&cache_path)formats the cached tidy-patched file, butjoint_rangesis built fromtidy_diff.hunks().before, which contains original-file coordinates. Sincemake_patch(&tidy_patch_contents, &original_contents)computesbeforeas original-file lines andafteras patched-file lines, usinghunk.beforetargets the wrong lines. Tidy fixes that insert or delete lines shift line numbers in the patched file; this mismatch can cause clang-format to skip formatting or produce invalid ranges like--lines=10:9for pure insertions.Suggested direction
Also translate any non-overlapping original
rangesbefore adding them tojoint_ranges, so every--linesargument refers to the cached patched file.🤖 Prompt for AI Agents
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.
This block is my main concern. I think I need to adjust the
ranges(declared prior to this block) to use the line numbers in the patched file by clang-tidy. Because some of the insertions/deletions may alter the original line numbers, therangesof original line numbers may be invalid.Can you suggestion a function that abstracts this block, returns
joint_rangeswith the adjusted&rangesas compared to the&tidy_diff?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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 5256
@2bndy5Here's a proposedcompute_format_rangeshelper. The key idea:hunk.after(nothunk.before). Pure-deletion hunks (whereafter.start == after.end) produce nothing for clang-format.rangethat is not fully contained inside a tidy hunk, translated to patched-file coordinates by accumulating the net line-count shift from all preceding tidy hunks.The call-site then becomes:
A couple of notes:
shiftaccumulation intentionally only counts hunks whosebefore.end <= range.start()— i.e., hunks completely before the range. Since we already skipped ranges overlapping a tidy hunk, the shift atrange.startandrange.endis the same (they sit in the same inter-hunk gap), so one shift value suffices for both endpoints.🧬 Code Graph Analysis Results
cpp-linter/src/clang_tools/clang_format.rsJoint-range construction block (the part your comment is concerned with)
Lines 159-186
Where
rangescomes fromLines 67-70
Where
tidy_diffcomes fromLines 153-158
cpp-linter/src/common_fs.rsFileObjfields that ultimately determine whatget_ranges()returnsLines 25-46
get_ranges()implementation (used to producerangesinclang_format.rs)Lines 48-324 (relevant excerpt:
get_ranges)cpp-linter/src/clang_tools/mod.rsPatch/diff creation used to compute
tidy_diffand the formatting diff hunksLines 328-336
🧠 Learnings used
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.
That's not an edge case. Its the complexity that I was implicating. I'm not dismissing the proposal, rather I was expecting more (thus the new function to abstract the complexity).
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.
@2bndy5, fair point — partial overlap is the real scenario to handle. Here's an updatedcompute_format_rangesthat fully handles it by splitting eachrangearound every overlapping tidy hunk, dropping the covered fragments, and translating the survivors to patched-file coordinates:The call-site simplifies to:
How the three cases are handled:
beforeThe
shiftaccumulation is safe because each surviving sub-segment sits in a gap between two adjacent hunks (or before the first / after the last), so every point within it has the same cumulative shift.🐇 ~(__)
🧠 Learnings used
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as off-topic.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.