Skip to content

Experimental command to format code blocks embedded in docstrings #7598

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
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

zth
Copy link
Collaborator

@zth zth commented Jul 4, 2025

Adds an experimental command to tools for formatting ReScript code blocks in docstrings.

I put it under tools just because that was the easiest place to put it. Feedback gladly accepted on where to put it.
I ran formatting on Stdlib_Result.resi so you can see an example of the results easily.

@zth zth marked this pull request as ready for review July 4, 2025 12:53
@zth zth requested review from cknitt, nojaf and fhammerschmidt July 4, 2025 12:54
@zth
Copy link
Collaborator Author

zth commented Jul 4, 2025

Looking in to why CI fails.

Copy link
Collaborator

@nojaf nojaf left a comment

Choose a reason for hiding this comment

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

Looks promising!
Will play with this once CI is green.

lineCount := currentLine + 1;
match (lines, !currentCodeBlockContents) with
| l :: rest, None ->
if String.trim l = "```rescript" then (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe check with a lowercase compare?
Allowing ReScript as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lowercase language identifier is the standard for tagging md code blocks. But we should probably add support for ```res as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Feels more like the thing you encountered the most in the wild rather than a hard standard.
https://github.github.com/gfm/#info-string does not mention casing.

@zth zth force-pushed the tools-format-code-blocks-in-docstrings branch from f7f994f to dc2cc93 Compare July 4, 2025 16:17
Copy link

pkg-pr-new bot commented Jul 4, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7598

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7598

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7598

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7598

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7598

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7598

commit: a35a867

@zth
Copy link
Collaborator Author

zth commented Jul 4, 2025

@nojaf some tweaking left, but please do play around with it if you want!

@zth zth requested a review from cristianoc July 4, 2025 18:17
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