Skip to content

Commit b9bd407

Browse files
authored
Format docstrings with the new format tools command (#7623)
* format docstrings with the new format tools command * handle piped assertEqual * compiled files * add extraction command for code blocks * change transform to only work on structure items * refactor * change code block extraction approach to use the typed artifacts instead, since we need more info for each block than we do for formatting * add ExtractCodeBlocks to RescriptTools for simplicity * integrate code block extraction into doctests script * only include code blocks with tests in them * update analysis examples * fix last remaining format issues in runtime docstrings * update analysis test files * more test output * changelog * fix changelog
1 parent 8658e1c commit b9bd407

File tree

98 files changed

+2250
-2249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2250
-2249
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
- Clean up `config.ml`. https://github.com/rescript-lang/rescript/pull/7636
2626
- Rewatch: simplify getting bsc path. https://github.com/rescript-lang/rescript/pull/7634
2727

28+
#### :rocket: New Feature
29+
30+
- 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
31+
2832
# 12.0.0-beta.1
2933

3034
#### :rocket: New Feature

analysis/src/Protocol.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ let optWrapInQuotes s =
137137
| None -> None
138138
| Some s -> Some (wrapInQuotes s)
139139

140+
let stringifyResult = function
141+
| Ok r -> stringifyObject [("TAG", Some (wrapInQuotes "Ok")); ("_0", Some r)]
142+
| Error e ->
143+
stringifyObject [("TAG", Some (wrapInQuotes "Error")); ("_0", Some e)]
144+
140145
let stringifyCompletionItem c =
141146
stringifyObject
142147
[

lib/es6/RescriptTools.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
let Docgen;
55

6+
let ExtractCodeBlocks;
7+
68
export {
79
Docgen,
10+
ExtractCodeBlocks,
811
}
912
/* No side effect */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

lib/es6/Stdlib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID: "Assert_failure",
1313
_1: [
1414
"Stdlib.res",
15-
124,
15+
122,
1616
4
1717
],
1818
Error: new Error()

lib/js/RescriptTools.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33

44
let Docgen;
55

6+
let ExtractCodeBlocks;
7+
68
exports.Docgen = Docgen;
9+
exports.ExtractCodeBlocks = ExtractCodeBlocks;
710
/* No side effect */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

lib/js/Stdlib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID: "Assert_failure",
1313
_1: [
1414
"Stdlib.res",
15-
124,
15+
122,
1616
4
1717
],
1818
Error: new Error()

runtime/Belt.res

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,15 @@ let letters = ["a", "b", "c"]
130130
let a = letters[0]
131131
132132
// Use a switch statement:
133-
let capitalA =
134-
switch a {
135-
| Some(a) => Some(Js.String.toUpperCase(a))
136-
| None => None
137-
}
133+
let capitalA = switch a {
134+
| Some(a) => Some(Js.String.toUpperCase(a))
135+
| None => None
136+
}
138137
139138
let k = letters[10] // k == None
140139
```
141140
142-
With that little bit of tweaking, our code now compiles successfully and is 100% free of runtime errors!
141+
With that little bit of tweaking, our code now compiles successfully and is 100% free of runtime errors\!
143142
144143
### A Special Encoding for Collection Safety
145144
@@ -150,31 +149,25 @@ We use a phantom type to solve the problem:
150149
## Examples
151150
152151
```rescript
153-
module Comparable1 =
154-
Belt.Id.MakeComparable(
155-
{
156-
type t = (int, int)
157-
let cmp = ((a0, a1), (b0, b1)) =>
158-
switch Pervasives.compare(a0, b0) {
159-
| 0 => Pervasives.compare(a1, b1)
160-
| c => c
161-
}
152+
module Comparable1 = Belt.Id.MakeComparable({
153+
type t = (int, int)
154+
let cmp = ((a0, a1), (b0, b1)) =>
155+
switch Pervasives.compare(a0, b0) {
156+
| 0 => Pervasives.compare(a1, b1)
157+
| c => c
162158
}
163-
)
159+
})
164160
165161
let mySet1 = Belt.Set.make(~id=module(Comparable1))
166162
167-
module Comparable2 =
168-
Belt.Id.MakeComparable(
169-
{
170-
type t = (int, int)
171-
let cmp = ((a0, a1), (b0, b1)) =>
172-
switch Pervasives.compare(a0, b0) {
173-
| 0 => Pervasives.compare(a1, b1)
174-
| c => c
175-
}
163+
module Comparable2 = Belt.Id.MakeComparable({
164+
type t = (int, int)
165+
let cmp = ((a0, a1), (b0, b1)) =>
166+
switch Pervasives.compare(a0, b0) {
167+
| 0 => Pervasives.compare(a1, b1)
168+
| c => c
176169
}
177-
)
170+
})
178171
179172
let mySet2 = Belt.Set.make(~id=module(Comparable2))
180173
```
@@ -184,8 +177,8 @@ Here, the compiler would infer `mySet1` and `mySet2` having different type, so e
184177
## Examples
185178
186179
```rescript
187-
let mySet1: t<(int, int), Comparable1.identity>
188-
let mySet2: t<(int, int), Comparable2.identity>
180+
let mySet1: t<(int, int), Comparable1.identity> = %todo
181+
let mySet2: t<(int, int), Comparable2.identity> = %todo
189182
```
190183
191184
`Comparable1.identity` and `Comparable2.identity` are not the same using our encoding scheme.

0 commit comments

Comments
 (0)