@@ -155,6 +155,43 @@ let signatureHelp ~path ~pos ~currentFile ~debug =
155
155
let supportsMarkdownLinks = true in
156
156
let foundFunctionApplicationExpr = ref None in
157
157
let setFound r = foundFunctionApplicationExpr := Some r in
158
+ let searchForArgWithCursor ~args ~exp =
159
+ let extractedArgs = extractExpApplyArgs ~args in
160
+ let argAtCursor =
161
+ let unlabelledArgCount = ref 0 in
162
+ extractedArgs
163
+ |> List. find_map (fun arg ->
164
+ match arg.label with
165
+ | None ->
166
+ let currentUnlabelledArgCount = ! unlabelledArgCount in
167
+ unlabelledArgCount := currentUnlabelledArgCount + 1 ;
168
+ (* An argument without a label is just the expression, so we can use that. *)
169
+ if arg.exp.pexp_loc |> Loc. hasPos ~pos: posBeforeCursor then
170
+ Some (Unlabelled currentUnlabelledArgCount)
171
+ else None
172
+ | Some {name; posStart; posEnd} -> (
173
+ (* Check for the label identifier itself having the cursor *)
174
+ match
175
+ pos |> CursorPosition. classifyPositions ~pos Start ~pos End
176
+ with
177
+ | HasCursor -> Some (Labelled name)
178
+ | NoCursor | EmptyLoc -> (
179
+ (* If we're not in the label, check the exp. Either the exp
180
+ exists and has the cursor. Or the exp is a parser recovery
181
+ node, in which case we assume that the parser recovery
182
+ indicates that the cursor was here. *)
183
+ match
184
+ ( arg.exp.pexp_desc,
185
+ arg.exp.pexp_loc
186
+ |> CursorPosition. classifyLoc ~pos: posBeforeCursor )
187
+ with
188
+ | Pexp_extension ({txt = " rescript.exprhole" }, _), _
189
+ | _ , HasCursor ->
190
+ Some (Labelled name)
191
+ | _ -> None )))
192
+ in
193
+ setFound (argAtCursor, exp, extractedArgs)
194
+ in
158
195
let expr (iterator : Ast_iterator.iterator ) (expr : Parsetree.expression ) =
159
196
(match expr with
160
197
(* Look for applying idents, like someIdent(...) *)
@@ -165,41 +202,7 @@ let signatureHelp ~path ~pos ~currentFile ~debug =
165
202
when pexp_loc
166
203
|> CursorPosition. classifyLoc ~pos: posBeforeCursor
167
204
== HasCursor ->
168
- let extractedArgs = extractExpApplyArgs ~args in
169
- let argAtCursor =
170
- let unlabelledArgCount = ref 0 in
171
- extractedArgs
172
- |> List. find_map (fun arg ->
173
- match arg.label with
174
- | None ->
175
- let currentUnlabelledArgCount = ! unlabelledArgCount in
176
- unlabelledArgCount := currentUnlabelledArgCount + 1 ;
177
- (* An argument without a label is just the expression, so we can use that. *)
178
- if arg.exp.pexp_loc |> Loc. hasPos ~pos: posBeforeCursor then
179
- Some (Unlabelled currentUnlabelledArgCount)
180
- else None
181
- | Some {name; posStart; posEnd} -> (
182
- (* Check for the label identifier itself having the cursor *)
183
- match
184
- pos |> CursorPosition. classifyPositions ~pos Start ~pos End
185
- with
186
- | HasCursor -> Some (Labelled name)
187
- | NoCursor | EmptyLoc -> (
188
- (* If we're not in the label, check the exp. Either the exp
189
- exists and has the cursor. Or the exp is a parser recovery
190
- node, in which case we assume that the parser recovery
191
- indicates that the cursor was here. *)
192
- match
193
- ( arg.exp.pexp_desc,
194
- arg.exp.pexp_loc
195
- |> CursorPosition. classifyLoc ~pos: posBeforeCursor )
196
- with
197
- | Pexp_extension ({txt = " rescript.exprhole" }, _), _
198
- | _ , HasCursor ->
199
- Some (Labelled name)
200
- | _ -> None )))
201
- in
202
- setFound (argAtCursor, exp, extractedArgs)
205
+ searchForArgWithCursor ~args ~exp
203
206
| _ -> () );
204
207
Ast_iterator. default_iterator.expr iterator expr
205
208
in
0 commit comments