From c8c64f5b4edc025ddc543ed4cced40a44039f562 Mon Sep 17 00:00:00 2001 From: Spotandjake Date: Sun, 28 Jul 2024 21:57:51 -0400 Subject: [PATCH] Do not show hints for top level statements --- compiler/src/language_server/inlayhint.re | 33 ++++++++++++----------- compiler/src/typed/typedtreeIter.re | 22 +++++++-------- compiler/src/typed/typedtreeIter.rei | 4 +-- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/compiler/src/language_server/inlayhint.re b/compiler/src/language_server/inlayhint.re index 992b87839d..a424df788d 100644 --- a/compiler/src/language_server/inlayhint.re +++ b/compiler/src/language_server/inlayhint.re @@ -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^; diff --git a/compiler/src/typed/typedtreeIter.re b/compiler/src/typed/typedtreeIter.re index cf941b9b50..462916c9d8 100644 --- a/compiler/src/typed/typedtreeIter.re +++ b/compiler/src/typed/typedtreeIter.re @@ -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; @@ -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); } @@ -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); } @@ -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); @@ -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 = () => (); diff --git a/compiler/src/typed/typedtreeIter.rei b/compiler/src/typed/typedtreeIter.rei index 4984671624..b1a3abf551 100644 --- a/compiler/src/typed/typedtreeIter.rei +++ b/compiler/src/typed/typedtreeIter.rei @@ -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;