Skip to content

Commit e71b785

Browse files
committed
ensure piped calls are not messed up by being overwritten by the regular apply directly after the piped apply
1 parent 01501e4 commit e71b785

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

analysis/src/SignatureHelp.ml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,19 @@ let signatureHelp ~path ~pos ~currentFile ~debug =
179179
let supportsMarkdownLinks = true in
180180
let foundFunctionApplicationExpr = ref None in
181181
let setFound r =
182-
if !foundFunctionApplicationExpr = None then
182+
(* Because we want to handle both piped and regular function calls, and in
183+
the case of piped calls the iterator will process both the pipe and the
184+
regular call (even though it's piped), we need to ensure that we don't
185+
re-save the same expression (but unpiped, even though it's actually piped). *)
186+
match (!foundFunctionApplicationExpr, r) with
187+
| Some (_, alreadyFoundExp, _), (_, newExp, _)
188+
when alreadyFoundExp.Parsetree.pexp_loc <> newExp.Parsetree.pexp_loc
189+
->
183190
foundFunctionApplicationExpr := Some r
191+
| None, _ -> foundFunctionApplicationExpr := Some r
192+
| Some _, _ -> ()
184193
in
185-
let searchForArgWithCursor ~isPipeExpr ~args ~exp =
194+
let searchForArgWithCursor ~isPipeExpr ~args =
186195
let extractedArgs = extractExpApplyArgs ~args in
187196
let argAtCursor =
188197
let firstArgIndex = if isPipeExpr then 1 else 0 in
@@ -246,7 +255,7 @@ let signatureHelp ~path ~pos ~currentFile ~debug =
246255
else 0))
247256
| v -> v
248257
in
249-
setFound (argAtCursor, exp, extractedArgs)
258+
(argAtCursor, extractedArgs)
250259
in
251260
let expr (iterator : Ast_iterator.iterator) (expr : Parsetree.expression)
252261
=
@@ -269,7 +278,10 @@ let signatureHelp ~path ~pos ~currentFile ~debug =
269278
when pexp_loc
270279
|> CursorPosition.classifyLoc ~pos:posBeforeCursor
271280
== HasCursor ->
272-
searchForArgWithCursor ~isPipeExpr:true ~args ~exp
281+
let argAtCursor, extractedArgs =
282+
searchForArgWithCursor ~isPipeExpr:true ~args
283+
in
284+
setFound (argAtCursor, exp, extractedArgs)
273285
(* Look for applying idents, like someIdent(...) *)
274286
| {
275287
pexp_desc = Pexp_apply (({pexp_desc = Pexp_ident _} as exp), args);
@@ -278,7 +290,10 @@ let signatureHelp ~path ~pos ~currentFile ~debug =
278290
when pexp_loc
279291
|> CursorPosition.classifyLoc ~pos:posBeforeCursor
280292
== HasCursor ->
281-
searchForArgWithCursor ~isPipeExpr:false ~args ~exp
293+
let argAtCursor, extractedArgs =
294+
searchForArgWithCursor ~isPipeExpr:false ~args
295+
in
296+
setFound (argAtCursor, exp, extractedArgs)
282297
| _ -> ());
283298
Ast_iterator.default_iterator.expr iterator expr
284299
in

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,34 +267,42 @@ extracted params:
267267
}
268268

269269
Signature help src/SignatureHelp.res 71:29
270-
posCursor:[71:13] posNoWhite:[71:12] Found expr:[71:11->71:33]
270+
posCursor:[71:28] posNoWhite:[71:27] Found expr:[71:11->71:33]
271271
Pexp_apply ...[71:11->71:13] (...[71:16->71:30])
272-
posCursor:[71:13] posNoWhite:[71:12] Found expr:[71:11->71:13]
273-
Pexp_ident fn:[71:11->71:13]
272+
posCursor:[71:28] posNoWhite:[71:27] Found expr:[71:16->71:30]
273+
Pexp_apply ...[71:16->71:28] (...[71:29->71:30])
274+
posCursor:[71:28] posNoWhite:[71:27] Found expr:[71:16->71:28]
275+
Pexp_ident iAmSoSpecial:[71:16->71:28]
274276
argAtCursor: unlabelled<0>
275277
extracted params:
276-
[(int, string, int]
278+
[string]
277279
{
278280
"signatures": [{
279-
"label": "(int, string, int) => unit",
280-
"parameters": [{"label": [0, 4], "documentation": {"kind": "markdown", "value": "```rescript\nint\n```"}}, {"label": [6, 12], "documentation": {"kind": "markdown", "value": "```rescript\nint\n```"}}, {"label": [14, 17], "documentation": {"kind": "markdown", "value": "```rescript\nint\n```"}}]
281+
"label": "string => unit",
282+
"parameters": [{"label": [0, 6], "documentation": {"kind": "markdown", "value": "```rescript\nstring\n```"}}]
281283
}],
282284
"activeSignature": 0,
283285
"activeParameter": 0
284286
}
285287

286288
Signature help src/SignatureHelp.res 74:40
287-
posCursor:[74:13] posNoWhite:[74:12] Found expr:[74:11->74:47]
289+
posCursor:[74:39] posNoWhite:[74:38] Found expr:[74:11->74:47]
288290
Pexp_apply ...[74:11->74:13] (...[74:16->74:44])
289-
posCursor:[74:13] posNoWhite:[74:12] Found expr:[74:11->74:13]
290-
Pexp_ident fn:[74:11->74:13]
291+
posCursor:[74:39] posNoWhite:[74:38] Found expr:[74:16->74:44]
292+
Pexp_apply ...[74:16->74:28] (...[74:31->74:41])
293+
posCursor:[74:39] posNoWhite:[74:38] Found expr:[74:31->74:41]
294+
Pexp_apply ...[74:31->74:39] (...[74:40->74:41])
295+
posCursor:[74:39] posNoWhite:[74:38] Found expr:[74:31->74:39]
296+
Pexp_ident someFunc:[74:31->74:39]
291297
argAtCursor: unlabelled<0>
292298
extracted params:
293-
[(int, string, int]
299+
[(
300+
int, ~two: string=?, ~three: unit => unit, ~four: someVariant, unit]
294301
{
295302
"signatures": [{
296-
"label": "(int, string, int) => unit",
297-
"parameters": [{"label": [0, 4], "documentation": {"kind": "markdown", "value": "```rescript\nint\n```"}}, {"label": [6, 12], "documentation": {"kind": "markdown", "value": "```rescript\nint\n```"}}, {"label": [14, 17], "documentation": {"kind": "markdown", "value": "```rescript\nint\n```"}}]
303+
"label": "(\n int,\n ~two: string=?,\n ~three: unit => unit,\n ~four: someVariant,\n unit,\n) => unit",
304+
"parameters": [{"label": [0, 7], "documentation": {"kind": "markdown", "value": "```rescript\nint\n```"}}, {"label": [11, 25], "documentation": {"kind": "markdown", "value": "```rescript\noption<string>\n```"}}, {"label": [29, 49], "documentation": {"kind": "markdown", "value": ""}}, {"label": [53, 71], "documentation": {"kind": "markdown", "value": "```rescript\nsomeVariant\n```\n```rescript\ntype someVariant = One | Two | Three\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22SignatureHelp.res%22%2C0%2C0%5D)"}}, {"label": [75, 79], "documentation": {"kind": "markdown", "value": "```rescript\nint\n```"}}],
305+
"documentation": {"kind": "markdown", "value": " Does stuff. "}
298306
}],
299307
"activeSignature": 0,
300308
"activeParameter": 0

0 commit comments

Comments
 (0)