Skip to content

Commit 4184e3b

Browse files
committed
handle pipe in signature help
1 parent 0ef49f0 commit 4184e3b

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

analysis/src/SignatureHelp.ml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,14 @@ let signatureHelp ~path ~pos ~currentFile ~debug =
154154
let posBeforeCursor = Pos.posBeforeCursor pos in
155155
let supportsMarkdownLinks = true in
156156
let foundFunctionApplicationExpr = ref None in
157-
let setFound r = foundFunctionApplicationExpr := Some r in
158-
let searchForArgWithCursor ~args ~exp =
157+
let setFound r =
158+
if !foundFunctionApplicationExpr = None then
159+
foundFunctionApplicationExpr := Some r
160+
in
161+
let searchForArgWithCursor ~isPipeExpr ~args ~exp =
159162
let extractedArgs = extractExpApplyArgs ~args in
160163
let argAtCursor =
161-
let unlabelledArgCount = ref 0 in
164+
let unlabelledArgCount = ref (if isPipeExpr then 1 else 0) in
162165
extractedArgs
163166
|> List.find_map (fun arg ->
164167
match arg.label with
@@ -194,6 +197,25 @@ let signatureHelp ~path ~pos ~currentFile ~debug =
194197
in
195198
let expr (iterator : Ast_iterator.iterator) (expr : Parsetree.expression) =
196199
(match expr with
200+
(* Handle pipes, like someVar->someFunc(... *)
201+
| {
202+
pexp_desc =
203+
Pexp_apply
204+
( {pexp_desc = Pexp_ident {txt = Lident "|."}},
205+
[
206+
_;
207+
( _,
208+
{
209+
pexp_desc =
210+
Pexp_apply (({pexp_desc = Pexp_ident _} as exp), args);
211+
pexp_loc;
212+
} );
213+
] );
214+
}
215+
when pexp_loc
216+
|> CursorPosition.classifyLoc ~pos:posBeforeCursor
217+
== HasCursor ->
218+
searchForArgWithCursor ~isPipeExpr:true ~args ~exp
197219
(* Look for applying idents, like someIdent(...) *)
198220
| {
199221
pexp_desc = Pexp_apply (({pexp_desc = Pexp_ident _} as exp), args);
@@ -202,7 +224,7 @@ let signatureHelp ~path ~pos ~currentFile ~debug =
202224
when pexp_loc
203225
|> CursorPosition.classifyLoc ~pos:posBeforeCursor
204226
== HasCursor ->
205-
searchForArgWithCursor ~args ~exp
227+
searchForArgWithCursor ~isPipeExpr:false ~args ~exp
206228
| _ -> ());
207229
Ast_iterator.default_iterator.expr iterator expr
208230
in

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ posCursor:[53:29] posNoWhite:[53:28] Found expr:[53:20->53:31]
203203
Pexp_apply ...[53:20->53:29] (...[53:30->53:31])
204204
posCursor:[53:29] posNoWhite:[53:28] Found expr:[53:20->53:29]
205205
Pexp_ident otherFunc:[53:20->53:29]
206-
argAtCursor: unlabelled<0>
206+
argAtCursor: unlabelled<1>
207207
extracted params:
208208
[(string, int, float]
209209
{
@@ -212,6 +212,6 @@ extracted params:
212212
"parameters": [{"label": [15, 22], "documentation": {"kind": "markdown", "value": "```rescript\nstring\n```"}}, {"label": [24, 27], "documentation": {"kind": "markdown", "value": "```rescript\nstring\n```"}}, {"label": [29, 34], "documentation": {"kind": "markdown", "value": "```rescript\nstring\n```"}}]
213213
}],
214214
"activeSignature": 0,
215-
"activeParameter": 0
215+
"activeParameter": 1
216216
}
217217

0 commit comments

Comments
 (0)