Skip to content

Commit 6767708

Browse files
committed
Add more expressions to annotation scanner
This gives more accurate type information in the LSP server.
1 parent c3793a7 commit 6767708

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/lib/ast_util.ml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,23 +2136,36 @@ struct
21362136
else (
21372137
let result =
21382138
match aux with
2139-
| E_block exps | E_tuple exps -> option_mapm (find_annot_exp sl) exps
2139+
| E_block exps | E_tuple exps | E_vector exps | E_list exps -> option_mapm (find_annot_exp sl) exps
21402140
| E_app (_, exps) -> option_mapm (find_annot_exp sl) exps
21412141
| E_let (pat, exp, body) -> option_chain (find_annot_pat sl pat) (option_mapm (find_annot_exp sl) [exp; body])
2142+
| E_assert (exp1, exp2) | E_cons (exp1, exp2) | E_vector_append (exp1, exp2) ->
2143+
option_mapm (find_annot_exp sl) [exp1; exp2]
21422144
| E_assign (lexp, exp) -> option_chain (find_annot_lexp sl lexp) (find_annot_exp sl exp)
21432145
| E_var (lexp, exp1, exp2) ->
21442146
option_chain (find_annot_lexp sl lexp) (option_mapm (find_annot_exp sl) [exp1; exp2])
21452147
| E_if (cond_exp, then_exp, else_exp) -> option_mapm (find_annot_exp sl) [cond_exp; then_exp; else_exp]
21462148
| E_match (exp, cases) | E_try (exp, cases) ->
21472149
option_chain (find_annot_exp sl exp) (option_mapm (find_annot_pexp sl) cases)
2148-
| E_return exp | E_typ (_, exp) -> find_annot_exp sl exp
2150+
| E_return exp | E_typ (_, exp) | E_exit exp | E_throw exp | E_field (exp, _) -> find_annot_exp sl exp
21492151
| E_for (_, exp_from, exp_to, exp_by, _, body) ->
21502152
option_mapm (find_annot_exp sl) [exp_from; exp_to; exp_by; body]
2153+
| E_loop (_, measure, exp_cond, exp_body) ->
2154+
option_chain (find_annot_measure sl measure) (option_mapm (find_annot_exp sl) [exp_cond; exp_body])
2155+
| E_struct (_, fexps) -> option_mapm (find_annot_fexp sl) fexps
2156+
| E_struct_update (exp, fexps) -> option_chain (find_annot_exp sl exp) (option_mapm (find_annot_fexp sl) fexps)
21512157
| _ -> None
21522158
in
21532159
match result with None -> Some (l, annot, Loc.categorize_exp aux) | _ -> result
21542160
)
21552161

2162+
and find_annot_measure sl (Measure_aux (aux, l)) =
2163+
if not (subloc sl l) then None
2164+
else (match aux with Measure_none -> None | Measure_some exp -> find_annot_exp sl exp)
2165+
2166+
and find_annot_fexp sl (FE_aux (FE_fexp (_, exp), (l, annot))) =
2167+
if not (subloc sl l) then None else find_annot_exp sl exp
2168+
21562169
and find_annot_lexp sl (LE_aux (aux, (l, annot))) =
21572170
if not (subloc sl l) then None
21582171
else (

0 commit comments

Comments
 (0)