Skip to content

Commit 60c2166

Browse files
committed
Add more exhaustive tests for docstring markdown conversion
1 parent 67d6b9b commit 60c2166

File tree

2 files changed

+127
-26
lines changed

2 files changed

+127
-26
lines changed

ocaml-lsp-server/src/doc_to_md.ml

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ open Cmarkit
33

44
(** TODO:
55
6-
- Support meta from odoc-parser locations
7-
- Add support for references *)
6+
- Add support for references
7+
- Broken lists
8+
- Labels in headers
9+
- Align text with HTML
10+
- Verbatim is indented in tests
11+
12+
Unsupported (next):
13+
14+
- Support meta from odoc-parser locations *)
815

916
type t =
1017
| Raw of string
@@ -278,19 +285,8 @@ and block_element_list_to_block l =
278285
let translate doc : t =
279286
let location = Lexing.dummy_pos in
280287
let v = Odoc_parser.parse_comment ~location ~text:doc in
281-
match Odoc_parser.warnings v with
282-
| [] ->
283-
let ast = Odoc_parser.ast v in
284-
let block = block_element_list_to_block ast in
285-
let doc = Doc.make block in
286-
let cmark = Cmarkit_commonmark.of_doc doc in
287-
Markdown cmark
288-
| warnings ->
289-
let messages =
290-
List.map
291-
~f:(fun warn -> ("msg", `String (Odoc_parser.Warning.to_string warn)))
292-
warnings
293-
in
294-
Log.log ~section:"debug" (fun () ->
295-
Log.msg "Invalid documentation comment" messages);
296-
Raw doc
288+
let ast = Odoc_parser.ast v in
289+
let block = block_element_list_to_block ast in
290+
let doc = Doc.make block in
291+
let cmark = Cmarkit_commonmark.of_doc doc in
292+
Markdown cmark

ocaml-lsp-server/test/e2e/__tests__/textDocument-signatureHelp.ts

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,59 @@ describe_opt("textDocument/completion", () => {
244244
it("can return documentation for the function being applied", async () => {
245245
openDocument(
246246
outdent`
247-
(** This function has a nice documentation.
248-
249-
It performs division of two integer numbers.
250-
247+
(** This is an example of a docstring that demonstrates various ocamldoc syntax features.
248+
249+
{3 Sections and Labels}
250+
251+
We can create sections using {3 Section title} and labels using {3:label_name Section title with label}
252+
253+
{3 Links and Cross-references}
254+
255+
External links: {{:https://ocaml.org/} OCaml's official website}
256+
257+
{3 Inline Formatting}
258+
259+
{b Bold}, {i Italic}, {e Emphasize}, {^ Superscript}, {_ Subscript}, and [inline code]
260+
261+
{3 Text Alignment}
262+
263+
{C Centered text}
264+
{L Left-aligned text}
265+
{R Right-aligned text}
266+
267+
{3 Lists}
268+
269+
{ol
270+
{- Ordered list item 1}
271+
{- Ordered list item 2}
272+
}
273+
274+
{ul
275+
{- Unordered list item 1}
276+
{- Unordered list item 2}
277+
}
278+
279+
- Unordered list item 1
280+
- Unordered list item 2
281+
282+
{3 Code Blocks}
283+
284+
{[
285+
let square x = x * x
286+
let result = square 3
287+
]}
288+
289+
{3 Verbatim}
290+
291+
{v
292+
This text will be displayed verbatim.
293+
No formatting will be applied.
294+
v}
295+
296+
{3 Module List}
297+
298+
{!modules: Array List String}
299+
251300
@param x dividend
252301
@param divisor
253302
@@ -288,10 +337,66 @@ describe_opt("textDocument/completion", () => {
288337
],
289338
documentation: {
290339
kind: "markdown",
291-
value: outdent`
292-
This function has a nice documentation.
293-
294-
It performs division of two integer numbers.
340+
value: outdent`This is an example of a docstring that demonstrates various ocamldoc syntax features.
341+
342+
### Sections and Labels
343+
344+
We can create sections using
345+
346+
### Section title
347+
348+
and labels using
349+
350+
### Section title with label
351+
352+
### Links and Cross-references
353+
354+
External links: [OCaml's official website](https://ocaml.org/)
355+
356+
### Inline Formatting
357+
358+
**Bold**, *Italic*, *Emphasize*, Superscript, Subscript, and \`inline code\`
359+
360+
### Text Alignment
361+
362+
Centered text
363+
364+
Left-aligned text
365+
366+
Right-aligned text
367+
368+
### Lists
369+
370+
1.Ordered list item 1
371+
2.Ordered list item 2
372+
373+
*Unordered list item 1
374+
*Unordered list item 2
375+
376+
*Unordered list item 1
377+
*Unordered list item 2
378+
379+
### Code Blocks
380+
381+
\`\`\`
382+
let square x = x * x
383+
let result = square 3
384+
let result = square 3
385+
\`\`\`
386+
387+
### Verbatim
388+
389+
\`\`\`verb
390+
This text will be displayed verbatim.
391+
No formatting will be applied.
392+
No formatting will be applied.
393+
\`\`\`
394+
395+
### Module List
396+
397+
*Array
398+
*List
399+
*String
295400
296401
***@param*** \`x\`
297402
dividend

0 commit comments

Comments
 (0)