Skip to content

Commit 33de948

Browse files
committed
support async infer for closure
1 parent 0e52e41 commit 33de948

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

crates/code_analysis/src/compilation/analyzer/unresolve/resolve_closure_param.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
2-
infer_call_expr_func, infer_expr, DbIndex, InferGuard, LuaDocParamInfo, LuaInferConfig, LuaType,
2+
infer_call_expr_func, infer_expr, DbIndex, InferGuard, LuaDocParamInfo, LuaInferConfig,
3+
LuaPropertyOwnerId, LuaType,
34
};
45

56
use super::UnResolveClosureParams;
@@ -19,16 +20,19 @@ pub fn try_resolve_closure_params(
1920
call_expr,
2021
call_expr_type,
2122
&mut InferGuard::new(),
22-
None
23+
None,
2324
)?;
2425

25-
let signature = db
26-
.get_signature_index_mut()
27-
.get_mut(&closure_params.signature_id)?;
28-
2926
let expr_closure_params =
3027
if let Some(param_type) = call_doc_func.get_params().get(closure_params.param_idx) {
3128
if let Some(LuaType::DocFunction(func)) = &param_type.1 {
29+
if func.is_async() {
30+
let file_id = closure_params.file_id;
31+
let property_owner = LuaPropertyOwnerId::Signature(closure_params.signature_id);
32+
db.get_property_index_mut()
33+
.add_async(file_id, property_owner);
34+
}
35+
3236
func.get_params()
3337
} else {
3438
return Some(true);
@@ -37,6 +41,10 @@ pub fn try_resolve_closure_params(
3741
return Some(true);
3842
};
3943

44+
let signature = db
45+
.get_signature_index_mut()
46+
.get_mut(&closure_params.signature_id)?;
47+
4048
let signature_params = &mut signature.param_docs;
4149
for (idx, (name, type_ref)) in expr_closure_params.iter().enumerate() {
4250
if signature_params.contains_key(&idx) {

resources/std/coroutine.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ coroutine = {}
1818
---
1919
--- Creates a new coroutine, with body `f`. `f` must be a Lua function. Returns
2020
--- this new coroutine, an object with type `"thread"`.
21-
---@param f fun():thread
21+
---@param f async fun(...)
2222
---@return thread
2323
function coroutine.create(f) end
2424

@@ -62,7 +62,7 @@ function coroutine.resume(co, ...) end
6262
---
6363
--- Returns the running coroutine plus a boolean, true when the running
6464
--- coroutine is the main one.
65-
---@return thread|boolean, string
65+
---@return thread, string
6666
function coroutine.running() end
6767

6868
---
@@ -86,7 +86,7 @@ function coroutine.status(co) end
8686
--- passed to the function behave as the extra arguments to `resume`. Returns
8787
--- the same values returned by `resume`, except the first
8888
--- boolean. In case of error, propagates the error.
89-
---@param f fun():thread
89+
---@param f async fun()
9090
---@return fun():any
9191
function coroutine.wrap(f) end
9292

0 commit comments

Comments
 (0)