Skip to content

Commit

Permalink
Do not show hints for top level statements
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake committed Jul 29, 2024
1 parent fb31ce3 commit c8c64f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
33 changes: 17 additions & 16 deletions compiler/src/language_server/inlayhint.re
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,25 @@ let find_hints = program => {
};
};

let enter_binding = ({vb_pat, vb_expr}: value_binding) => {
switch (vb_pat.pat_extra) {
| [] =>
switch (vb_pat.pat_desc) {
| TPatVar(_, {loc}) =>
let bind_end = loc.loc_end;
let p: Protocol.position = {
line: bind_end.pos_lnum - 1,
character: bind_end.pos_cnum - bind_end.pos_bol,
};
let typ = vb_pat.pat_type;
let typeSignature = string_of_typ(typ);
hints := [build_hint(p, typeSignature), ...hints^];
let enter_binding = ({vb_pat, vb_expr}: value_binding, toplevel: bool) =>
if (!toplevel) {
switch (vb_pat.pat_extra) {
| [] =>
switch (vb_pat.pat_desc) {
| TPatVar(_, {loc}) =>
let bind_end = loc.loc_end;
let p: Protocol.position = {
line: bind_end.pos_lnum - 1,
character: bind_end.pos_cnum - bind_end.pos_bol,
};
let typ = vb_pat.pat_type;
let typeSignature = string_of_typ(typ);
hints := [build_hint(p, typeSignature), ...hints^];
| _ => ()
}
| _ => ()
}
| _ => ()
};
};
};
});
Iterator.iter_typed_program(program);
hints^;
Expand Down
22 changes: 11 additions & 11 deletions compiler/src/typed/typedtreeIter.re
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ module type IteratorArgument = {
let leave_core_type: core_type => unit;
let leave_toplevel_stmt: toplevel_stmt => unit;

let enter_bindings: (rec_flag, mut_flag) => unit;
let enter_binding: value_binding => unit;
let enter_bindings: (rec_flag, mut_flag, bool) => unit;
let enter_binding: (value_binding, bool) => unit;
let leave_binding: value_binding => unit;
let leave_bindings: (rec_flag, mut_flag) => unit;

Expand Down Expand Up @@ -74,16 +74,16 @@ module MakeIterator =
Iter.leave_core_type(ct);
}

and iter_binding = ({vb_pat, vb_expr} as vb) => {
Iter.enter_binding(vb);
and iter_binding = (~toplevel=false, {vb_pat, vb_expr} as vb) => {
Iter.enter_binding(vb, toplevel);
iter_pattern(vb_pat);
iter_expression(vb_expr);
Iter.leave_binding(vb);
}

and iter_bindings = (rec_flag, mut_flag, binds) => {
Iter.enter_bindings(rec_flag, mut_flag);
List.iter(iter_binding, binds);
and iter_bindings = (~toplevel=false, rec_flag, mut_flag, binds) => {
Iter.enter_bindings(rec_flag, mut_flag, toplevel);
List.iter(iter_binding(~toplevel), binds);
Iter.leave_bindings(rec_flag, mut_flag);
}

Expand Down Expand Up @@ -132,7 +132,7 @@ module MakeIterator =
| TTopModule({tmod_statements}) => iter_toplevel_stmts(tmod_statements)
| TTopExpr(e) => iter_expression(e)
| TTopLet(recflag, mutflag, binds) =>
iter_bindings(recflag, mutflag, binds)
iter_bindings(recflag, mutflag, binds, ~toplevel=true)
};
Iter.leave_toplevel_stmt(stmt);
}
Expand Down Expand Up @@ -206,7 +206,7 @@ module MakeIterator =
| TExpIdent(_)
| TExpConstant(_) => ()
| TExpLet(recflag, mutflag, binds) =>
iter_bindings(recflag, mutflag, binds)
iter_bindings(recflag, mutflag, binds, ~toplevel=false)
| TExpLambda(branches, _) => iter_match_branches(branches)
| TExpApp(exp, _, args) =>
iter_expression(exp);
Expand Down Expand Up @@ -274,8 +274,8 @@ module DefaultIteratorArgument: IteratorArgument = {
let enter_expression = _ => ();
let enter_core_type = _ => ();
let enter_toplevel_stmt = _ => ();
let enter_bindings = (_, _) => ();
let enter_binding = _ => ();
let enter_bindings = (_, _, _) => ();
let enter_binding = (_, _) => ();
let enter_data_declaration = _ => ();
let enter_data_declarations = () => ();

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/typed/typedtreeIter.rei
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ module type IteratorArgument = {
let leave_core_type: core_type => unit;
let leave_toplevel_stmt: toplevel_stmt => unit;

let enter_bindings: (rec_flag, mut_flag) => unit;
let enter_binding: value_binding => unit;
let enter_bindings: (rec_flag, mut_flag, bool) => unit;
let enter_binding: (value_binding, bool) => unit;
let leave_binding: value_binding => unit;
let leave_bindings: (rec_flag, mut_flag) => unit;

Expand Down

0 comments on commit c8c64f5

Please sign in to comment.