Skip to content

update #539

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

Merged
merged 59 commits into from
Jun 27, 2025
Merged

update #539

merged 59 commits into from
Jun 27, 2025

Conversation

xuhuanzy
Copy link
Member

No description provided.

@xuhuanzy xuhuanzy linked an issue Jun 14, 2025 that may be closed by this pull request
@lewis6991
Copy link
Collaborator

Is this really a good idea? Seems like all locations should be returned. Perhaps you can sort the results instead?

@xuhuanzy
Copy link
Member Author

Is this really a good idea? Seems like all locations should be returned. Perhaps you can sort the results instead?

So I sorted the Find All Implementations to place the actual definitions as far forward as possible.

The compromise is that if there is a matching ---@field func fun(), then return that item along with the actual definition, discarding any other functions defined with @field.

@xuhuanzy
Copy link
Member Author

Alternatively, we can enable this behavior when the number of declarations exceeds a specified threshold.

This behavior is enabled because, in practice, some functions may have a large number of declarations with the same name. A typical example is event. When dealing with hundreds of event overloads, the jump behavior should ideally take us directly to the most matching declaration rather than returning all options for selection, which would be highly inefficient and often meaningless.

@lewis6991
Copy link
Collaborator

lewis6991 commented Jun 14, 2025

In the example:

                ---@class T 
                 ---@field func fun(a:Goto1) # 1 
                 ---@field func fun(a:Goto2) # 2 
                 ---@field func fun(a:Goto3) # 3 
                 local T = {} 
  
                 function T:func(a) 
                 end 
  
                 ---@type T 
                 local t 
  
                 t.func(Goto1) 
                 t.fu<??>nc(Goto2) 
                 t.func(Goto3)

I would expect the locations returned would be the function definition and the matching @field. Removing #1 and #3 makes sense.

However if the argument type isn't known (e.g. is any), then everything should be returned

@xuhuanzy
Copy link
Member Author

I would expect the locations returned would be the function definition and the matching @field. Removing #1 and #3 makes sense.

However if the argument type isn't known (e.g. is any), then everything should be returned

The current behavior of jumping to definition is similar, but it's important to note that if the actual definition is inherited from a parent class, it will not appear here.

Regarding definitions inherited from parent classes, I've observed that luals does not return them when searching for all implementations either. Perhaps we should return the actual definition from the parent class?

@lewis6991
Copy link
Collaborator

When defining classes, so far I mostly inherit from abstract classes, and not from any that implements definitions. What is the most standard way to do that in Lua?

I assume the subclass definition would need to explicitly call the parent class? If so then it's probably ok to not go to the parent definition. I'm not sure though.

@xuhuanzy xuhuanzy force-pushed the update branch 3 times, most recently from d090a84 to 54ff123 Compare June 16, 2025 13:24
@xuhuanzy
Copy link
Member Author

xuhuanzy commented Jun 19, 2025

@lewis6991
In Neovim, how are classes initialized in terms of format? Regarding the __call hint, cppcxy's opinion is that if it's local a = Class(), then prompt local a = new Class(), and if it's not Class(), then
acb9b069cd46b80fbfda84c5dbe6a1c8

@lewis6991
Copy link
Collaborator

lewis6991 commented Jun 19, 2025

Usually something like:

--- @class Class
local Class = {}
Class.__index = Class

function Class:method()
end


function Class.new(arg1, arg2)
  return setmetatable({
    arg1 = arg1,
    arg2 = arg2,
  }, Class)
end

We don't have any formats for classes that inherit other classes because I don't know how to do it.

@xuhuanzy
Copy link
Member Author

xuhuanzy commented Jun 19, 2025

We don't have any formats for classes that inherit other classes because I don't know how to do it.

Generally speaking, it is achieved through several specific functions to centralize definition and instantiation.

Then this feature is not useful to you; currently, it only provides hints when ---@overload is present.

image

@xuhuanzy xuhuanzy linked an issue Jun 23, 2025 that may be closed by this pull request
@xuhuanzy xuhuanzy linked an issue Jun 23, 2025 that may be closed by this pull request
@CppCXY CppCXY merged commit c7b0301 into EmmyLuaLs:main Jun 27, 2025
15 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
3 participants