-
Notifications
You must be signed in to change notification settings - Fork 54
fix #814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #814
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ use crate::{ | |||||||||||||||||||||||
| FileId, | ||||||||||||||||||||||||
| db_index::{LuaFunctionType, LuaType}, | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| use crate::{SemanticModel, VariadicType}; | ||||||||||||||||||||||||
| use crate::{SemanticModel, VariadicType, first_param_may_not_self}; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #[derive(Debug)] | ||||||||||||||||||||||||
| pub struct LuaSignature { | ||||||||||||||||||||||||
|
|
@@ -137,11 +137,8 @@ impl LuaSignature { | |||||||||||||||||||||||
| match owner_type { | ||||||||||||||||||||||||
| Some(owner_type) => { | ||||||||||||||||||||||||
| // 一些类型不应该被视为 method | ||||||||||||||||||||||||
| if let (LuaType::Ref(_) | LuaType::Def(_), _) = (owner_type, param_type) | ||||||||||||||||||||||||
| && (param_type.is_any() | ||||||||||||||||||||||||
| || param_type.is_table() | ||||||||||||||||||||||||
| || param_type.is_class_tpl() | ||||||||||||||||||||||||
| || param_type.is_str_tpl_ref()) | ||||||||||||||||||||||||
| if matches!(owner_type, LuaType::Ref(_) | LuaType::Def(_)) | ||||||||||||||||||||||||
| && first_param_may_not_self(param_type) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+140
to
144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original code used a complex conditional statement to check the type. The refactored code uses Consider adding a comment explaining the purpose of this check to improve maintainability.
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -301,3 +301,15 @@ fn get_real_type_with_depth<'a>( | |
| _ => Some(typ), | ||
| } | ||
| } | ||
|
|
||
| // 第一个参数是否不应该视为 self | ||
| pub fn first_param_may_not_self(typ: &LuaType) -> bool { | ||
| if typ.is_table() || matches!(typ, LuaType::Ref(_) | LuaType::Def(_) | LuaType::Any) { | ||
| return false; | ||
| } | ||
| if let LuaType::Union(u) = typ { | ||
| return u.into_vec().iter().any(first_param_may_not_self); | ||
| } | ||
|
|
||
| true | ||
| } | ||
|
Comment on lines
+305
to
+315
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function determines whether the first parameter should not be considered as Consider adding a more detailed comment explaining the rationale behind this logic, especially why certain types are excluded from being considered |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ use smol_str::SmolStr; | |||||||||||||||||||||||
| use crate::{ | ||||||||||||||||||||||||
| AsyncState, DbIndex, FileId, InFiled, SemanticModel, | ||||||||||||||||||||||||
| db_index::{LuaMemberKey, LuaSignatureId, r#type::type_visit_trait::TypeVisitTrait}, | ||||||||||||||||||||||||
| first_param_may_not_self, | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| use super::{TypeOps, type_decl::LuaTypeDeclId}; | ||||||||||||||||||||||||
|
|
@@ -686,11 +687,8 @@ impl LuaFunctionType { | |||||||||||||||||||||||
| match owner_type { | ||||||||||||||||||||||||
| Some(owner_type) => { | ||||||||||||||||||||||||
| // 一些类型不应该被视为 method | ||||||||||||||||||||||||
| if let (LuaType::Ref(_) | LuaType::Def(_), _) = (owner_type, t) | ||||||||||||||||||||||||
| && (t.is_any() | ||||||||||||||||||||||||
| || t.is_table() | ||||||||||||||||||||||||
| || t.is_class_tpl() | ||||||||||||||||||||||||
| || t.is_str_tpl_ref()) | ||||||||||||||||||||||||
| if matches!(owner_type, LuaType::Ref(_) | LuaType::Def(_)) | ||||||||||||||||||||||||
| && first_param_may_not_self(t) | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+690
to
694
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original code used a complex conditional statement to check the type. The refactored code uses Consider adding a comment explaining the purpose of this check to improve maintainability.
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -361,7 +361,11 @@ fn hover_doc_function_type( | |
| if index == 0 && is_method && !func.is_colon_define() { | ||
| "".to_string() | ||
| } else if let Some(ty) = ¶m.1 { | ||
| format!("{}: {}", name, humanize_type(db, ty, RenderLevel::Normal)) | ||
| format!( | ||
| "{}: {}", | ||
| name, | ||
| humanize_type(db, ty, builder.detail_render_level) | ||
| ) | ||
| } else { | ||
| name.to_string() | ||
| } | ||
|
Comment on lines
361
to
371
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
first_param_may_not_selfto the use statement increases code readability by explicitly stating the dependencies of this module. This makes it easier to understand the module's functionality without having to search for the function's definition.