Skip to content

Commit 6a7effa

Browse files
committed
fix Clippy
1 parent 7935f0b commit 6a7effa

File tree

9 files changed

+56
-63
lines changed

9 files changed

+56
-63
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"files.insertFinalNewline": true,
44
"files.trimFinalNewlines": true,
55
"files.trimTrailingWhitespace": true,
6-
"files.trimTrailingWhitespaceInRegexAndStrings": true
6+
"files.trimTrailingWhitespaceInRegexAndStrings": true,
7+
"rust-analyzer.check.command": "clippy",
78
}

crates/emmylua_code_analysis/src/compilation/analyzer/lua/call.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,29 @@ use crate::{
77

88
pub fn analyze_call(analyzer: &mut LuaAnalyzer, call_expr: LuaCallExpr) -> Option<()> {
99
let prefix_expr = call_expr.clone().get_prefix_expr()?;
10-
match analyzer.infer_expr(&prefix_expr) {
11-
Ok(expr_type) => {
12-
let LuaType::Signature(signature_id) = expr_type else {
13-
return Some(());
14-
};
15-
let signature = analyzer.db.get_signature_index().get(&signature_id)?;
16-
for (idx, param_info) in signature.param_docs.iter() {
17-
if let Some(ref attrs) = param_info.attributes {
18-
for attr in attrs.iter() {
19-
if attr.id.get_name() == "class_ctor" {
20-
let unresolve = UnResolveClassCtor {
21-
file_id: analyzer.file_id,
22-
call_expr: call_expr.clone(),
23-
signature_id: signature_id,
24-
param_idx: *idx,
25-
};
26-
analyzer
27-
.context
28-
.add_unresolve(unresolve.into(), InferFailReason::None);
29-
return Some(());
30-
}
10+
if let Ok(expr_type) = analyzer.infer_expr(&prefix_expr) {
11+
let LuaType::Signature(signature_id) = expr_type else {
12+
return Some(());
13+
};
14+
let signature = analyzer.db.get_signature_index().get(&signature_id)?;
15+
for (idx, param_info) in signature.param_docs.iter() {
16+
if let Some(ref attrs) = param_info.attributes {
17+
for attr in attrs.iter() {
18+
if attr.id.get_name() == "class_ctor" {
19+
let unresolve = UnResolveClassCtor {
20+
file_id: analyzer.file_id,
21+
call_expr: call_expr.clone(),
22+
signature_id,
23+
param_idx: *idx,
24+
};
25+
analyzer
26+
.context
27+
.add_unresolve(unresolve.into(), InferFailReason::None);
28+
return Some(());
3129
}
3230
}
3331
}
3432
}
35-
Err(_) => {}
3633
}
3734
Some(())
3835
}

crates/emmylua_code_analysis/src/compilation/analyzer/unresolve/resolve.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ pub fn try_resolve_class_ctor(
272272
.find(|attr| attr.id.get_name() == "class_ctor")
273273
.ok_or(InferFailReason::None)?;
274274
let LuaType::DocStringConst(target_signature_name) =
275-
class_ctor_use.args.get(0).ok_or(InferFailReason::None)?
275+
class_ctor_use.args.first().ok_or(InferFailReason::None)?
276276
else {
277277
return Err(InferFailReason::None);
278278
};
@@ -365,31 +365,28 @@ fn get_class_ctor_target_type(
365365
call_expr: LuaCallExpr,
366366
call_index: usize,
367367
) -> Option<LuaTypeDeclId> {
368-
match param_type {
369-
LuaType::StrTplRef(str_tpl) => {
370-
let name = {
371-
let arg_expr = call_expr
372-
.get_args_list()?
373-
.get_args()
374-
.nth(call_index)?
375-
.clone();
376-
let name = infer_expr(db, cache, arg_expr).ok()?;
377-
match name {
378-
LuaType::StringConst(s) => s.to_string(),
379-
_ => return None,
380-
}
381-
};
382-
383-
let prefix = str_tpl.get_prefix();
384-
let suffix = str_tpl.get_suffix();
385-
let type_decl_id: LuaTypeDeclId =
386-
LuaTypeDeclId::new(format!("{}{}{}", prefix, name, suffix).as_str());
387-
let type_decl = db.get_type_index().get_type_decl(&type_decl_id)?;
388-
if type_decl.is_class() {
389-
return Some(type_decl_id);
368+
if let LuaType::StrTplRef(str_tpl) = param_type {
369+
let name = {
370+
let arg_expr = call_expr
371+
.get_args_list()?
372+
.get_args()
373+
.nth(call_index)?
374+
.clone();
375+
let name = infer_expr(db, cache, arg_expr).ok()?;
376+
match name {
377+
LuaType::StringConst(s) => s.to_string(),
378+
_ => return None,
390379
}
380+
};
381+
382+
let prefix = str_tpl.get_prefix();
383+
let suffix = str_tpl.get_suffix();
384+
let type_decl_id: LuaTypeDeclId =
385+
LuaTypeDeclId::new(format!("{}{}{}", prefix, name, suffix).as_str());
386+
let type_decl = db.get_type_index().get_type_decl(&type_decl_id)?;
387+
if type_decl.is_class() {
388+
return Some(type_decl_id);
391389
}
392-
_ => {}
393390
}
394391

395392
None

crates/emmylua_code_analysis/src/diagnostic/checker/assign_type_mismatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub fn check_table_expr(
221221
if let Some(attribute_uses) = property.attribute_uses() {
222222
for attribute_use in attribute_uses.iter() {
223223
if attribute_use.id.get_name() == "skip_diagnostic" {
224-
if let Some(LuaType::DocStringConst(code)) = attribute_use.args.get(0) {
224+
if let Some(LuaType::DocStringConst(code)) = attribute_use.args.first() {
225225
if code.as_ref() == "table_field" {
226226
return Some(false);
227227
}

crates/emmylua_code_analysis/src/diagnostic/checker/attribute_check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn check_param_count(
6767
context: &mut DiagnosticContext,
6868
def_params: &[(String, Option<LuaType>)],
6969
attribute_use: &LuaDocAttributeUse,
70-
args: &Vec<LuaLiteralExpr>,
70+
args: &[LuaLiteralExpr],
7171
) -> Option<()> {
7272
let call_args_count = args.len();
7373
// 调用参数少于定义参数, 需要考虑可空参数
@@ -76,7 +76,7 @@ fn check_param_count(
7676
if def_param.0 == "..." {
7777
break;
7878
}
79-
if def_param.1.as_ref().is_some_and(|typ| is_nullable(typ)) {
79+
if def_param.1.as_ref().is_some_and(is_nullable) {
8080
continue;
8181
}
8282
context.add_diagnostic(

crates/emmylua_ls/src/handlers/completion/add_completions/add_member_completion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ pub fn get_index_alias_name(
362362
let alias_label = common_property
363363
.find_attribute_use(LuaTypeDeclId::new("index_alias"))?
364364
.args
365-
.get(0)
365+
.first()
366366
.map(|param| match param {
367367
LuaType::DocStringConst(s) => s.as_ref(),
368368
_ => "",

crates/emmylua_ls/src/handlers/completion/providers/doc_name_token_provider.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn get_doc_completion_expected(trigger_token: &LuaSyntaxToken) -> Option<DocComp
8585
Some(DocCompletionExpected::DiagnosticCode)
8686
}
8787
LuaSyntaxKind::DocTypeFlag => {
88-
let attr = LuaDocTypeFlag::cast(parent.clone().into())?;
88+
let attr = LuaDocTypeFlag::cast(parent.clone())?;
8989
Some(DocCompletionExpected::ClassFlag(attr))
9090
}
9191
_ => None,
@@ -106,7 +106,7 @@ fn get_doc_completion_expected(trigger_token: &LuaSyntaxToken) -> Option<DocComp
106106
match parent.kind().into() {
107107
LuaSyntaxKind::DocDiagnosticCodeList => Some(DocCompletionExpected::DiagnosticCode),
108108
LuaSyntaxKind::DocTypeFlag => {
109-
let attr = LuaDocTypeFlag::cast(parent.clone().into())?;
109+
let attr = LuaDocTypeFlag::cast(parent.clone())?;
110110
Some(DocCompletionExpected::ClassFlag(attr))
111111
}
112112
_ => None,
@@ -116,7 +116,7 @@ fn get_doc_completion_expected(trigger_token: &LuaSyntaxToken) -> Option<DocComp
116116
let parent = trigger_token.parent()?;
117117
match parent.kind().into() {
118118
LuaSyntaxKind::DocTypeFlag => {
119-
let attr = LuaDocTypeFlag::cast(parent.clone().into())?;
119+
let attr = LuaDocTypeFlag::cast(parent.clone())?;
120120
Some(DocCompletionExpected::ClassFlag(attr))
121121
}
122122
_ => None,

crates/emmylua_ls/src/handlers/completion/providers/doc_type_provider.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn check_can_add_type_completion(builder: &CompletionBuilder) -> Option<Completi
8787
LuaTokenKind::TkName => {
8888
let parent = builder.trigger_token.parent()?;
8989
if let Some(doc_name) = LuaDocNameType::cast(parent) {
90-
if let Some(_) = doc_name.get_parent::<LuaDocAttributeUse>() {
90+
if doc_name.get_parent::<LuaDocAttributeUse>().is_some() {
9191
return Some(CompletionType::AttributeUse);
9292
}
9393
return Some(CompletionType::Type);
@@ -129,7 +129,7 @@ fn check_can_add_type_completion(builder: &CompletionBuilder) -> Option<Completi
129129
None
130130
}
131131
LuaTokenKind::TkDocAttributeUse => {
132-
return Some(CompletionType::AttributeUse);
132+
Some(CompletionType::AttributeUse)
133133
}
134134
_ => None,
135135
}

crates/emmylua_ls/src/handlers/semantic_token/build_semantic_tokens.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -785,14 +785,12 @@ fn build_node_semantic_token(
785785
}
786786
LuaAst::LuaDocTagAttributeUse(tag_use) => {
787787
// 给 `@[]` 染色, @已经染色过了
788-
tag_use
789-
.token_by_kind(LuaTokenKind::TkDocAttributeUse)
790-
.map(|token| {
791-
builder.push(token.syntax(), SemanticTokenType::KEYWORD);
792-
});
793-
tag_use.syntax().last_token().map(|token| {
788+
if let Some(token) = tag_use.token_by_kind(LuaTokenKind::TkDocAttributeUse) {
789+
builder.push(token.syntax(), SemanticTokenType::KEYWORD);
790+
}
791+
if let Some(token) = tag_use.syntax().last_token() {
794792
builder.push(&token, SemanticTokenType::KEYWORD);
795-
});
793+
}
796794
}
797795
_ => {}
798796
}

0 commit comments

Comments
 (0)