Skip to content

Commit 28d095c

Browse files
committed
skip ~ or ? in the location of named arguments
Fixes #244
1 parent af851ed commit 28d095c

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

analysis/src/ProcessCmt.ml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,23 @@ struct
10761076
| Texp_let (_, _, _) ->
10771077
(* TODO this scope tracking won't work for recursive *)
10781078
addScopeExtent expression.exp_loc
1079-
| Texp_function {cases} -> (
1080-
match cases with [{c_rhs}] -> addScopeExtent c_rhs.exp_loc | _ -> ())
1079+
| Texp_function {arg_label; cases} -> (
1080+
match cases with
1081+
| [{c_lhs = {pat_desc = Tpat_var (ident, name)} as c_lhs; c_rhs}] ->
1082+
(match arg_label with
1083+
| Labelled _ | Optional _ ->
1084+
let loc_start = name.loc.loc_start in
1085+
(* skip `~` or `?` in the location of labeled arguments *)
1086+
let loc_start = {loc_start with pos_cnum = loc_start.pos_cnum + 1} in
1087+
let loc = {name.loc with loc_start} in
1088+
let name = {name with loc} in
1089+
let c_lhs = {c_lhs with pat_desc = Tpat_var (ident, name)} in
1090+
(* Force an earlier enter_pattern to control the location. *)
1091+
enter_pattern c_lhs
1092+
| Nolabel -> ());
1093+
1094+
addScopeExtent c_rhs.exp_loc
1095+
| _ -> ())
10811096
| _ -> ()
10821097

10831098
let leave_expression expression =

analysis/tests/src/References.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ let b = a
77

88
let c = x
99

10-
let foo = (~x) => x + 1
11-
// ^ref
10+
let foo = (~xx) => xx + 1
11+
// ^ref

analysis/tests/src/expected/References.res.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ References tests/src/References.res 0:4
66
{"uri": "References.res", "range": {"start": {"line": 0, "character": 4}, "end": {"line": 0, "character": 5}}}
77
]
88

9-
References tests/src/References.res 9:18
9+
References tests/src/References.res 9:19
1010
[
11-
{"uri": "References.res", "range": {"start": {"line": 9, "character": 18}, "end": {"line": 9, "character": 19}}},
12-
{"uri": "References.res", "range": {"start": {"line": 9, "character": 11}, "end": {"line": 9, "character": 13}}}
11+
{"uri": "References.res", "range": {"start": {"line": 9, "character": 19}, "end": {"line": 9, "character": 21}}},
12+
{"uri": "References.res", "range": {"start": {"line": 9, "character": 12}, "end": {"line": 9, "character": 14}}}
1313
]
1414

0 commit comments

Comments
 (0)