-
Notifications
You must be signed in to change notification settings - Fork 53
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
Conversation
Summary of ChangesHello @xuhuanzy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request primarily refactors the internal logic for how method calls are identified and how their parameters are interpreted, especially regarding the implicit Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request refactors the hover function to improve code readability and maintainability by introducing a new helper function first_param_may_not_self and using matches! for pattern matching. The changes also include updates to function type rendering in hover documentation.
| db_index::{LuaFunctionType, LuaType}, | ||
| }; | ||
| use crate::{SemanticModel, VariadicType}; | ||
| use crate::{SemanticModel, VariadicType, first_param_may_not_self}; |
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.
| if matches!(owner_type, LuaType::Ref(_) | LuaType::Def(_)) | ||
| && first_param_may_not_self(param_type) | ||
| { | ||
| return false; | ||
| } |
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.
The original code used a complex conditional statement to check the type. The refactored code uses matches! which is more concise and readable for pattern matching.
Consider adding a comment explaining the purpose of this check to improve maintainability.
| if matches!(owner_type, LuaType::Ref(_) | LuaType::Def(_)) | |
| && first_param_may_not_self(param_type) | |
| { | |
| return false; | |
| } | |
| if matches!(owner_type, LuaType::Ref(_) | LuaType::Def(_)) { | |
| // These types should not be considered methods. | |
| if first_param_may_not_self(param_type) { | |
| return false; | |
| } | |
| } |
| // 第一个参数是否不应该视为 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 | ||
| } |
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.
This function determines whether the first parameter should not be considered as self. It checks if the type is a table, Ref, Def, or Any, and returns false if it is. If the type is a union, it recursively checks each type in the union. Otherwise, it returns true.
Consider adding a more detailed comment explaining the rationale behind this logic, especially why certain types are excluded from being considered self.
| if matches!(owner_type, LuaType::Ref(_) | LuaType::Def(_)) | ||
| && first_param_may_not_self(t) | ||
| { | ||
| return false; | ||
| } |
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.
The original code used a complex conditional statement to check the type. The refactored code uses matches! which is more concise and readable for pattern matching.
Consider adding a comment explaining the purpose of this check to improve maintainability.
| if matches!(owner_type, LuaType::Ref(_) | LuaType::Def(_)) | |
| && first_param_may_not_self(t) | |
| { | |
| return false; | |
| } | |
| if matches!(owner_type, LuaType::Ref(_) | LuaType::Def(_)) { | |
| // These types should not be considered methods. | |
| if first_param_may_not_self(t) { | |
| return false; | |
| } | |
| } |
| 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() | ||
| } |
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.
No description provided.