Skip to content

Commit d39e28c

Browse files
authored
fix extracted docs of types include escaped linebreaks in signature (#891)
* remove Json.escape, which is already called inside of Protocol.wrapInQuotes and update test * add test case for exotic identifier let \"SomeConstant\" = 12 * update tools/changelog
1 parent abebd90 commit d39e28c

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

analysis/src/DocExtraction.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,26 @@ let rec stringifyDocItem ?(indentation = 0) ~originalEnv (item : docItem) =
112112
[
113113
("id", Some (wrapInQuotes id));
114114
("kind", Some (wrapInQuotes "value"));
115-
("name", Some (name |> Json.escape |> wrapInQuotes));
115+
("name", Some (name |> wrapInQuotes));
116116
( "deprecated",
117117
match deprecated with
118118
| Some d -> Some (wrapInQuotes d)
119119
| None -> None );
120120
( "signature",
121-
Some (signature |> String.trim |> Json.escape |> wrapInQuotes) );
121+
Some (signature |> String.trim |> wrapInQuotes) );
122122
("docstrings", Some (stringifyDocstrings docstring));
123123
]
124124
| Type {id; docstring; signature; name; deprecated; detail} ->
125125
stringifyObject ~startOnNewline:true ~indentation
126126
[
127127
("id", Some (wrapInQuotes id));
128128
("kind", Some (wrapInQuotes "type"));
129-
("name", Some (name |> Json.escape |> wrapInQuotes));
129+
("name", Some (name |> wrapInQuotes));
130130
( "deprecated",
131131
match deprecated with
132132
| Some d -> Some (wrapInQuotes d)
133133
| None -> None );
134-
("signature", Some (signature |> Json.escape |> wrapInQuotes));
134+
("signature", Some (signature |> wrapInQuotes));
135135
("docstrings", Some (stringifyDocstrings docstring));
136136
( "detail",
137137
match detail with

analysis/tests/src/DocExtractionRes.res

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ let make = name => {
2222
/** Stuff goes offline.*/
2323
let asOffline = (t: t) => {...t, online: false}
2424

25+
/** exotic identifier */
26+
let \"SomeConstant\" = 12
27+
2528
module SomeInnerModule = {
2629
/*** Another module level docstring here.*/
2730
type status =

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ extracting docs for src/DocExtractionRes.res
4141
"signature": "let asOffline: t => t",
4242
"docstrings": ["Stuff goes offline."]
4343
},
44+
{
45+
"id": "DocExtractionRes.SomeConstant\\",
46+
"kind": "value",
47+
"name": "SomeConstant\\",
48+
"signature": "let SomeConstant\\: int",
49+
"docstrings": ["exotic identifier"]
50+
},
4451
{
4552
"id": "DocExtractionRes.SomeInnerModule",
4653
"name": "SomeInnerModule",
@@ -77,7 +84,7 @@ extracting docs for src/DocExtractionRes.res
7784
"id": "DocExtractionRes.SomeInnerModule.validInputs",
7885
"kind": "type",
7986
"name": "validInputs",
80-
"signature": "type validInputs = [\\n | #\\\"needs-escaping\\\"\\n | #something\\n | #status(status)\\n | #withPayload(int)\\n]",
87+
"signature": "type validInputs = [\n | #\"needs-escaping\"\n | #something\n | #status(status)\n | #withPayload(int)\n]",
8188
"docstrings": ["These are all the valid inputs."]
8289
},
8390
{
@@ -118,7 +125,7 @@ extracting docs for src/DocExtractionRes.res
118125
"id": "DocExtractionRes.AnotherModule.someVariantWithInlineRecords",
119126
"kind": "type",
120127
"name": "someVariantWithInlineRecords",
121-
"signature": "type someVariantWithInlineRecords =\\n | SomeStuff({offline: bool})",
128+
"signature": "type someVariantWithInlineRecords =\n | SomeStuff({offline: bool})",
122129
"docstrings": ["Trying how it looks with an inline record in a variant."],
123130
"detail":
124131
{

tools/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#### :bug: Bug Fix
1616

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

1920
## 0.3.0
2021

0 commit comments

Comments
 (0)