Skip to content

Commit e50147f

Browse files
committed
WIP: Fix type-annotate action for functions
1 parent 18f5b9a commit e50147f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ocaml-lsp-server/src/code_actions/action_type_annotate.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@ open Fiber.O
44
let action_kind = "type-annotate"
55

66
let check_typeable_context pipeline pos_start =
7+
let open Typedtree in
78
let pos_start = Mpipeline.get_lexing_pos pipeline pos_start in
89
let typer = Mpipeline.typer_result pipeline in
910
let browse = Mbrowse.of_typedtree (Mtyper.get_typedtree typer) in
1011
let is_exp_constrained = function
11-
| Typedtree.Texp_constraint _, _, _ -> true
12-
| Typedtree.Texp_coerce (Some _, _), _, _ -> true
12+
| Texp_constraint _, _, _ -> true
13+
| Texp_coerce (Some _, _), _, _ -> true
1314
| _ -> false
1415
in
1516
let is_pat_constrained = function
16-
| Typedtree.Tpat_constraint _, _, _ -> true
17+
| Tpat_constraint _, _, _ -> true
1718
| _ -> false
1819
in
1920
let is_valid p extras =
2021
if List.exists ~f:p extras then `Invalid else `Valid
2122
in
2223
match Mbrowse.enclosing pos_start [ browse ] with
24+
| (_, Pattern { pat_desc = Tpat_var _; _})
25+
:: (_, Value_binding { vb_expr = { exp_desc = Texp_function _; _} ; _ })
26+
:: _ -> `Invalid (* TODO: traverse function arguments *)
2327
| (_, Expression e) :: _ -> is_valid is_exp_constrained e.exp_extra
24-
| (_, Pattern { pat_desc = Typedtree.Tpat_any; _ })
25-
:: (_, Pattern { pat_desc = Typedtree.Tpat_alias _; pat_extra; _ })
28+
| (_, Pattern { pat_desc = Tpat_any; _ })
29+
:: (_, Pattern { pat_desc = Tpat_alias _; pat_extra; _ })
2630
:: _ -> is_valid is_pat_constrained pat_extra
2731
| (_, Pattern p) :: _ -> is_valid is_pat_constrained p.pat_extra
2832
| _ :: _ | [] -> `Invalid

0 commit comments

Comments
 (0)