-
Notifications
You must be signed in to change notification settings - Fork 965
More fine-grained file-lines #1836
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
Conversation
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.
A couple of minor code-tidiness comments inline
src/visitor.rs
Outdated
|
|
||
| impl<'a> FmtVisitor<'a> { | ||
| // Return true if the given span does not intersect with file lines. | ||
| fn skip_span(&self, span: Span) -> bool { |
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 use the context version of skip_span rather than duplicating the code?
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.
We could, though we need to call get_context() everytime, which is a bit unfortunate.
src/visitor.rs
Outdated
| pub fn visit_item(&mut self, item: &ast::Item) { | ||
| if self.skip_span(item.span) { | ||
| return; | ||
| } |
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.
We could make this a macro and wouldn't have to repeat the if ... return.
|
Rebased with the change to use macro. |
|
I was super-excited to try this with bindgen, but this causes a bunch of undesired effects. Current STR (will try to find something more reduced later today):
diff --git a/src/lib.rs b/src/lib.rs
index 3a85382..1b68a0a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1268,7 +1268,7 @@ fn filter_builtins(ctx: &BindgenContext, cursor: &clang::Cursor) -> bool {
/// Parse one `Item` from the Clang cursor.
pub fn parse_one(ctx: &mut BindgenContext,
- cursor: clang::Cursor,
+ cursor: clang::Cursor,
parent: Option<ItemId>)
-> clang_sys::CXChildVisitResult {
if !filter_builtins(ctx, &cursor) {
rustfmt --file-lines '[{"range": [1268, 1274], "file": "src/lib.rs"}]' src/lib.rsExpected: Only the Actual: A lot of use statements and whitespace is missing, and also lines with comments misindented. |
|
This helps not to get them skipped, but the use statements still get reformatted / reordered: Disclaimer, no clue about whether it's the right fix :-) |
|
Ok, I also got a patch for the other issue, I'll try to add some tests :-) |
|
I opened #1841 with my fixes on top of this. Also, thanks @topecongiro! I was about to report too much stuff being formatted with file-lines, and you already had a fix up for review, that's awesome! :) |
|
Thanks for the changes! |
Currently rustfmt ignores file lines check for items.
Closes #1835.