Skip to content

Commit 13d274c

Browse files
Address review comments
1 parent fcc448a commit 13d274c

File tree

28 files changed

+182
-31
lines changed

28 files changed

+182
-31
lines changed

CHANGELOG.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,26 @@
204204
deprecated environment variables.
205205
([Surya Rose](https://github.com/GearsDatapacks))
206206

207-
- When generating documentation, the build tool now prints correct type variable
208-
names for function signatures. For example, this code:
207+
- When generating documentation, the build tool now prints type variable using
208+
the same names as were used in the code for function signatures. For example,
209+
this code:
209210

210211
```gleam
211-
pub fn to_list(list: List(#(key, value))) -> Dict(key, value) {
212+
pub fn to_list(entries: List(#(key, value))) -> Dict(key, value) {
212213
...
213214
}
214215
```
215216

216217
Previously would have been printed as:
217218

218219
```gleam
219-
pub fn to_list(list: List(#(a, b))) -> Dict(a, b)
220+
pub fn to_list(entries: List(#(a, b))) -> Dict(a, b)
220221
```
221222

222223
But now is rendered as the following:
223224

224225
```gleam
225-
pub fn to_list(list: List(#(key, value))) -> Dict(key, value)
226+
pub fn to_list(entries: List(#(key, value))) -> Dict(key, value)
226227
```
227228

228229
([Surya Rose](https://github.com/GearsDatapacks))

compiler-core/src/docs/printer.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ impl Printer<'_> {
127127
source_url: source_links.url(*location),
128128
opaque: *opaque,
129129
}),
130-
131130
Definition::TypeAlias(TypeAlias {
132131
publicity: Publicity::Public,
133132
location,
@@ -150,8 +149,11 @@ impl Printer<'_> {
150149
},
151150
opaque: false,
152151
}),
153-
154-
_ => None,
152+
Definition::TypeAlias(_)
153+
| Definition::CustomType(_)
154+
| Definition::Function(_)
155+
| Definition::Import(_)
156+
| Definition::ModuleConstant(_) => None,
155157
}
156158
}
157159

@@ -208,7 +210,11 @@ impl Printer<'_> {
208210
},
209211
}),
210212

211-
_ => None,
213+
Definition::TypeAlias(_)
214+
| Definition::CustomType(_)
215+
| Definition::Function(_)
216+
| Definition::Import(_)
217+
| Definition::ModuleConstant(_) => None,
212218
}
213219
}
214220

@@ -436,7 +442,7 @@ impl Printer<'_> {
436442

437443
loop {
438444
n = rest % alphabet_length;
439-
rest /= alphabet_length;
445+
rest = rest / alphabet_length;
440446
chars.push((n as u8 + char_offset) as char);
441447

442448
if rest == 0 {

compiler-core/src/docs/snapshots/gleam_core__docs__tests__canonical_link.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMar
598598
599599
</div>
600600
601-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>() -> <span class="hljs-title">Int</span></code></pre>
601+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>() -> <span class="hljs-title">Int</span></code></pre>
602602
603603
<div class="rendered-markdown"><p>Here is some documentation</p>
604604
</div>
@@ -965,7 +965,7 @@ expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMar
965965
966966
</div>
967967
968-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>() -> <span class="hljs-title">Int</span></code></pre>
968+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>() -> <span class="hljs-title">Int</span></code></pre>
969969
970970
<div class="rendered-markdown"><p>Here is some documentation</p>
971971
</div>

compiler-core/src/docs/snapshots/gleam_core__docs__tests__discarded_arguments_are_not_shown.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ expression: "compile(config, modules)"
264264
265265
</div>
266266
267-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">discard</span>(<span class="hljs-variable">discarded</span>: <span class="hljs-variable">a</span>) -> <span class="hljs-title">Int</span></code></pre>
267+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">discard</span>(<span class="hljs-variable">discarded</span>: <span class="hljs-variable">a</span>) -> <span class="hljs-title">Int</span></code></pre>
268268
269269
<div class="rendered-markdown"></div>
270270
</div>

compiler-core/src/docs/snapshots/gleam_core__docs__tests__docs_of_a_type_constructor_are_not_used_by_the_following_function.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ expression: "compile(config, modules)"
272272
273273
<div class="custom-type-constructors">
274274
<div class="rendered-markdown"></div>
275-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub type </span><span class="hljs-title">Wibble</span> {
275+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub type </span><span class="hljs-title">Wibble</span> {
276276
<span class="hljs-title">Wobble</span>(<span class="hljs-variable">wabble</span>: <span class="hljs-title">Int</span>)
277277
}</code></pre>
278278
@@ -284,7 +284,7 @@ expression: "compile(config, modules)"
284284
<li class="constructor-item">
285285
<div class="constructor-row">
286286
<svg class="icon icon-star"><use xlink:href="#icon-star"></use></svg>
287-
<pre class="constructor-name"><code class="hljs gleam hljs-ignore"><span class="hljs-title">Wobble</span>(<span class="hljs-variable">wabble</span>: <span class="hljs-title">Int</span>)</code></pre>
287+
<pre class="constructor-name"><code class="hljs hljs-ignore"><span class="hljs-title">Wobble</span>(<span class="hljs-variable">wabble</span>: <span class="hljs-title">Int</span>)</code></pre>
288288
</div>
289289
290290
<div class="constructor-item-docs">
@@ -335,7 +335,7 @@ expression: "compile(config, modules)"
335335
336336
</div>
337337
338-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">main</span>() -> <span class="hljs-variable">a</span></code></pre>
338+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">main</span>() -> <span class="hljs-variable">a</span></code></pre>
339339
340340
<div class="rendered-markdown"></div>
341341
</div>

compiler-core/src/docs/snapshots/gleam_core__docs__tests__generated_type_variables.snap

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- main.gleam
7+
8+
pub fn wibble(_a, _b, _c, _d) {
9+
todo
10+
}
11+
12+
513
---- VALUES
614

715
--- wibble

compiler-core/src/docs/snapshots/gleam_core__docs__tests__generated_type_variables_do_not_take_into_account_other_definitions.snap

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- main.gleam
7+
8+
pub fn wibble(_a: a, _b: b, _c: c) -> d {
9+
todo
10+
}
11+
12+
pub fn identity(x) { x }
13+
14+
515
---- VALUES
616

717
--- identity

compiler-core/src/docs/snapshots/gleam_core__docs__tests__generated_type_variables_mixed_with_existing_variables.snap

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- main.gleam
7+
8+
pub fn wibble(_a: b, _b: a, _c, _d) {
9+
todo
10+
}
11+
12+
513
---- VALUES
614

715
--- wibble

compiler-core/src/docs/snapshots/gleam_core__docs__tests__generated_type_variables_with_existing_variables_coming_afterwards.snap

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- main.gleam
7+
8+
pub fn wibble(_a, _b, _c: b, _d: a) {
9+
todo
10+
}
11+
12+
513
---- VALUES
614

715
--- wibble

compiler-core/src/docs/snapshots/gleam_core__docs__tests__hello_docs.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ expression: "compile(config, modules)"
264264
265265
</div>
266266
267-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>() -> <span class="hljs-title">Int</span></code></pre>
267+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>() -> <span class="hljs-title">Int</span></code></pre>
268268
269269
<div class="rendered-markdown"><p>Here is some documentation</p>
270270
</div>

compiler-core/src/docs/snapshots/gleam_core__docs__tests__highlight_constant_definition.snap

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- main.gleam
7+
8+
pub const x = 22
9+
10+
511
---- VALUES
612

713
--- x

compiler-core/src/docs/snapshots/gleam_core__docs__tests__highlight_custom_type.snap

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- main.gleam
7+
8+
pub type Wibble(a, b) {
9+
Wibble(a, i: Int)
10+
Wobble(b: b, c: String)
11+
}
12+
13+
514
---- TYPES
615

716
--- Wibble

compiler-core/src/docs/snapshots/gleam_core__docs__tests__highlight_function_definition.snap

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- main.gleam
7+
8+
pub fn wibble(list: List(Int), generic: a, function: fn(a) -> b) -> #(a, b) { todo }
9+
10+
511
---- VALUES
612

713
--- wibble

compiler-core/src/docs/snapshots/gleam_core__docs__tests__highlight_opaque_custom_type.snap

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- main.gleam
7+
8+
pub opaque type Wibble(a, b) {
9+
Wibble(a, i: Int)
10+
Wobble(b: b, c: String)
11+
}
12+
13+
514
---- TYPES
615

716
--- Wibble

compiler-core/src/docs/snapshots/gleam_core__docs__tests__highlight_type_alias.snap

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- main.gleam
7+
8+
pub type Option(a) = Result(a, Nil)
9+
10+
511
---- TYPES
612

713
--- Option

compiler-core/src/docs/snapshots/gleam_core__docs__tests__ignored_argument_is_called_arg.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ expression: "compile(config, modules)"
264264
265265
</div>
266266
267-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>(<span class="hljs-variable">arg</span>: <span class="hljs-variable">a</span>) -> <span class="hljs-title">Int</span></code></pre>
267+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>(<span class="hljs-variable">arg</span>: <span class="hljs-variable">a</span>) -> <span class="hljs-title">Int</span></code></pre>
268268
269269
<div class="rendered-markdown"></div>
270270
</div>

compiler-core/src/docs/snapshots/gleam_core__docs__tests__link_to_type_in_different_module.snap

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- gleam/dict.gleam
7+
pub type Dict(a, b)
8+
9+
-- main.gleam
10+
11+
import gleam/dict
12+
13+
pub fn make_dict() -> dict.Dict(a, b) { todo }
14+
15+
516
---- VALUES
617

718
--- make_dict

compiler-core/src/docs/snapshots/gleam_core__docs__tests__link_to_type_in_different_package.snap

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- gleam/dict.gleam
7+
pub type Dict(a, b)
8+
9+
-- main.gleam
10+
11+
import gleam/dict
12+
13+
pub fn make_dict() -> dict.Dict(a, b) { todo }
14+
15+
516
---- VALUES
617

718
--- make_dict

compiler-core/src/docs/snapshots/gleam_core__docs__tests__link_to_type_in_same_module.snap

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
source: compiler-core/src/docs/tests.rs
33
expression: output
44
---
5+
---- SOURCE CODE
6+
-- main.gleam
7+
8+
pub type Dict(a, b)
9+
10+
pub fn new() -> Dict(a, b) { todo }
11+
12+
513
---- TYPES
614

715
--- Dict

compiler-core/src/docs/snapshots/gleam_core__docs__tests__long_function_wrapping.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ expression: "compile(config, modules)"
272272
273273
<div class="custom-type-constructors">
274274
<div class="rendered-markdown"></div>
275-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub type </span><span class="hljs-title">Option</span>(<span class="hljs-variable">t</span>) {
275+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub type </span><span class="hljs-title">Option</span>(<span class="hljs-variable">t</span>) {
276276
<span class="hljs-title">Some</span>(<span class="hljs-variable">t</span>)
277277
<span class="hljs-title">None</span>
278278
}</code></pre>
@@ -285,7 +285,7 @@ expression: "compile(config, modules)"
285285
<li class="constructor-item">
286286
<div class="constructor-row">
287287
<svg class="icon icon-star"><use xlink:href="#icon-star"></use></svg>
288-
<pre class="constructor-name"><code class="hljs gleam hljs-ignore"><span class="hljs-title">Some</span>(<span class="hljs-variable">t</span>)</code></pre>
288+
<pre class="constructor-name"><code class="hljs hljs-ignore"><span class="hljs-title">Some</span>(<span class="hljs-variable">t</span>)</code></pre>
289289
</div>
290290
291291
<div class="constructor-item-docs">
@@ -298,7 +298,7 @@ expression: "compile(config, modules)"
298298
<li class="constructor-item">
299299
<div class="constructor-row">
300300
<svg class="icon icon-star"><use xlink:href="#icon-star"></use></svg>
301-
<pre class="constructor-name"><code class="hljs gleam hljs-ignore"><span class="hljs-title">None</span></code></pre>
301+
<pre class="constructor-name"><code class="hljs hljs-ignore"><span class="hljs-title">None</span></code></pre>
302302
</div>
303303
304304
<div class="constructor-item-docs">
@@ -333,7 +333,7 @@ expression: "compile(config, modules)"
333333
334334
</div>
335335
336-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">lazy_or</span>(
336+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">lazy_or</span>(
337337
<span class="hljs-variable">first</span>: <a href="#Option"><span class="hljs-title">Option</span></a>(<span class="hljs-variable">a</span>),
338338
<span class="hljs-variable">second</span>: <span class="hljs-keyword">fn</span>() -> <a href="#Option"><span class="hljs-title">Option</span></a>(<span class="hljs-variable">a</span>),
339339
) -> <a href="#Option"><span class="hljs-title">Option</span></a>(<span class="hljs-variable">a</span>)</code></pre>

compiler-core/src/docs/snapshots/gleam_core__docs__tests__markdown_code_from_function_comment_is_trimmed.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ expression: "compile(config, modules)"
264264
265265
</div>
266266
267-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">indentation_test</span>() -> <span class="hljs-variable">a</span></code></pre>
267+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">indentation_test</span>() -> <span class="hljs-variable">a</span></code></pre>
268268
269269
<div class="rendered-markdown"><p>Here’s an example code snippet:</p>
270270
<pre><code>wibble

compiler-core/src/docs/snapshots/gleam_core__docs__tests__no_hex_publish.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMar
584584
585585
</div>
586586
587-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>() -> <span class="hljs-title">Int</span></code></pre>
587+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>() -> <span class="hljs-title">Int</span></code></pre>
588588
589589
<div class="rendered-markdown"><p>Here is some documentation</p>
590590
</div>
@@ -944,7 +944,7 @@ expression: "compile_with_markdown_pages(config, modules, pages,\nCompileWithMar
944944
945945
</div>
946946
947-
<pre><code class="hljs gleam hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>() -> <span class="hljs-title">Int</span></code></pre>
947+
<pre><code class="hljs hljs-ignore"><span class="hljs-keyword">pub fn </span><span class="hljs-title">one</span>() -> <span class="hljs-title">Int</span></code></pre>
948948
949949
<div class="rendered-markdown"><p>Here is some documentation</p>
950950
</div>

0 commit comments

Comments
 (0)