File tree 6 files changed +45
-8
lines changed
6 files changed +45
-8
lines changed Original file line number Diff line number Diff line change 18
18
- Add completion to top level decorators. https://github.com/rescript-lang/rescript-vscode/pull/799
19
19
- Add code action for wrapping patterns where option is expected with ` Some ` . https://github.com/rescript-lang/rescript-vscode/pull/806
20
20
- Better completion from identifiers with inferred types. https://github.com/rescript-lang/rescript-vscode/pull/808
21
+ - Make suggested template functions async when the target function returns a promise. https://github.com/rescript-lang/rescript-vscode/pull/816
21
22
22
23
#### :nail_care : Polish
23
24
Original file line number Diff line number Diff line change @@ -1382,8 +1382,8 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
1382
1382
~env () ;
1383
1383
]
1384
1384
else []
1385
- | Tfunction {env; typ; args; uncurried} when prefix = " " && mode = Expression
1386
- ->
1385
+ | Tfunction {env; typ; args; uncurried; returnType}
1386
+ when prefix = " " && mode = Expression ->
1387
1387
let shouldPrintAsUncurried = uncurried && ! Config. uncurried <> Uncurried in
1388
1388
let mkFnArgs ~asSnippet =
1389
1389
match args with
@@ -1419,11 +1419,18 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
1419
1419
in
1420
1420
" (" ^ if shouldPrintAsUncurried then " . " else " " ^ argsText ^ " )"
1421
1421
in
1422
+ let isAsync =
1423
+ match TypeUtils. extractType ~env ~package: full.package returnType with
1424
+ | Some (Tpromise _ ) -> true
1425
+ | _ -> false
1426
+ in
1427
+ let asyncPrefix = if isAsync then " async " else " " in
1422
1428
[
1423
1429
Completion. createWithSnippet
1424
- ~name: (mkFnArgs ~as Snippet:false ^ " => {}" )
1430
+ ~name: (asyncPrefix ^ mkFnArgs ~as Snippet:false ^ " => {}" )
1425
1431
~insert Text:
1426
- (mkFnArgs ~as Snippet:! Cfg. supportsSnippets
1432
+ (asyncPrefix
1433
+ ^ mkFnArgs ~as Snippet:! Cfg. supportsSnippets
1427
1434
^ " => "
1428
1435
^ if ! Cfg. supportsSnippets then " {$0}" else " {}" )
1429
1436
~sort Text:" A" ~kind: (Value typ) ~env () ;
Original file line number Diff line number Diff line change @@ -343,6 +343,7 @@ and completionType =
343
343
args : typedFnArg list ;
344
344
typ : Types .type_expr ;
345
345
uncurried : bool ;
346
+ returnType : Types .type_expr ;
346
347
}
347
348
348
349
module Env = struct
Original file line number Diff line number Diff line change @@ -125,8 +125,8 @@ let rec extractType ~env ~package (t : Types.type_expr) =
125
125
| Tconstr (Pident {name = "function$" } , [t ; _ ], _ ) -> (
126
126
(* Uncurried functions. *)
127
127
match extractFunctionType t ~env ~package with
128
- | args , _tRet when args <> [] ->
129
- Some (Tfunction {env; args; typ = t; uncurried = true })
128
+ | args , tRet when args <> [] ->
129
+ Some (Tfunction {env; args; typ = t; uncurried = true ; returnType = tRet })
130
130
| _args , _tRet -> None )
131
131
| Tconstr (path , typeArgs , _ ) -> (
132
132
match References. digConstructor ~env ~package path with
@@ -168,8 +168,9 @@ let rec extractType ~env ~package (t : Types.type_expr) =
168
168
Some (Tpolyvariant {env; constructors; typeExpr = t})
169
169
| Tarrow _ -> (
170
170
match extractFunctionType t ~env ~package with
171
- | args , _tRet when args <> [] ->
172
- Some (Tfunction {env; args; typ = t; uncurried = false })
171
+ | args , tRet when args <> [] ->
172
+ Some
173
+ (Tfunction {env; args; typ = t; uncurried = false ; returnType = tRet})
173
174
| _args , _tRet -> None )
174
175
| _ -> None
175
176
Original file line number Diff line number Diff line change @@ -250,3 +250,10 @@ external commitLocalUpdate: (~updater: RecordSourceSelectorProxy.t => unit) => u
250
250
251
251
// commitLocalUpdate(~updater=)
252
252
// ^com
253
+
254
+ let fnTakingAsyncCallback = (cb : unit => promise <unit >) => {
255
+ let _ = cb
256
+ }
257
+
258
+ // fnTakingAsyncCallback()
259
+ // ^com
Original file line number Diff line number Diff line change @@ -1074,3 +1074,23 @@ Path commitLocalUpdate
1074
1074
"insertTextFormat": 2
1075
1075
}]
1076
1076
1077
+ Complete src/CompletionExpressions.res 257:25
1078
+ posCursor:[257:25] posNoWhite:[257:24] Found expr:[257:3->257:26]
1079
+ Pexp_apply ...[257:3->257:24] (...[257:25->257:26])
1080
+ Completable: Cexpression CArgument Value[fnTakingAsyncCallback]($0)
1081
+ Package opens Pervasives.JsxModules.place holder
1082
+ Resolved opens 1 pervasives
1083
+ ContextPath CArgument Value[fnTakingAsyncCallback]($0)
1084
+ ContextPath Value[fnTakingAsyncCallback]
1085
+ Path fnTakingAsyncCallback
1086
+ [{
1087
+ "label": "async () => {}",
1088
+ "kind": 12,
1089
+ "tags": [],
1090
+ "detail": "unit => promise<unit>",
1091
+ "documentation": null,
1092
+ "sortText": "A",
1093
+ "insertText": "async () => {$0}",
1094
+ "insertTextFormat": 2
1095
+ }]
1096
+
You can’t perform that action at this time.
0 commit comments