Skip to content

Commit 408d6e2

Browse files
committed
implement on_install filter
1 parent ad3bfa3 commit 408d6e2

File tree

7 files changed

+26
-8
lines changed

7 files changed

+26
-8
lines changed

crates/xmake_code_analysis/resources/std/xmake/package_dependencies.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ function on_fetch(os, func) end
330330
--- end)
331331
--- ```
332332
---@scope package
333+
---@overload fun(...: string, func: PackageHook): nil
333334
---@param func PackageHook Function to run when installing
334335
---@return nil
335-
function on_install(func) end
336-
336+
function on_install(func, ...) end
337337
---Custom download package
338338
---
339339
---[Open in browser](https://xmake.io/api/description/package-dependencies#on_download)

crates/xmake_code_analysis/resources/std/xmake/project_target.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,10 @@ function on_package(func) end
309309
---
310310
---[Open in browser](https://xmake.io/api/description/project-target#on_install)
311311
---@scope target
312+
---@overload fun(...: string, func: TargetHook): nil
312313
---@param func TargetHook Function to run for custom install
313314
---@return nil
314-
function on_install(func) end
315+
function on_install(func, ...) end
315316

316317
---
317318
---Run custom uninstall target file script

crates/xmake_code_analysis/src/compilation/analyzer/lua/closure.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ fn analyze_lambda_params(
5555
LuaAst::LuaCallArgList(call_arg_list) => {
5656
let call_expr = call_arg_list.get_parent::<LuaCallExpr>()?;
5757
let pos = closure.get_position();
58-
let founded_idx = call_arg_list
59-
.get_args()
60-
.position(|arg| arg.get_position() == pos)?;
58+
let args = call_arg_list.get_args().collect::<Vec<_>>();
59+
let founded_idx = args.iter().position(|arg| arg.get_position() == pos)?;
60+
let is_last_param = founded_idx == args.len() - 1;
6161

6262
let unresolved = UnResolveCallClosureParams {
6363
file_id: analyzer.file_id,
6464
signature_id: signature_id.clone(),
6565
call_expr,
6666
param_idx: founded_idx,
67+
is_last_param,
6768
};
6869

6970
analyzer

crates/xmake_code_analysis/src/compilation/analyzer/unresolve/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ pub struct UnResolveCallClosureParams {
340340
pub signature_id: LuaSignatureId,
341341
pub call_expr: LuaCallExpr,
342342
pub param_idx: usize,
343+
pub is_last_param: bool,
343344
}
344345

345346
impl From<UnResolveCallClosureParams> for UnResolve {

crates/xmake_code_analysis/src/compilation/analyzer/unresolve/resolve_closure.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ pub fn try_resolve_call_closure_params(
5050
_ => {}
5151
}
5252

53-
let (async_state, params_to_insert) = if let Some(param_type) =
53+
let param_type = if closure_params.is_last_param {
54+
call_doc_func.get_params().last()
55+
} else {
5456
call_doc_func.get_params().get(param_idx)
55-
{
57+
};
58+
let (async_state, params_to_insert) = if let Some(param_type) = param_type {
5659
let Some(param_type) = get_real_type(db, &param_type.1.as_ref().unwrap_or(&LuaType::Any))
5760
else {
5861
return Ok(());

crates/xmake_code_analysis/src/diagnostic/checker/check_param_count.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ fn check_call_expr(
109109
}
110110
}
111111

112+
// 没必要检查
113+
if fake_params.len() > 1 && fake_params.first()?.0 == "..." {
114+
return None;
115+
}
116+
112117
// Check for missing parameters
113118
if call_args_count < fake_params.len() {
114119
// 调用参数包含 `...`

crates/xmake_code_analysis/src/diagnostic/checker/param_type_check.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ fn check_call_expr(
5959
}
6060
}
6161

62+
if params.len() > 1 && params.first()?.0 == "..." {
63+
// 可变参数在前面, 则反向检查
64+
params.reverse();
65+
arg_types.reverse();
66+
arg_ranges.reverse();
67+
}
68+
6269
for (idx, param) in params.iter().enumerate() {
6370
if param.0 == "..." {
6471
if arg_types.len() < idx {

0 commit comments

Comments
 (0)