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

Commit 7b886ef

Browse files
committed
Refactor: clean up hover parts.
1 parent 5c8124a commit 7b886ef

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

src/rescript-editor-support/Hover.re

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -133,45 +133,45 @@ let newHover = (~file: SharedTypes.file, ~getModule, loc) => {
133133
| None => (typeString, docstring)
134134
| Some((extra, extraDocstring)) => (
135135
typeString ++ "\n\n" ++ codeBlock(extra),
136-
extraDocstring,
136+
switch (extraDocstring) {
137+
| None => []
138+
| Some(d) => [d]
139+
},
137140
)
138141
};
139-
(Some(typeString), docstring);
142+
(typeString, docstring);
140143
};
141144

142145
let parts =
143146
switch (References.definedForLoc(~file, ~getModule, locKind)) {
144147
| None =>
145-
let (typeString, docstring) = t |> fromType(~docstring=None);
146-
[typeString, docstring];
148+
let (typeString, docstring) = t |> fromType(~docstring=[]);
149+
[typeString, ...docstring];
147150
| Some((docstring, res)) =>
148-
let parts =
149-
switch (res) {
150-
| `Declared =>
151-
let (typeString, docstring) = t |> fromType(~docstring);
152-
[typeString, docstring];
153-
| `Constructor({cname: {txt}, args}) =>
154-
let (typeString, docstring) = t |> fromType(~docstring);
151+
switch (res) {
152+
| `Declared =>
153+
let (typeString, docstring) = t |> fromType(~docstring);
154+
[typeString, ...docstring];
155+
| `Constructor({cname: {txt}, args}) =>
156+
let (typeString, docstring) = t |> fromType(~docstring);
155157

156-
let argsString =
157-
switch (args) {
158-
| [] => ""
159-
| _ =>
160-
args
161-
|> List.map(((t, _)) => Shared.typeToString(t))
162-
|> String.concat(", ")
163-
|> Printf.sprintf("(%s)")
164-
};
158+
let argsString =
159+
switch (args) {
160+
| [] => ""
161+
| _ =>
162+
args
163+
|> List.map(((t, _)) => Shared.typeToString(t))
164+
|> String.concat(", ")
165+
|> Printf.sprintf("(%s)")
166+
};
165167

166-
[typeString, Some(codeBlock(txt ++ argsString)), docstring];
167-
| `Field({typ}) =>
168-
let (typeString, docstring) = typ |> fromType(~docstring);
169-
[typeString, docstring];
170-
};
171-
172-
parts;
168+
[typeString, codeBlock(txt ++ argsString), ...docstring];
169+
| `Field({typ}) =>
170+
let (typeString, docstring) = typ |> fromType(~docstring);
171+
[typeString, ...docstring];
172+
}
173173
};
174174

175-
Some(String.concat("\n\n", parts |> Utils.filterMap(x => x)));
175+
Some(String.concat("\n\n", parts));
176176
};
177177
};

src/rescript-editor-support/References.re

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ let definedForLoc = (~file, ~getModule, locKind) => {
9999
switch (tip) {
100100
| Constructor(name) =>
101101
let%opt constructor = Query.getConstructor(file, stamp, name);
102-
Some((None, `Constructor(constructor)));
102+
Some(([], `Constructor(constructor)));
103103
| Field(name) =>
104104
let%opt field = Query.getField(file, stamp, name);
105-
Some((None, `Field(field)));
105+
Some(([], `Field(field)));
106106
| _ =>
107107
maybeLog(
108108
"Trying for declared "
@@ -114,7 +114,12 @@ let definedForLoc = (~file, ~getModule, locKind) => {
114114
);
115115
let%opt declared =
116116
Query.declaredForTip(~stamps=file.stamps, stamp, tip);
117-
Some((declared.docstring, `Declared));
117+
let docstring =
118+
switch (declared.docstring) {
119+
| None => []
120+
| Some(d) => [d]
121+
};
122+
Some((docstring, `Declared));
118123
};
119124
};
120125

0 commit comments

Comments
 (0)