Skip to content

Commit

Permalink
Support both ns.doc/res.doc and ns.optional and res.optional for diff…
Browse files Browse the repository at this point in the history
…erent compiler versions.

See rescript-lang/rescript#5862
  • Loading branch information
cristianoc committed Nov 28, 2022
1 parent 300ab80 commit 544c789
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- Remove spacing between type definition in clients that do not support markdown links. https://github.com/rescript-lang/rescript-vscode/pull/619
- Rename custom LSP methods names. https://github.com/rescript-lang/rescript-vscode/pull/611
- 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.

#### :bug: Bug Fix

Expand Down
2 changes: 1 addition & 1 deletion analysis/src/ProcessAttributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let rec findDocAttribute attributes =
let open Parsetree in
match attributes with
| [] -> None
| ( {Asttypes.txt = "ocaml.doc" | "ns.doc"},
| ( {Asttypes.txt = "ocaml.doc" | "ns.doc" | "res.doc"},
PStr
[
{
Expand Down
4 changes: 4 additions & 0 deletions analysis/tests/src/DocComments.res
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ let docCommentNoNested1 = 12
*/
let docCommentNoNested2 = 12
// ^hov

@res.doc("New doc comment format")
let newDoc = 10
// ^hov
3 changes: 3 additions & 0 deletions analysis/tests/src/expected/DocComments.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ Hover src/DocComments.res 33:9
Hover src/DocComments.res 44:6
{"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"}}

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

2 changes: 1 addition & 1 deletion analysis/vendor/compiler-libs-406/printtyp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ and tree_of_constructor cd =
(name, args, Some ret)

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

0 comments on commit 544c789

Please sign in to comment.