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

Format markdown files and rust code blocks in markdown files #5909

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Commits on Sep 12, 2023

  1. Make ParseSess an optional arg to FormatHandler::handle_formatted_file

    The only implementaiton of the `FormatHandler` trait is the one
    implemented for `Session`, and in that implementation we pass the
    `ParseSess` to `source_file::write_file`, which also takes the
    `ParseSess` as an optional argument.
    
    looking at the implementation of `source_file::write_file`, the
    `ParseSess` is optionally used to determine the file's original line
    ending instead of reading the file from the file system again to do so.
    
    Given the above explanation, I don't think there's any issue changing
    the signature of `FormatHandler::handle_formatted_file` and the
    implementation of `FormatHandler for Session`.
    ytmimi committed Sep 12, 2023
    Configuration menu
    Copy the full SHA
    6752286 View commit details
    Browse the repository at this point in the history
  2. update visibility of items related to markdown code block formatting

    The visibility of several private items in comments.rs were updated to
    `pub(crate)`. These items will help when adding support for formatting
    rust code blocks in markdown files.
    ytmimi committed Sep 12, 2023
    Configuration menu
    Copy the full SHA
    0d4c4f6 View commit details
    Browse the repository at this point in the history
  3. add CodeBlockAttribute::is_formattable_rust method

    A helper method used to determine if the code block contains rust code
    that should be formatted. This will help when implementing rust code
    block formatting in markdown files.
    ytmimi committed Sep 12, 2023
    Configuration menu
    Copy the full SHA
    1adcbf1 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    beef9c5 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    b87db9c View commit details
    Browse the repository at this point in the history
  6. implement formatting code blocks in markdown files

    The `rewrite_markdown` function will take markdown as input and apply
    rustfmt on rust code blocks. Because of how `pulldown-cmark-to-cmark`
    is implemented there will be some light rewriting of the markdown file
    outside of code block reformatting. This mostly relates to updating
    newlines after markdown elements like headers and lists, and possibly
    updating the indentation of indented code blocks.
    
    In the future we may even consider implementing doc comment rewriting in
    terms of `rewrite_markdown`.
    ytmimi committed Sep 12, 2023
    Configuration menu
    Copy the full SHA
    2295119 View commit details
    Browse the repository at this point in the history
  7. Allow users to format rust code in markdown code blocks

    Now users can envoke rustfmt directly with a markdown file and the rust
    code within that file will be reformatted e.g. `rustfmt README.md`
    ytmimi committed Sep 12, 2023
    Configuration menu
    Copy the full SHA
    35c2f31 View commit details
    Browse the repository at this point in the history
  8. Allow mardown files in system tests

    This will make it easeir to write tests for markdown codeblock
    reformatting.
    ytmimi committed Sep 12, 2023
    Configuration menu
    Copy the full SHA
    079c3af View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    f445fee View commit details
    Browse the repository at this point in the history