Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e94e17e

Browse files
committedFeb 2, 2024
feat(lsp): Add Inlay types
1 parent 353b544 commit e94e17e

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed
 

‎compiler/src/language_server/inlayhint.re

+24-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ let send_no_result = (~id: Protocol.message_id) => {
3333
Protocol.response(~id, `Null);
3434
};
3535

36+
let build_hint =
37+
(position: Protocol.position, message: string): ResponseResult.inlay_hint => {
38+
{label: ": " ++ message, position};
39+
};
40+
3641
let find_hints = program => {
3742
let hints = ref([]);
3843
open Typedtree;
@@ -52,12 +57,26 @@ let find_hints = program => {
5257
line: stmt_end.pos_lnum - 1,
5358
character: stmt_end.pos_cnum - stmt_end.pos_bol + 1 + 1,
5459
};
60+
hints := [build_hint(p, name), ...hints^];
61+
| _ => ()
62+
};
63+
};
5564

56-
let r: ResponseResult.inlay_hint = {
57-
label: ": " ++ name,
58-
position: p,
59-
};
60-
hints := [r, ...hints^];
65+
let enter_binding = ({vb_pat}: value_binding) => {
66+
switch (vb_pat.pat_extra) {
67+
| [] =>
68+
switch (vb_pat.pat_desc) {
69+
| TPatVar(_, {loc}) =>
70+
let bind_end = loc.loc_end;
71+
let p: Protocol.position = {
72+
line: bind_end.pos_lnum - 1,
73+
character: bind_end.pos_cnum - bind_end.pos_bol,
74+
};
75+
let typeSignature =
76+
Printtyp.string_of_type_scheme(vb_pat.pat_type);
77+
hints := [build_hint(p, typeSignature), ...hints^];
78+
| _ => ()
79+
}
6180
| _ => ()
6281
};
6382
};

0 commit comments

Comments
 (0)
Please sign in to comment.