diff --git a/CHANGELOG.md b/CHANGELOG.md index d3979e4e5..e957cdf72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ - Fix Incorrect semantic highlighting of `external` declarations https://github.com/rescript-lang/rescript-vscode/pull/517 +- Fix issue where doc comment with nested comments inside is not shown properly on hover https://github.com/rescript-lang/rescript-vscode/pull/526 + ## v1.4.2 #### :bug: Bug Fix diff --git a/analysis/src/PrepareUtils.ml b/analysis/src/PrepareUtils.ml deleted file mode 100644 index 5554d1ae9..000000000 --- a/analysis/src/PrepareUtils.ml +++ /dev/null @@ -1,45 +0,0 @@ -let findStars line = - let l = String.length line in - let rec loop i = - if i >= l - 1 then None - else if line.[i] = '*' && line.[i + 1] = ' ' then Some (i + 2) - else if line.[i] <> ' ' then None - else loop (i + 1) - in - loop 0 - -let combine one two = - match (one, two) with - | None, None -> None - | Some a, None -> Some a - | None, Some b -> Some b - | Some a, Some b -> if a = b then Some a else Some 0 - -let trimFirst num string = - let length = String.length string in - if length > num then String.sub string num (length - num) else "" - -let cleanOffStars doc = - let lines = Str.split (Str.regexp_string "\n") doc in - let rec loop lines = - match lines with - | [] -> None - | [one] -> ( - match String.trim one with - | "" -> None - | _ -> findStars one) - | one :: rest -> ( - match String.trim one with - | "" -> loop rest - | _ -> combine (findStars one) (loop rest)) - in - let num = loop lines in - match num with - | None | Some 0 -> doc - | Some num -> ( - match lines with - | [] | [_] -> doc - | one :: rest -> - (if findStars one <> None then trimFirst num one else String.trim one) - ^ "\n" - ^ String.concat "\n" (rest |> List.map (trimFirst num))) diff --git a/analysis/src/ProcessAttributes.ml b/analysis/src/ProcessAttributes.ml index 9a2272ebc..f7a432d20 100644 --- a/analysis/src/ProcessAttributes.ml +++ b/analysis/src/ProcessAttributes.ml @@ -14,7 +14,7 @@ let rec findDocAttribute attributes = }; ] ) :: _ -> - Some (PrepareUtils.cleanOffStars doc) + Some doc | _ :: rest -> findDocAttribute rest let rec findDeprecatedAttribute attributes = diff --git a/analysis/tests/src/DocComments.res b/analysis/tests/src/DocComments.res new file mode 100644 index 000000000..a6c3c15fc --- /dev/null +++ b/analysis/tests/src/DocComments.res @@ -0,0 +1,46 @@ +@ns.doc(" Doc comment with a triple-backquote example + + ```res example + let a = 10 + /* + * stuff + */ + ``` +") +let docComment1 = 12 +// ^hov + +/** + Doc comment with a triple-backquote example + + ```res example + let a = 10 + /* + * stuff + */ + ``` +*/ +let docComment2 = 12 +// ^hov + + +@ns.doc(" Doc comment with a triple-backquote example + + ```res example + let a = 10 + let b = 20 + ``` +") +let docCommentNoNested1 = 12 +// ^hov + +/** + Doc comment with a triple-backquote example + + ```res example + let a = 10 + let b = 20 + ``` +*/ +let docCommentNoNested2 = 12 +// ^hov diff --git a/analysis/tests/src/expected/DocComments.res.txt b/analysis/tests/src/expected/DocComments.res.txt new file mode 100644 index 000000000..5cd5104b9 --- /dev/null +++ b/analysis/tests/src/expected/DocComments.res.txt @@ -0,0 +1,12 @@ +Hover src/DocComments.res 9:9 +{"contents": "```rescript\nint\n```\n\n Doc comment with a triple-backquote example\\n \\n ```res example\\n let a = 10\\n /*\\n * stuff\\n */\\n ```\\n"} + +Hover src/DocComments.res 22:6 +{"contents": "```rescript\nint\n```\n\n\n Doc comment with a triple-backquote example\n \n ```res example\n let a = 10\n /*\n * stuff\n */\n ```\n"} + +Hover src/DocComments.res 33:9 +{"contents": "```rescript\nint\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 44:6 +{"contents": "```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"} +