Skip to content

Conversation

@xuhuanzy
Copy link
Member

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 self parameter. By extracting a common condition into a dedicated, reusable function, it significantly enhances code readability and consistency across the type analysis components. Additionally, it introduces more granular control over how types are rendered in hover documentation, allowing for dynamic detail levels, and includes a new test to validate these improvements.

Highlights

  • Refactored Method Parameter Logic: Extracted the logic for determining if a function's first parameter should not be considered 'self' into a new, reusable function first_param_may_not_self.
  • Improved Method Call Detection: Applied the new first_param_may_not_self function to simplify and clarify the is_method_call logic within LuaSignature and LuaFunctionType, enhancing consistency.
  • Dynamic Hover Type Rendering: Updated the hover documentation generation to use a configurable detail_render_level for type display, allowing for more flexible and detailed output.
  • New Test Case: Added a new test test_fix_method_1 to ensure correct hover behavior for generic methods, specifically addressing a scenario with ClassControl.new(name: T).
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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};

Choose a reason for hiding this comment

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

medium

Adding first_param_may_not_self to 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.

Comment on lines +140 to 144
if matches!(owner_type, LuaType::Ref(_) | LuaType::Def(_))
&& first_param_may_not_self(param_type)
{
return false;
}

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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;
}
}

Comment on lines +305 to +315
// 第一个参数是否不应该视为 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
}

Choose a reason for hiding this comment

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

medium

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.

Comment on lines +690 to 694
if matches!(owner_type, LuaType::Ref(_) | LuaType::Def(_))
&& first_param_may_not_self(t)
{
return false;
}

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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;
}
}

Comment on lines 361 to 371
if index == 0 && is_method && !func.is_colon_define() {
"".to_string()
} else if let Some(ty) = &param.1 {
format!("{}: {}", name, humanize_type(db, ty, RenderLevel::Normal))
format!(
"{}: {}",
name,
humanize_type(db, ty, builder.detail_render_level)
)
} else {
name.to_string()
}

Choose a reason for hiding this comment

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

medium

The code was reformatted to improve readability by explicitly formatting the string with name, db, ty, and builder.detail_render_level on separate lines. This change enhances maintainability by making it easier to modify the formatting in the future.

@xuhuanzy xuhuanzy changed the title refactor hover function fix Oct 21, 2025
@CppCXY CppCXY merged commit 221edc8 into EmmyLuaLs:main Oct 21, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants