Skip to content

Commit 5506990

Browse files
committed
Support both ns.doc/res.doc and ns.optional and res.optional for different compiler versions.
See rescript-lang/rescript#5862
1 parent 300ab80 commit 5506990

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
- Remove spacing between type definition in clients that do not support markdown links. https://github.com/rescript-lang/rescript-vscode/pull/619
1818
- Rename custom LSP methods names. https://github.com/rescript-lang/rescript-vscode/pull/611
19+
- Accept both `@ns.doc` and the new `@res.doc` for the internal representation of doc comments. And both `@ns.optional` and `@res.optional` for the optional fields. https://github.com/rescript-lang/rescript-vscode/pull/642
1920

2021
#### :bug: Bug Fix
2122

analysis/src/ProcessAttributes.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let rec findDocAttribute attributes =
55
let open Parsetree in
66
match attributes with
77
| [] -> None
8-
| ( {Asttypes.txt = "ocaml.doc" | "ns.doc"},
8+
| ( {Asttypes.txt = "ocaml.doc" | "ns.doc" | "res.doc"},
99
PStr
1010
[
1111
{

analysis/tests/src/DocComments.res

+4
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ let docCommentNoNested1 = 12
4444
*/
4545
let docCommentNoNested2 = 12
4646
// ^hov
47+
48+
@res.doc("New doc comment format")
49+
let newDoc = 10
50+
// ^hov

analysis/tests/src/expected/DocComments.res.txt

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ Hover src/DocComments.res 33:9
1010
Hover src/DocComments.res 44:6
1111
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n\n\n Doc comment with a triple-backquote example\n \n ```res example\n let a = 10\n let b = 20\n ```\n"}}
1212

13+
Hover src/DocComments.res 48:5
14+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n\nNew doc comment format"}}
15+

analysis/vendor/compiler-libs-406/printtyp.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ and tree_of_constructor cd =
926926
(name, args, Some ret)
927927

928928
and tree_of_label l =
929-
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional") in
929+
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional" || txt = "res.optional") in
930930
let typ = match l.ld_type.desc with
931931
| Tconstr (p, [t1], _) when opt && Path.same p Predef.path_option -> t1
932932
| _ -> l.ld_type in

0 commit comments

Comments
 (0)