Skip to content

Commit e969ad7

Browse files
authored
chore(graindoc)!: Remove section attribute (#1681)
* chore(graindoc)!: Remove section attribute * chore(stdlib): Remove section docblocks * chore(stdlib): Regenerate markdown docs
1 parent 58cd224 commit e969ad7

Some content is hidden

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

104 files changed

+386
-826
lines changed

compiler/graindoc/docblock.re

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let () =
3232
}
3333
});
3434

35-
let enumerate_exports = stmts => {
35+
let enumerate_provides = program => {
3636
let id_tbl = ref(Ident.empty);
3737

3838
let rec pattern_ids = ({pat_desc, pat_loc}: Typedtree.pattern) => {
@@ -48,7 +48,7 @@ let enumerate_exports = stmts => {
4848
};
4949
};
5050

51-
module ExportIterator =
51+
module ProvideIterator =
5252
TypedtreeIter.MakeIterator({
5353
include TypedtreeIter.DefaultIteratorArgument;
5454

@@ -89,13 +89,14 @@ let enumerate_exports = stmts => {
8989
};
9090
});
9191

92-
List.iter(ExportIterator.iter_toplevel_stmt, stmts);
92+
ProvideIterator.iter_typed_program(program);
9393

9494
id_tbl^;
9595
};
9696

97-
let location_for_ident = (~exports, ident) => {
98-
snd(Ident.find_name(Ident.name(ident), exports));
97+
let location_for_ident =
98+
(~provides: Ident.tbl(Grain_parsing.Location.t), ident) => {
99+
snd(Ident.find_name(Ident.name(ident), provides));
99100
};
100101

101102
let title_for_api = (~module_name, ident: Ident.t) => {
@@ -145,11 +146,12 @@ let lookup_type_expr = (~idx, type_exprs) => {
145146
let for_value_description =
146147
(
147148
~comments,
148-
~loc: Grain_parsing.Location.t,
149+
~provides,
149150
~module_name,
150151
~ident: Ident.t,
151152
vd: Types.value_description,
152153
) => {
154+
let loc = location_for_ident(~provides, ident);
153155
let name = title_for_api(~module_name, ident);
154156
let type_sig = Printtyp.string_of_value_description(~ident, vd);
155157
let comment =
@@ -185,11 +187,12 @@ let for_value_description =
185187
let for_type_declaration =
186188
(
187189
~comments,
188-
~loc: Grain_parsing.Location.t,
190+
~provides,
189191
~module_name,
190192
~ident: Ident.t,
191193
td: Types.type_declaration,
192194
) => {
195+
let loc = location_for_ident(~provides, ident);
193196
let name = title_for_api(~module_name, ident);
194197
let type_sig = Printtyp.string_of_type_declaration(~ident, td);
195198
let comment =
@@ -204,45 +207,6 @@ let for_type_declaration =
204207
{module_name, name, type_sig, description, attributes};
205208
};
206209

207-
let for_signature_item =
208-
(
209-
~comments,
210-
~exports: Ident.tbl(Grain_parsing.Location.t),
211-
~module_name,
212-
sig_item: Types.signature_item,
213-
) => {
214-
switch (sig_item) {
215-
| TSigValue(ident, vd) =>
216-
let loc = location_for_ident(~exports, ident);
217-
let docblock =
218-
for_value_description(~comments, ~module_name, ~ident, ~loc, vd);
219-
Some(docblock);
220-
| TSigType(ident, td, _rec) =>
221-
let loc = location_for_ident(~exports, ident);
222-
let docblock =
223-
for_type_declaration(~comments, ~module_name, ~ident, ~loc, td);
224-
Some(docblock);
225-
| _ => None
226-
};
227-
};
228-
229-
let signature_item_in_range =
230-
(
231-
~exports: Ident.tbl(Grain_parsing.Location.t),
232-
sig_item: Types.signature_item,
233-
range: Grain_utils.Range.t,
234-
) => {
235-
switch (sig_item) {
236-
| TSigValue(ident, vd) =>
237-
let loc = location_for_ident(~exports, ident);
238-
Grain_utils.Range.inRange(loc.loc_start.pos_lnum, range);
239-
| TSigType(ident, td, _rec) =>
240-
let loc = location_for_ident(~exports, ident);
241-
Grain_utils.Range.inRange(loc.loc_start.pos_lnum, range);
242-
| _ => false
243-
};
244-
};
245-
246210
// Used for joining multiple `@throws` annotations with the exact same type
247211
module StringMap = Map.Make(String);
248212

compiler/graindoc/graindoc.re

Lines changed: 90 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ let generate_docs =
8282
(~current_version, ~output=?, program: Typedtree.typed_program) => {
8383
let comments = Comments.to_ordered(program.comments);
8484

85-
let exports = Docblock.enumerate_exports(program.statements);
85+
let provides = Docblock.enumerate_provides(program);
8686

8787
let signature_items = program.signature.cmi_sign;
8888

@@ -182,61 +182,99 @@ let generate_docs =
182182
| None => ()
183183
};
184184

185-
let add_docblock = sig_item => {
186-
let docblock =
187-
Docblock.for_signature_item(
188-
~comments,
189-
~exports,
190-
~module_name,
191-
sig_item,
192-
);
193-
switch (docblock) {
194-
| Some(docblock) =>
195-
Buffer.add_buffer(
196-
buf,
197-
Docblock.to_markdown(~current_version, docblock),
198-
)
199-
| None => ()
200-
};
201-
};
185+
let sig_types =
186+
List.filter(
187+
(sig_item: Types.signature_item) => {
188+
switch (sig_item) {
189+
| TSigTypeExt(_)
190+
| TSigModule(_)
191+
| TSigModType(_)
192+
| TSigValue(_) => false
193+
| TSigType(_) => true
194+
}
195+
},
196+
signature_items,
197+
);
198+
199+
switch (sig_types) {
200+
| [] => ()
201+
| _ =>
202+
Buffer.add_string(buf, Markdown.heading(~level=2, "Types"));
203+
Buffer.add_string(
204+
buf,
205+
Markdown.paragraph(
206+
"Type declarations included in the " ++ module_name ++ " module.",
207+
),
208+
);
202209

203-
let section_comments = Comments.Doc.find_sections(comments);
204-
if (List.length(section_comments) == 0) {
205-
List.iter(add_docblock, signature_items);
206-
} else {
207-
List.iteri(
208-
(idx, (comment, desc, attrs)) => {
209-
let next_section_start_line =
210-
Option.fold(
211-
~none=max_int,
212-
~some=((comment, _, _)) => Comments.start_line(comment),
213-
List.nth_opt(section_comments, idx + 1),
210+
List.iter(
211+
(sig_type: Types.signature_item) => {
212+
switch (sig_type) {
213+
| TSigType(ident, td, _rec) =>
214+
let docblock =
215+
Docblock.for_type_declaration(
216+
~comments,
217+
~provides,
218+
~module_name,
219+
~ident,
220+
td,
221+
);
222+
Buffer.add_buffer(
223+
buf,
224+
Docblock.to_markdown(~current_version, docblock),
214225
);
215-
let range =
216-
Grain_utils.Range.Exclusive(
217-
Comments.end_line(comment),
218-
next_section_start_line,
226+
| _ => failwith("Unreachable: TSigType-only list")
227+
}
228+
},
229+
sig_types,
230+
);
231+
};
232+
233+
let sig_values =
234+
List.filter(
235+
(sig_item: Types.signature_item) => {
236+
switch (sig_item) {
237+
| TSigType(_)
238+
| TSigTypeExt(_)
239+
| TSigModule(_)
240+
| TSigModType(_) => false
241+
| TSigValue(_) => true
242+
}
243+
},
244+
signature_items,
245+
);
246+
247+
switch (sig_values) {
248+
| [] => ()
249+
| _ =>
250+
Buffer.add_string(buf, Markdown.heading(~level=2, "Values"));
251+
Buffer.add_string(
252+
buf,
253+
Markdown.paragraph(
254+
"Functions and constants included in the " ++ module_name ++ " module.",
255+
),
256+
);
257+
258+
List.iter(
259+
(sig_value: Types.signature_item) => {
260+
switch (sig_value) {
261+
| TSigValue(ident, vd) =>
262+
let docblock =
263+
Docblock.for_value_description(
264+
~comments,
265+
~provides,
266+
~module_name,
267+
~ident,
268+
vd,
269+
);
270+
Buffer.add_buffer(
271+
buf,
272+
Docblock.to_markdown(~current_version, docblock),
219273
);
220-
List.iter(
221-
(attr: Comment_attributes.t) => {
222-
switch (attr) {
223-
| Section({attr_name, attr_desc}) =>
224-
Buffer.add_string(buf, Markdown.heading(~level=2, attr_name));
225-
Buffer.add_string(buf, Markdown.paragraph(attr_desc));
226-
| _ => ()
227-
}
228-
},
229-
attrs,
230-
);
231-
List.iter(
232-
sig_item =>
233-
if (Docblock.signature_item_in_range(~exports, sig_item, range)) {
234-
add_docblock(sig_item);
235-
},
236-
signature_items,
237-
);
274+
| _ => failwith("Unreachable: TSigValue-only list")
275+
}
238276
},
239-
section_comments,
277+
sig_values,
240278
);
241279
};
242280

compiler/src/diagnostics/comment_attributes.re

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ type t =
1717
attr_desc,
1818
attr_type,
1919
})
20-
// Currently only accepts single-line examples
2120
| Example({attr_desc})
22-
| Section({
23-
attr_name,
24-
attr_desc,
25-
})
2621
| Deprecated({attr_desc})
2722
| Since({attr_version})
2823
| History({

compiler/src/diagnostics/comments.re

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ module Attribute = {
9090
};
9191
};
9292

93-
let is_section = attr => {
94-
switch (attr) {
95-
| Section(_) => true
96-
| _ => false
97-
};
98-
};
99-
10093
let is_deprecated = attr => {
10194
switch (attr) {
10295
| Deprecated(_) => true
@@ -255,16 +248,6 @@ module Doc = {
255248
};
256249
ending_on_lnum_help(lnum, true);
257250
};
258-
259-
let find_sections = (module C: OrderedComments) => {
260-
let section_comments = ref([]);
261-
C.iter((_, (_comment, _desc, attrs) as comment) =>
262-
if (List.exists(Attribute.is_section, attrs)) {
263-
section_comments := [comment, ...section_comments^];
264-
}
265-
);
266-
List.rev(section_comments^);
267-
};
268251
};
269252

270253
let print_comment = (comment: Parsetree.comment) => {

compiler/src/diagnostics/graindoc_lexer.re

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ and lexer_mode =
6060
| Start
6161
| Default
6262
| Param
63-
| Section
6463
| Since
6564
| History
6665
| Throws
@@ -71,7 +70,6 @@ let rec token = (state, lexbuf) => {
7170
| Start => start(state, lexbuf)
7271
| Default => default(state, lexbuf)
7372
| Param => param(state, lexbuf)
74-
| Section => section(state, lexbuf)
7573
| Since => since(state, lexbuf)
7674
| History => history(state, lexbuf)
7775
| Throws => throws(state, lexbuf)
@@ -102,9 +100,6 @@ and default = (state, lexbuf) => {
102100
| "@example" =>
103101
state.lexer_mode = FreeTextAttribute;
104102
EXAMPLE;
105-
| "@section" =>
106-
state.lexer_mode = Section;
107-
SECTION;
108103
| "@deprecated" =>
109104
state.lexer_mode = FreeTextAttribute;
110105
DEPRECATED;

compiler/src/diagnostics/graindoc_parser.messages

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,6 @@ graindoc: THROWS CONSTRUCTOR THROWS
125125
## The known suffix of the stack is as follows:
126126
## THROWS CONSTRUCTOR
127127
##
128-
graindoc: SECTION TEXT THROWS
129-
##
130-
## Ends in an error in state: 24.
131-
##
132-
## attribute -> SECTION TEXT . COLON attribute_text [ THROWS SINCE SECTION RETURNS PARAM HISTORY EXAMPLE EOL EOF DEPRECATED ]
133-
##
134-
## The known suffix of the stack is as follows:
135-
## SECTION TEXT
136-
##
137128
graindoc: PARAM IDENT THROWS
138129
##
139130
## Ends in an error in state: 30.
@@ -175,15 +166,6 @@ graindoc: DEPRECATED EOL THROWS
175166
## The known suffix of the stack is as follows:
176167
## eols
177168
##
178-
graindoc: SECTION TEXT COLON THROWS
179-
##
180-
## Ends in an error in state: 25.
181-
##
182-
## attribute -> SECTION TEXT COLON . attribute_text [ THROWS SINCE SECTION RETURNS PARAM HISTORY EXAMPLE EOL EOF DEPRECATED ]
183-
##
184-
## The known suffix of the stack is as follows:
185-
## SECTION TEXT COLON
186-
##
187169
graindoc: RETURNS THROWS
188170
##
189171
## Ends in an error in state: 27.
@@ -253,18 +235,6 @@ graindoc: HISTORY THROWS
253235

254236
Expected a version number in Semantic Versioning format, e.g. `v1.2.3`.
255237

256-
graindoc: SECTION THROWS
257-
##
258-
## Ends in an error in state: 23.
259-
##
260-
## attribute -> SECTION . TEXT COLON attribute_text [ THROWS SINCE SECTION RETURNS PARAM HISTORY EXAMPLE EOL EOF DEPRECATED ]
261-
##
262-
## The known suffix of the stack is as follows:
263-
## SECTION
264-
##
265-
266-
Expected a section title.
267-
268238
graindoc: PARAM THROWS
269239
##
270240
## Ends in an error in state: 29.

compiler/src/diagnostics/graindoc_parser.mly

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ attribute:
3030
| PARAM IDENT COLON attribute_text { Param({ attr_name=$2; attr_type=None; attr_desc=$4 }) }
3131
| RETURNS attribute_text { Returns({ attr_desc=$2; attr_type=None }) }
3232
| EXAMPLE attribute_text { Example({attr_desc=$2}) }
33-
| SECTION TEXT COLON attribute_text { Section({ attr_name=$2; attr_desc=$4; }) }
3433
| DEPRECATED attribute_text { Deprecated({attr_desc=$2}) }
3534
| SINCE SEMVER { Since({attr_version=$2}) }
3635
| HISTORY SEMVER COLON attribute_text { History({ attr_version=$2; attr_desc=$4; }) }

0 commit comments

Comments
 (0)