Skip to content

Commit a0fbf01

Browse files
committed
Remove extra newline from passing a documentation with empty string
1 parent 09ca1cf commit a0fbf01

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

analysis/src/NewCompletions.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ let getItems ~full ~package ~rawOpens ~allModules ~pos ~parts =
410410
(opens |> List.map (fun env -> attributeCompletions ~env ~suffix))))
411411

412412
let mkItem ~name ~kind ~detail ~deprecated ~docstring =
413-
let valueMessage =
413+
let docContent =
414414
(match deprecated with None -> "" | Some s -> "Deprecated: " ^ s ^ "\n\n")
415415
^
416416
match docstring with [] -> "" | _ :: _ -> docstring |> String.concat "\n"
@@ -424,7 +424,9 @@ let mkItem ~name ~kind ~detail ~deprecated ~docstring =
424424
kind;
425425
tags;
426426
detail;
427-
documentation = {kind = "markdown"; value = valueMessage};
427+
documentation =
428+
(if docContent = "" then None
429+
else Some {kind = "markdown"; value = docContent});
428430
}
429431

430432
let processCompletable ~findItems ~package ~rawOpens

analysis/src/Protocol.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
let array l = "[" ^ (String.concat ", " l) ^ "]"
2-
31
type position = {
42
line: int;
53
character: int;
@@ -20,7 +18,7 @@ type completionItem = {
2018
kind: int;
2119
tags: int list;
2220
detail: string;
23-
documentation: markupContent;
21+
documentation: markupContent option;
2422
}
2523

2624
type hover = {
@@ -32,6 +30,10 @@ type location = {
3230
range: range;
3331
}
3432

33+
let null = "null"
34+
35+
let array l = "[" ^ (String.concat ", " l) ^ "]"
36+
3537
let stringifyPosition p =
3638
Printf.sprintf {|{"line": %i, "character": %i}|} p.line p.character
3739

@@ -56,7 +58,9 @@ let stringifyCompletionItem c =
5658
c.kind
5759
(c.tags |> List.map string_of_int |> array)
5860
(Json.escape c.detail)
59-
(stringifyMarkupContent c.documentation)
61+
(match c.documentation with
62+
| None -> null
63+
| Some doc -> stringifyMarkupContent doc)
6064

6165
let stringifyHover h =
6266
Printf.sprintf {|{"contents": "%s"}|}
@@ -66,5 +70,3 @@ let stringifyLocation h =
6670
Printf.sprintf {|{"uri": "%s", "range": %s}|}
6771
(Json.escape h.uri)
6872
(stringifyRange h.range)
69-
70-
let null = "null"

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Complete tests/src/Complete.res 0:2
2222
"kind": 12,
2323
"tags": [],
2424
"detail": "(t<'a>, t<'b>, (. 'a, 'b) => 'c) => t<'c>",
25-
"documentation": {"kind": "markdown", "value": ""}
25+
"documentation": null
2626
}, {
2727
"label": "map",
2828
"kind": 12,
@@ -34,19 +34,19 @@ Complete tests/src/Complete.res 0:2
3434
"kind": 12,
3535
"tags": [],
3636
"detail": "(t<'a>, (. int, 'a) => 'b) => t<'b>",
37-
"documentation": {"kind": "markdown", "value": ""}
37+
"documentation": null
3838
}, {
3939
"label": "mapU",
4040
"kind": 12,
4141
"tags": [],
4242
"detail": "(t<'a>, (. 'a) => 'b) => t<'b>",
43-
"documentation": {"kind": "markdown", "value": ""}
43+
"documentation": null
4444
}, {
4545
"label": "makeByU",
4646
"kind": 12,
4747
"tags": [],
4848
"detail": "(int, (. int) => 'a) => t<'a>",
49-
"documentation": {"kind": "markdown", "value": ""}
49+
"documentation": null
5050
}, {
5151
"label": "mapReverse2",
5252
"kind": 12,
@@ -64,7 +64,7 @@ Complete tests/src/Complete.res 0:2
6464
"kind": 12,
6565
"tags": [],
6666
"detail": "(t<'a>, (. 'a) => 'b) => t<'b>",
67-
"documentation": {"kind": "markdown", "value": ""}
67+
"documentation": null
6868
}]
6969

7070
Complete tests/src/Complete.res 1:2
@@ -73,7 +73,7 @@ Complete tests/src/Complete.res 1:2
7373
"kind": 9,
7474
"tags": [],
7575
"detail": "module",
76-
"documentation": {"kind": "markdown", "value": ""}
76+
"documentation": null
7777
}, {
7878
"label": "fold_left",
7979
"kind": 12,
@@ -211,7 +211,7 @@ Complete tests/src/Complete.res 1:2
211211
"kind": 12,
212212
"tags": [],
213213
"detail": "(array<'a>, int) => 'a",
214-
"documentation": {"kind": "markdown", "value": ""}
214+
"documentation": null
215215
}, {
216216
"label": "make_matrix",
217217
"kind": 12,
@@ -241,7 +241,7 @@ Complete tests/src/Complete.res 1:2
241241
"kind": 12,
242242
"tags": [],
243243
"detail": "(array<'a>, int, 'a) => unit",
244-
"documentation": {"kind": "markdown", "value": ""}
244+
"documentation": null
245245
}, {
246246
"label": "create_matrix",
247247
"kind": 12,
@@ -352,13 +352,13 @@ Complete tests/src/Complete.res 19:2
352352
"kind": 4,
353353
"tags": [],
354354
"detail": "int",
355-
"documentation": {"kind": "markdown", "value": ""}
355+
"documentation": null
356356
}, {
357357
"label": "name",
358358
"kind": 4,
359359
"tags": [],
360360
"detail": "string",
361-
"documentation": {"kind": "markdown", "value": ""}
361+
"documentation": null
362362
}]
363363

364364
Complete tests/src/Complete.res 21:2
@@ -367,13 +367,13 @@ Complete tests/src/Complete.res 21:2
367367
"kind": 12,
368368
"tags": [],
369369
"detail": "(t<'a>, ('a, int) => 'b) => t<'b>",
370-
"documentation": {"kind": "markdown", "value": ""}
370+
"documentation": null
371371
}, {
372372
"label": "Js.Array2.map",
373373
"kind": 12,
374374
"tags": [],
375375
"detail": "(t<'a>, 'a => 'b) => t<'b>",
376-
"documentation": {"kind": "markdown", "value": ""}
376+
"documentation": null
377377
}]
378378

379379
Complete tests/src/Complete.res 23:2
@@ -406,13 +406,13 @@ Complete tests/src/Complete.res 36:2
406406
"kind": 12,
407407
"tags": [],
408408
"detail": "(t, int) => t",
409-
"documentation": {"kind": "markdown", "value": ""}
409+
"documentation": null
410410
}, {
411411
"label": "ForAuto.abd",
412412
"kind": 12,
413413
"tags": [],
414414
"detail": "(t, int) => t",
415-
"documentation": {"kind": "markdown", "value": ""}
415+
"documentation": null
416416
}]
417417

418418
Complete tests/src/Complete.res 38:2
@@ -436,7 +436,7 @@ Complete tests/src/Complete.res 50:2
436436
"kind": 12,
437437
"tags": [],
438438
"detail": "int",
439-
"documentation": {"kind": "markdown", "value": ""}
439+
"documentation": null
440440
}]
441441

442442
Complete tests/src/Complete.res 52:2
@@ -445,12 +445,12 @@ Complete tests/src/Complete.res 52:2
445445
"kind": 4,
446446
"tags": [],
447447
"detail": "string",
448-
"documentation": {"kind": "markdown", "value": ""}
448+
"documentation": null
449449
}, {
450450
"label": "zoo",
451451
"kind": 4,
452452
"tags": [],
453453
"detail": "option<int>",
454-
"documentation": {"kind": "markdown", "value": ""}
454+
"documentation": null
455455
}]
456456

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ Complete tests/src/Jsx.res 10:2
1010
"kind": 4,
1111
"tags": [],
1212
"detail": "string",
13-
"documentation": {"kind": "markdown", "value": ""}
13+
"documentation": null
1414
}, {
1515
"label": "first",
1616
"kind": 4,
1717
"tags": [],
1818
"detail": "string",
19-
"documentation": {"kind": "markdown", "value": ""}
19+
"documentation": null
2020
}, {
2121
"label": "fun",
2222
"kind": 4,
2323
"tags": [],
2424
"detail": "option<string>",
25-
"documentation": {"kind": "markdown", "value": ""}
25+
"documentation": null
2626
}]
2727

0 commit comments

Comments
 (0)