Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit 60efec3

Browse files
amiraliescristianoc
authored andcommitted
Add typedef hover support
1 parent 633c7e3 commit 60efec3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/rescript-editor-support/Hover.re

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ let digConstructor = (~env, ~getModule, path) => {
1212
};
1313
};
1414

15+
let codeBlock = (~markdown, code) =>
16+
if (markdown) {
17+
Printf.sprintf("```rescript\n%s\n```", code);
18+
} else {
19+
code;
20+
};
21+
1522
let showModuleTopLevel =
1623
(
1724
~name,
@@ -32,7 +39,7 @@ let showModuleTopLevel =
3239
)
3340
|> String.concat("\n");
3441
let full = "module " ++ name ++ " = {" ++ "\n" ++ contents ++ "\n}";
35-
Some(markdown ? "```rescript\n" ++ full ++ "\n```" : full);
42+
Some(codeBlock(~markdown, full));
3643
};
3744

3845
let showModule =
@@ -55,7 +62,9 @@ let newHover =
5562
(~rootUri, ~file: SharedTypes.file, ~getModule, ~markdown, ~showPath, loc) => {
5663
switch (loc) {
5764
| SharedTypes.Explanation(text) => Some(text)
58-
| TypeDefinition(_name, _tdecl, _stamp) => None
65+
| TypeDefinition(name, decl, _stamp) =>
66+
let typeDef = Shared.declToString(name, decl);
67+
Some(codeBlock(~markdown, typeDef));
5968
| LModule(LocalReference(stamp, _tip)) =>
6069
let%opt md = Hashtbl.find_opt(file.stamps.modules, stamp);
6170
let%opt (file, declared) =
@@ -110,15 +119,13 @@ let newHover =
110119
/* Some(typ.toString()) */
111120
};
112121

113-
let codeBlock = text =>
114-
markdown ? "```rescript\n" ++ text ++ "\n```" : text;
115-
let typeString = codeBlock(typeString);
122+
let typeString = codeBlock(~markdown, typeString);
116123
let typeString =
117124
typeString
118125
++ (
119126
switch (extraTypeInfo) {
120127
| None => ""
121-
| Some(extra) => "\n\n" ++ codeBlock(extra)
128+
| Some(extra) => "\n\n" ++ codeBlock(~markdown, extra)
122129
}
123130
);
124131

@@ -138,6 +145,7 @@ let newHover =
138145
Some(typeString),
139146
Some(
140147
codeBlock(
148+
~markdown,
141149
txt
142150
++ "("
143151
++ (

0 commit comments

Comments
 (0)