Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,26 @@ fn check_doc(

let comment = get_closure_expr_comment(closure_expr);

if comment.is_none() && is_global {
let code = if is_global {
DiagnosticCode::MissingGlobalDoc
} else {
DiagnosticCode::IncompleteSignatureDoc
};

if comment.is_none() {
let message = if is_global {
t!(
"Missing comment for global function `%{name}`.",
name = function_name
)
} else {
t!(
"Missing comment for function `%{name}`.",
name = function_name
)
};
if let Some(stat) = closure_expr.get_parent::<LuaStat>() {
context.add_diagnostic(
DiagnosticCode::MissingGlobalDoc,
stat.get_range(),
t!(
"Missing comment for global function `%{name}`.",
name = function_name
)
.to_string(),
None,
);
context.add_diagnostic(code, stat.get_range(), message.to_string(), None);
}
return Some(());
}
Expand All @@ -64,12 +72,6 @@ fn check_doc(
return Some(());
};

let code = if is_global {
DiagnosticCode::MissingGlobalDoc
} else {
DiagnosticCode::IncompleteSignatureDoc
};

let doc_param_names: HashSet<String> = comment
.children::<LuaDocTagParam>()
.filter_map(|param| {
Expand All @@ -84,11 +86,6 @@ fn check_doc(
.map(|return_doc| return_doc.get_types().count())
.sum();

// 如果文档中没有参数和返回值注解, 且不是全局函数, 则不检查
if doc_param_names.is_empty() && doc_return_len == 0 && !is_global {
return Some(());
}

check_params(
context,
closure_expr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,29 @@ mod tests {
let mut ws = VirtualWorkspace::new();
ws.enable_full_diagnostic();

// TODO: closures are not detected as functions in the semantic model
// assert!(!ws.check_code_for(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't know how to handle it, you can ask AI for help.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have to be this PR?
Closures are not detected for global functions either. So I'm not sure if fixing that needs to be done right now.
The functionality that I am adding is unrelated to fixing the function detection.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, That sounds reasonable.

// DiagnosticCode::MissingGlobalDoc,
// r#"
// local c = function(x, y)
// return x + y
// end
// "#
// ));

assert!(!ws.check_code_for(
DiagnosticCode::IncompleteSignatureDoc,
r#"
---@param p number
local function FLPR3(p, e)
return 0
local function do_add(x, y)
return x + y
end
"#
));

assert!(!ws.check_code_for(
DiagnosticCode::IncompleteSignatureDoc,
r#"
local function noop()
end
"#
));
Expand All @@ -38,24 +55,26 @@ mod tests {
DiagnosticCode::IncompleteSignatureDoc,
r#"
---@param p number
local function FLPR3(p)
local function FLPR3(p, e)
return 0
end
"#
));

assert!(ws.check_code_for(
assert!(!ws.check_code_for(
DiagnosticCode::IncompleteSignatureDoc,
r#"
---@param p number
local function FLPR3(p)
return 0
end
"#
));
assert!(ws.check_code_for(

assert!(!ws.check_code_for(
DiagnosticCode::IncompleteSignatureDoc,
r#"
---
--- function without param signature
local function FLPR3(p)
return 0
end
Expand Down