Skip to content

Format docstrings with the new format tools command #7623

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 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
- Remove internal/unused `-bs-v` flag. https://github.com/rescript-lang/rescript/pull/7627
- Remove unused `-bs-D` and `-bs-list-conditionals` flags. https://github.com/rescript-lang/rescript/pull/7631

#### :rocket: New Feature

- Add experimental command to `rescript-tools` for extracting all ReScript code blocks from markdown, either a md-file directly, or inside of docstrings in ReScript code. https://github.com/rescript-lang/rescript/pull/7623

# 12.0.0-beta.1

#### :rocket: New Feature
Expand Down
5 changes: 5 additions & 0 deletions analysis/src/Protocol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ let optWrapInQuotes s =
| None -> None
| Some s -> Some (wrapInQuotes s)

let stringifyResult = function
| Ok r -> stringifyObject [("TAG", Some (wrapInQuotes "Ok")); ("_0", Some r)]
| Error e ->
stringifyObject [("TAG", Some (wrapInQuotes "Error")); ("_0", Some e)]

let stringifyCompletionItem c =
stringifyObject
[
Expand Down
3 changes: 3 additions & 0 deletions lib/es6/RescriptTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

let Docgen;

let ExtractCodeBlocks;

export {
Docgen,
ExtractCodeBlocks,
}
/* No side effect */
1 change: 1 addition & 0 deletions lib/es6/RescriptTools_ExtractCodeBlocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
2 changes: 1 addition & 1 deletion lib/es6/Stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function assertEqual(a, b) {
RE_EXN_ID: "Assert_failure",
_1: [
"Stdlib.res",
124,
122,
4
],
Error: new Error()
Expand Down
3 changes: 3 additions & 0 deletions lib/js/RescriptTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@

let Docgen;

let ExtractCodeBlocks;

exports.Docgen = Docgen;
exports.ExtractCodeBlocks = ExtractCodeBlocks;
/* No side effect */
1 change: 1 addition & 0 deletions lib/js/RescriptTools_ExtractCodeBlocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
2 changes: 1 addition & 1 deletion lib/js/Stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function assertEqual(a, b) {
RE_EXN_ID: "Assert_failure",
_1: [
"Stdlib.res",
124,
122,
4
],
Error: new Error()
Expand Down
49 changes: 21 additions & 28 deletions runtime/Belt.res
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,15 @@ let letters = ["a", "b", "c"]
let a = letters[0]
// Use a switch statement:
let capitalA =
switch a {
| Some(a) => Some(Js.String.toUpperCase(a))
| None => None
}
let capitalA = switch a {
| Some(a) => Some(Js.String.toUpperCase(a))
| None => None
}
let k = letters[10] // k == None
```
With that little bit of tweaking, our code now compiles successfully and is 100% free of runtime errors!
With that little bit of tweaking, our code now compiles successfully and is 100% free of runtime errors\!
### A Special Encoding for Collection Safety
Expand All @@ -150,31 +149,25 @@ We use a phantom type to solve the problem:
## Examples
```rescript
module Comparable1 =
Belt.Id.MakeComparable(
{
type t = (int, int)
let cmp = ((a0, a1), (b0, b1)) =>
switch Pervasives.compare(a0, b0) {
| 0 => Pervasives.compare(a1, b1)
| c => c
}
module Comparable1 = Belt.Id.MakeComparable({
type t = (int, int)
let cmp = ((a0, a1), (b0, b1)) =>
switch Pervasives.compare(a0, b0) {
| 0 => Pervasives.compare(a1, b1)
| c => c
}
)
})
let mySet1 = Belt.Set.make(~id=module(Comparable1))
module Comparable2 =
Belt.Id.MakeComparable(
{
type t = (int, int)
let cmp = ((a0, a1), (b0, b1)) =>
switch Pervasives.compare(a0, b0) {
| 0 => Pervasives.compare(a1, b1)
| c => c
}
module Comparable2 = Belt.Id.MakeComparable({
type t = (int, int)
let cmp = ((a0, a1), (b0, b1)) =>
switch Pervasives.compare(a0, b0) {
| 0 => Pervasives.compare(a1, b1)
| c => c
}
)
})
let mySet2 = Belt.Set.make(~id=module(Comparable2))
```
Expand All @@ -184,8 +177,8 @@ Here, the compiler would infer `mySet1` and `mySet2` having different type, so e
## Examples
```rescript
let mySet1: t<(int, int), Comparable1.identity>
let mySet2: t<(int, int), Comparable2.identity>
let mySet1: t<(int, int), Comparable1.identity> = %todo
let mySet2: t<(int, int), Comparable2.identity> = %todo
Comment on lines +180 to +181
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did this so it could be parsed/compiled.

```
`Comparable1.identity` and `Comparable2.identity` are not the same using our encoding scheme.
Expand Down
Loading