Skip to content
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

reflow #95

Closed
wants to merge 97 commits into from
Closed

reflow #95

wants to merge 97 commits into from

Conversation

drahnr
Copy link
Owner

@drahnr drahnr commented Aug 19, 2020

What does this PR accomplish?

Pushing #72 over the 🏁

  • 🦚 Feature

Closes #39

Changes proposed by this PR:

Remaining Challenges

  • a span is not a 1:1 mapping of a line
  • user selection must work with multiline suggestions (related to / covered by reflow #95 )
  • provide the same logic of --code exit code flags like we do for check
  • assure test cases cover all variant types with all possible single/multiline variations

Notes to reviewer:

📜 Checklist

  • Works on the ./demo sub directory
  • Test coverage is excellent and passes
  • Documentation is thorough

@drahnr drahnr requested a review from KuabeM August 19, 2020 11:39
src/reflow/mod.rs Outdated Show resolved Hide resolved
@drahnr drahnr requested a review from laysauchoa August 26, 2020 12:37
src/reflow/config.rs Outdated Show resolved Hide resolved
src/reflow/iter.rs Show resolved Hide resolved
src/reflow/iter.rs Show resolved Hide resolved
src/reflow/iter.rs Outdated Show resolved Hide resolved
src/reflow/iter.rs Outdated Show resolved Hide resolved
src/reflow/mod.rs Outdated Show resolved Hide resolved
src/documentation/chunk.rs Outdated Show resolved Hide resolved
src/reflow/mod.rs Outdated Show resolved Hide resolved
src/reflow/mod.rs Outdated Show resolved Hide resolved
src/reflow/mod.rs Outdated Show resolved Hide resolved
Copy link
Owner Author

@drahnr drahnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty well, I have yet to test this, a few nits as per usual 🛩️

@drahnr

This comment has been minimized.

@drahnr
Copy link
Owner Author

drahnr commented Sep 1, 2020

The assumption that there is one span per line is incorrect though.

Counter example:

#[doc=r#"yada
yada
"#]

@drahnr
Copy link
Owner Author

drahnr commented Sep 1, 2020

Added initial hooks for args and forwarding all of that, there are still a few 🚧 areas which need resolving.

Checklist moved to initial PR comment.

@KuabeM
Copy link
Collaborator

KuabeM commented Sep 2, 2020

Regarding the Span to line mapping: We can't really do something about that, the only (hacky) workaround I can think of is to count the number of whitespaces on multiline spans. In other words, use span.start for the first line of the span and we have to count the whitespaces for all subsequent lines.

src/documentation/chunk.rs Outdated Show resolved Hide resolved
src/documentation/chunk.rs Outdated Show resolved Hide resolved
@drahnr
Copy link
Owner Author

drahnr commented Sep 2, 2020

Not sure I understand your last comment. Do you mean newlines I stead of spaces? Not sure how that will help us here?

I think for doc=#r" comments we would be able to reflow, for doc=" the newlines would need to be escaped but any indent after the first would either be identical or set to 0.

src/documentation/chunk.rs Outdated Show resolved Hide resolved
r#" Some more text after the rule which represents a
paragraph"#,
];

Copy link
Owner Author

@drahnr drahnr Sep 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reflow check here is correct, but we could never use this as a direct replacement, since it would cover additional lines.
We would need a injection suggestion with a source span length of 0 (so nothing is removed, only text is inserted at that position). If this is the case, the comment type (/// in this case ) needs to be added as a injection for any additional lines inserted.

Semantically a "change" (to disambiguate) might have multiple spans it's going to cover, where a suggestion is only for one particular span - that's how it's modelled right now. I would stick with that, since all the selection code depends on that iirc - semantically it would make sense to move suggestions into multispan handling and span -> replacement based map.

src/reflow/mod.rs Outdated Show resolved Hide resolved
src/reflow/mod.rs Outdated Show resolved Hide resolved
src/reflow/mod.rs Outdated Show resolved Hide resolved
src/reflow/mod.rs Outdated Show resolved Hide resolved
@drahnr
Copy link
Owner Author

drahnr commented Oct 7, 2020

Another rebase round to get CI going.

@drahnr
Copy link
Owner Author

drahnr commented Oct 7, 2020

Progress! 🚂

There is still one assertion that fails, but you are getting closer!

> cargo run -- reflow --code 27 -r demo/src/

    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `target/debug/cargo-spellcheck reflow --code 27 -r demo/src/`
[2020-10-07T07:15:31Z ERROR cargo_spellcheck::documentation::literalset] Adjacent literal is not the same comment variant: TripleSlash vs DoubleSlashEM
[2020-10-07T07:15:31Z ERROR cargo_spellcheck::documentation::literalset] Adjacent literal is not the same comment variant: MacroDocEq vs TripleSlash
[2020-10-07T07:15:31Z ERROR cargo_spellcheck::documentation::literalset] Adjacent literal is not the same comment variant: TripleSlash vs MacroDocEq
[2020-10-07T07:15:31Z ERROR cargo_spellcheck::documentation::literalset] Adjacent literal is not the same comment variant: MacroDocEq vs TripleSlash
[2020-10-07T07:15:31Z ERROR cargo_spellcheck::documentation::literalset] Adjacent literal is not the same comment variant: TripleSlash vs MacroDocEq
[2020-10-07T07:15:31Z ERROR cargo_spellcheck::documentation::literalset] Adjacent literal is not the same comment variant: TripleSlash vs DoubleSlashEM
[2020-10-07T07:15:31Z ERROR cargo_spellcheck::documentation::literalset] Adjacent literal is not the same comment variant: TripleSlash vs DoubleSlashEM
[2020-10-07T07:15:31Z ERROR cargo_spellcheck::documentation::literalset] Adjacent literal is not the same comment variant: MacroDocEq vs TripleSlash
[2020-10-07T07:15:31Z ERROR cargo_spellcheck::documentation::literalset] Adjacent literal is not the same comment variant: TripleSlash vs MacroDocEq
error: spellcheck(Reflow)
   --> /media/supersonic1t/projects/cargo-spellcheck/demo/src/nested/mod.rs:11
    |
 11 |  Overly long statements that should be reflown since they are __very__ long and exceed the line limit.
    |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

(1/6) Apply this suggestion [y,n,q,a,d,j,e,?]?

 »  Overly long statements that should be reflown since they are __very__ long
   ...                                                                        /// and exceed the line limit.
thread 'main' panicked at 'Extracting `Bandaid`s from `State` must not fail. qed: BUG: Found a range which does not cover its own chunk', src/action/interactive.rs:162:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

and one test is still going 💥

thread 'documentation::chunk::test::find_line_length_docmacro' panicked at 'assertion failed: `(left == right)`
  left: `20`,
 right: `23`', src/documentation/chunk.rs:786:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    documentation::chunk::test::find_line_length_docmacro

Copy link
Owner Author

@drahnr drahnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍 I have yet to test it, but looks good!

src/action/bandaidset.rs Outdated Show resolved Hide resolved
src/documentation/literal.rs Outdated Show resolved Hide resolved
src/documentation/literal.rs Outdated Show resolved Hide resolved
KuabeM and others added 12 commits October 17, 2020 11:13
Note that this is extremely ugly, and the concerns need to be split between
the `Reflow` checker creating better replacements and defining more strictly
what the concren of `fn correct_lines` truely is. Imho, it should be a dumb
replacer, taking spans and doing something to them, the fact that it is
line based doesn't do us any good now, it should accept arbitrary spans
with replacement text, something that is derived from `BandAid`,
not necessarily bandaids themselves. `fn correct_lines` then should just
traverse the file content and patch the relevant Spans (inject or replace,
where delete is just shortcut for replacing something with an empty string literal)
removing the whole concept of lines other than as a referential system.
This will also aleviate the replacing bogus issues arising from replacing
newlines char types with \n.
Part one as outlined in the previous description.
Copy link
Owner Author

@drahnr drahnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change you cannot represent insertions with BandAid anymore, can you? A span is by definition at least length 1 since the start and end members are inclusive.

@KuabeM
Copy link
Collaborator

KuabeM commented Oct 24, 2020

With this change you cannot represent insertions with BandAid anymore, can you? A span is by definition at least length 1 since the start and end members are inclusive.

We don't need any insertions. Any BandAid always replaces something.

@KuabeM KuabeM mentioned this pull request Oct 24, 2020
3 tasks
@drahnr drahnr closed this Oct 24, 2020
@drahnr drahnr deleted the bernhard-reflow branch January 21, 2021 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checker / reflow reflow related topics enhancement 🦚 New feature or request heavy-duty 🚜 Big features not easy to implement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reflow documentation comments + markdown files
3 participants