@@ -32,15 +32,21 @@ let locItemToTypeHint ~full:{file; package} locItem =
32
32
| `Field -> fromType t))
33
33
| _ -> None
34
34
35
- let inlay ~path ~maxLength ~debug =
36
- let maxlen = try Some (int_of_string maxLength) with Failure _ -> None in
35
+ let inlay ~path ~pos ~ maxLength ~debug =
36
+ let maxlen = try Some (int_of_string maxLength) with Failure _ -> None in
37
37
let hints = ref [] in
38
+ let start_line, end_line = pos in
39
+ let push loc kind =
40
+ let range = Utils. cmtLocToRange loc in
41
+ if start_line < = range.end_.line && end_line > = range.start.line then
42
+ hints := (range, kind) :: ! hints
43
+ in
38
44
let rec processFunction (exp : Parsetree.expression ) =
39
45
match exp.pexp_desc with
40
46
| Pexp_fun (_ , _ , pat_exp , e ) -> (
41
47
match pat_exp with
42
48
| {ppat_desc = Ppat_var _ } ->
43
- hints := ( pat_exp.ppat_loc, Type ) :: ! hints ;
49
+ push pat_exp.ppat_loc Type ;
44
50
processFunction e
45
51
| _ -> processFunction e)
46
52
| _ -> ()
@@ -59,18 +65,17 @@ let inlay ~path ~maxLength ~debug =
59
65
| Pexp_send _ | Pexp_field _ | Pexp_open _ );
60
66
};
61
67
} ->
62
- hints := ( vb.pvb_pat.ppat_loc, Type ) :: ! hints
68
+ push vb.pvb_pat.ppat_loc Type
63
69
| {pvb_pat = {ppat_desc = Ppat_tuple tuples } } ->
64
70
List. iter
65
- (fun (tuple : Parsetree.pattern ) ->
66
- hints := (tuple.ppat_loc, Type ) :: ! hints)
71
+ (fun (tuple : Parsetree.pattern ) -> push tuple.ppat_loc Type )
67
72
tuples
68
73
| {
69
74
pvb_pat = {ppat_desc = Ppat_var _};
70
75
pvb_expr = {pexp_desc = Pexp_fun (_, _, pat, e)};
71
76
} ->
72
77
(match pat with
73
- | {ppat_desc = Ppat_var _ } -> hints := ( pat.ppat_loc, Type ) :: ! hints
78
+ | {ppat_desc = Ppat_var _ } -> push pat.ppat_loc Type
74
79
| _ -> () );
75
80
processFunction e
76
81
| _ -> () );
@@ -82,14 +87,9 @@ let inlay ~path ~maxLength ~debug =
82
87
Res_driver. parsingEngine.parseImplementation ~for Printer:false
83
88
in
84
89
let {Res_driver. parsetree = structure} = parser ~filename: path in
85
- iterator.structure iterator structure |> ignore
86
- else
87
- let parser = Res_driver. parsingEngine.parseInterface ~for Printer:false in
88
- let {Res_driver. parsetree = signature} = parser ~filename: path in
89
- iterator.signature iterator signature |> ignore);
90
+ iterator.structure iterator structure |> ignore);
90
91
! hints
91
- |> List. filter_map (fun (locOfName , hintKind ) ->
92
- let range = Utils. cmtLocToRange locOfName in
92
+ |> List. filter_map (fun ((range : Protocol.range ), hintKind ) ->
93
93
match Cmt. fullFromPath ~path with
94
94
| None -> None
95
95
| Some full -> (
@@ -116,6 +116,7 @@ let inlay ~path ~maxLength ~debug =
116
116
}
117
117
in
118
118
match maxlen with
119
- | Some value -> if (String. length label) > value then None else Some (result)
120
- | None -> Some (result))
119
+ | Some value ->
120
+ if String. length label > value then None else Some result
121
+ | None -> Some result)
121
122
| None -> None )))
0 commit comments