Skip to content

fix extracted docs of types include escaped linebreaks in signature #891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions analysis/src/DocExtraction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,26 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
[
("id", Some (wrapInQuotes id));
("kind", Some (wrapInQuotes "value"));
("name", Some (name |> Json.escape |> wrapInQuotes));
("name", Some (name |> wrapInQuotes));
( "deprecated",
match deprecated with
| Some d -> Some (wrapInQuotes d)
| None -> None );
( "signature",
Some (signature |> String.trim |> Json.escape |> wrapInQuotes) );
Some (signature |> String.trim |> wrapInQuotes) );
("docstrings", Some (stringifyDocstrings docstring));
]
| Type {id; docstring; signature; name; deprecated; detail} ->
stringifyObject ~startOnNewline:true ~indentation
[
("id", Some (wrapInQuotes id));
("kind", Some (wrapInQuotes "type"));
("name", Some (name |> Json.escape |> wrapInQuotes));
("name", Some (name |> wrapInQuotes));
( "deprecated",
match deprecated with
| Some d -> Some (wrapInQuotes d)
| None -> None );
("signature", Some (signature |> Json.escape |> wrapInQuotes));
("signature", Some (signature |> wrapInQuotes));
("docstrings", Some (stringifyDocstrings docstring));
( "detail",
match detail with
Expand Down
3 changes: 3 additions & 0 deletions analysis/tests/src/DocExtractionRes.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ let make = name => {
/** Stuff goes offline.*/
let asOffline = (t: t) => {...t, online: false}

/** exotic identifier */
let \"SomeConstant\" = 12

module SomeInnerModule = {
/*** Another module level docstring here.*/
type status =
Expand Down
11 changes: 9 additions & 2 deletions analysis/tests/src/expected/DocExtractionRes.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ extracting docs for src/DocExtractionRes.res
"signature": "let asOffline: t => t",
"docstrings": ["Stuff goes offline."]
},
{
"id": "DocExtractionRes.SomeConstant\\",
"kind": "value",
"name": "SomeConstant\\",
"signature": "let SomeConstant\\: int",
"docstrings": ["exotic identifier"]
},
{
"id": "DocExtractionRes.SomeInnerModule",
"name": "SomeInnerModule",
Expand Down Expand Up @@ -77,7 +84,7 @@ extracting docs for src/DocExtractionRes.res
"id": "DocExtractionRes.SomeInnerModule.validInputs",
"kind": "type",
"name": "validInputs",
"signature": "type validInputs = [\\n | #\\\"needs-escaping\\\"\\n | #something\\n | #status(status)\\n | #withPayload(int)\\n]",
"signature": "type validInputs = [\n | #\"needs-escaping\"\n | #something\n | #status(status)\n | #withPayload(int)\n]",
"docstrings": ["These are all the valid inputs."]
},
{
Expand Down Expand Up @@ -118,7 +125,7 @@ extracting docs for src/DocExtractionRes.res
"id": "DocExtractionRes.AnotherModule.someVariantWithInlineRecords",
"kind": "type",
"name": "someVariantWithInlineRecords",
"signature": "type someVariantWithInlineRecords =\\n | SomeStuff({offline: bool})",
"signature": "type someVariantWithInlineRecords =\n | SomeStuff({offline: bool})",
"docstrings": ["Trying how it looks with an inline record in a variant."],
"detail":
{
Expand Down
1 change: 1 addition & 0 deletions tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#### :bug: Bug Fix

- Fix docstrings for module alias. Get internal docstrings of module file. https://github.com/rescript-lang/rescript-vscode/pull/878
- Fix extracted docs of types include escaped linebreaks in signature. https://github.com/rescript-lang/rescript-vscode/pull/891

## 0.3.0

Expand Down