Skip to content

Commit 814a710

Browse files
committed
hover: remove spacing between type definition
1 parent 8e161ab commit 814a710

14 files changed

+57
-54
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
1313
## master
1414

15+
#### :nail_care: Polish
16+
- Remove spacing between type definition in clients that do not support markdown links. https://github.com/rescript-lang/rescript-vscode/pull/619
17+
1518
#### :bug: Bug Fix
1619

1720
- Fix issue where `-open Some.Path` in `"bsc-flags"` would sometimes be treated differently from `open Some.Path` locally in a file https://github.com/rescript-lang/rescript-vscode/pull/616

analysis/src/Hover.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ let hoverWithExpandedTypes ~docstring ~file ~package ~supportsMarkdownLinks typ
100100
Markdown.goToDefinitionText ~env ~pos:loc.Warnings.loc_start
101101
else ""
102102
in
103-
"\n" ^ Markdown.spacing
103+
Markdown.divider ^ (if supportsMarkdownLinks then Markdown.spacing else "")
104104
^ Markdown.codeBlock
105105
(decl
106106
|> Shared.declToString ~printNameAsIs:true
107107
(SharedTypes.pathIdentToString path))
108-
^ linkToTypeDefinitionStr ^ "\n" ^ Markdown.divider)
108+
^ linkToTypeDefinitionStr ^ "\n")
109109
in
110110
(typeString :: typeDefinitions |> String.concat "\n", docstring)
111111

analysis/src/Protocol.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ let stringifyCompletionItem c =
9797
| None -> null
9898
| Some doc -> stringifyMarkupContent doc)
9999

100-
let stringifyHover s = Printf.sprintf {|{"contents": "%s"}|} (Json.escape s)
100+
let stringifyHover value = Printf.sprintf {|{"contents": %s}|} (stringifyMarkupContent {kind = "markdown"; value})
101101

102102
let stringifyLocation (h : location) =
103103
Printf.sprintf {|{"uri": "%s", "range": %s}|} (Json.escape h.uri)
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Hover src/Auto.res 2:13
2-
{"contents": "```rescript\n(Belt.List.t<'a>, 'a => 'b) => Belt.List.t<'b>\n```\n\n\n```\n \n```\n```rescript\ntype Belt.List.t<'a> = list<'a>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22belt_List.mli%22%2C34%2C0%5D)\n\n---\n\n\n\n Returns a new list with `f` applied to each element of `someList`.\n\n ```res example\n list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4}\n ```\n"}
2+
{"contents": {"kind": "markdown", "value": "```rescript\n(Belt.List.t<'a>, 'a => 'b) => Belt.List.t<'b>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Belt.List.t<'a> = list<'a>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22belt_List.mli%22%2C34%2C0%5D)\n\n\n\n Returns a new list with `f` applied to each element of `someList`.\n\n ```res example\n list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4}\n ```\n"}}
33

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ JSX <div:[346:9->346:12] name[346:13->346:17]=...[346:18->346:20]> _children:346
14061406
Completable: Cjsx([div], name, [name])
14071407
Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
14081408
Resolved opens 2 Completion.res Completion.res
1409-
{"contents": "```rescript\nstring\n```"}
1409+
{"contents": {"kind": "markdown", "value": "```rescript\nstring\n```"}}
14101410

14111411
Hover src/Completion.res 349:17
14121412
Nothing at that position. Now trying to use completion.
@@ -1417,7 +1417,7 @@ Pexp_ident FAO.forAutoObject:[349:11->349:28]
14171417
Completable: Cpath Value[FAO, forAutoObject]
14181418
Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
14191419
Resolved opens 2 Completion.res Completion.res
1420-
{"contents": "```rescript\n{\"age\": int, \"forAutoLabel\": FAR.forAutoRecord}\n```"}
1420+
{"contents": {"kind": "markdown", "value": "```rescript\n{\"age\": int, \"forAutoLabel\": FAR.forAutoRecord}\n```"}}
14211421

14221422
Hover src/Completion.res 352:17
14231423
Nothing at that position. Now trying to use completion.
@@ -1435,7 +1435,7 @@ Found type for function (
14351435
unit,
14361436
~c: int,
14371437
) => int
1438-
{"contents": "```rescript\noption<int>\n```"}
1438+
{"contents": {"kind": "markdown", "value": "```rescript\noption<int>\n```"}}
14391439

14401440
Complete src/Completion.res 355:23
14411441
posCursor:[355:23] posNoWhite:[355:22] Found expr:[0:-1->355:23]

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ Definition src/Definition.res 10:23
55
{"uri": "Definition.res", "range": {"start": {"line": 6, "character": 7}, "end": {"line": 6, "character": 13}}}
66

77
Hover src/Definition.res 14:14
8-
{"contents": "```rescript\n('a => 'b, list<'a>) => list<'b>\n```\n\n [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an],\n and builds the list [[f a1; ...; f an]]\n with the results returned by [f]. Not tail-recursive. "}
8+
{"contents": {"kind": "markdown", "value": "```rescript\n('a => 'b, list<'a>) => list<'b>\n```\n\n [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an],\n and builds the list [[f a1; ...; f an]]\n with the results returned by [f]. Not tail-recursive. "}}
99

1010
Hover src/Definition.res 18:14
11-
{"contents": "```rescript\n(Belt.List.t<'a>, 'a => 'b) => Belt.List.t<'b>\n```\n\n\n```\n \n```\n```rescript\ntype Belt.List.t<'a> = list<'a>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22belt_List.mli%22%2C34%2C0%5D)\n\n---\n\n\n\n Returns a new list with `f` applied to each element of `someList`.\n\n ```res example\n list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4}\n ```\n"}
11+
{"contents": {"kind": "markdown", "value": "```rescript\n(Belt.List.t<'a>, 'a => 'b) => Belt.List.t<'b>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Belt.List.t<'a> = list<'a>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22belt_List.mli%22%2C34%2C0%5D)\n\n\n\n Returns a new list with `f` applied to each element of `someList`.\n\n ```res example\n list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4}\n ```\n"}}
1212

1313
Hover src/Definition.res 23:3
14-
{"contents": "```rescript\n(. int, int) => int\n```"}
14+
{"contents": {"kind": "markdown", "value": "```rescript\n(. int, int) => int\n```"}}
1515

1616
Definition src/Definition.res 26:3
1717
{"uri": "Definition.res", "range": {"start": {"line": 21, "character": 4}, "end": {"line": 21, "character": 13}}}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Hover src/Div.res 0:10
22
getLocItem #3: heuristic for <div>
3-
{"contents": "```rescript\n(\n string,\n ~props: ReactDOM_V3.domProps=?,\n array<React.element>,\n) => React.element\n```\n\n\n```\n \n```\n```rescript\ntype ReactDOM_V3.domProps = Props.domProps\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22ReactDOM_V3.res%22%2C57%2C2%5D)\n\n---\n\n\n\n```\n \n```\n```rescript\ntype React.element = Jsx.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n\n---\n"}
3+
{"contents": {"kind": "markdown", "value": "```rescript\n(\n string,\n ~props: ReactDOM_V3.domProps=?,\n array<React.element>,\n) => React.element\n```\n\n---\n\n```\n \n```\n```rescript\ntype ReactDOM_V3.domProps = Props.domProps\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22ReactDOM_V3.res%22%2C57%2C2%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.element = Jsx.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n"}}
44

55
Complete src/Div.res 3:17
66
posCursor:[3:17] posNoWhite:[3:16] Found expr:[3:4->3:17]
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Hover src/DocComments.res 9:9
2-
{"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"}
2+
{"contents": {"kind": "markdown", "value": "```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"}}
33

44
Hover src/DocComments.res 22:6
5-
{"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"}
5+
{"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 /*\n * stuff\n */\n ```\n"}}
66

77
Hover src/DocComments.res 33:9
8-
{"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"}
8+
{"contents": {"kind": "markdown", "value": "```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"}}
99

1010
Hover src/DocComments.res 44:6
11-
{"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"}
11+
{"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"}}
1212

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Hover src/Fragment.res 6:19
22
getLocItem #4: heuristic for </Comp> within fragments: take make as makeProps does not work
33
the type is not great but jump to definition works
4-
{"contents": "```rescript\nReact.component<{\"children\": React.element}>\n```\n\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C12%2C0%5D)\n\n---\n"}
4+
{"contents": {"kind": "markdown", "value": "```rescript\nReact.component<{\"children\": React.element}>\n```\n\n---\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C12%2C0%5D)\n"}}
55

66
Hover src/Fragment.res 9:56
77
Nothing at that position. Now trying to use completion.

0 commit comments

Comments
 (0)