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

FormatWriter: refactor scaladoc formatting, escape text a-la code fence #3036

Merged
merged 3 commits into from
Jan 12, 2022

Conversation

kitbellew
Copy link
Collaborator

Prepare for scalameta upgrade to next version (v4.4.32) which supports nested terms in scaladoc lists and tags.

@kitbellew kitbellew force-pushed the 3036 branch 2 times, most recently from 4f20e0a to 3651552 Compare January 7, 2022 07:05
@kitbellew kitbellew requested review from tgodzik and dos65 January 7, 2022 07:21
@kitbellew kitbellew changed the title FormatWriter: refactor scaladoc formatting, fix fenced code block indent FormatWriter: refactor scaladoc formatting, escape text a-la code fence Jan 8, 2022
Do not infer the position on the current, rather specify it explicitly
in the call.
Copy link
Member

@dos65 dos65 left a comment

Choose a reason for hiding this comment

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

Could you check the following case?

object a {
  /** 
   * - abc
   *   ```scala
   *   println("!!!")
   *   ```
   * - asdasd
   *
   */
}

Locally, after format I'm getting:

object a {

  /**
   *    - abc
   *  ```scala
   *  println("!!!")
   *  ```
   *    - asdasd
   */
}

Where MdCodeBlock should be indented by 3 space

@kitbellew
Copy link
Collaborator Author

Could you check the following case?

object a {
  /** 
   * - abc
   *   ```scala
   *   println("!!!")
   *   ```
   * - asdasd
   *
   */
}

Locally, after format I'm getting:

object a {

  /**
   *    - abc
   *  ```scala
   *  println("!!!")
   *  ```
   *    - asdasd
   */
}

Where MdCodeBlock should be indented by 3 space

@dos65 this change doesn't implement nesting yet, for that we need to release scalameta and upgrade this dependency here.

this change implements escaping of text which looks like a code fence but isn't.

Copy link
Member

@dos65 dos65 left a comment

Choose a reason for hiding this comment

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

LGTM!

Just one minor comment

Comment on lines 971 to 973
def checkFence(head: Char) =
(head == '`' || head == '~') && word.indexWhere(_ != head, 1) < 0
if (word.length >= 3 && checkFence(word(0)))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just if (word.startsWith("```") || word.startsWith("~~~"))?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i did it because the fence should consist of all characters being the same.

but now i am thinking that you might be right; we are trying to prevent a text to be interpreted as a fence, and text like ~~~scala will definitely be parsed into fence and info string.

Otherwise, depending on the indentation level, it might be mistaken for
a fenced code block, leading to non-idempotent formatting.
@kitbellew kitbellew merged commit c476bd4 into scalameta:master Jan 12, 2022
@kitbellew kitbellew deleted the 3036 branch January 12, 2022 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants