lua-language-server
lua-language-server copied to clipboard
No IntelliSense for callbacks - named functions.
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Other
Expected Behaviour
Function would have Intellisense like the anonymous function in picture.
Actual Behaviour
No Intellisense for function.
Reproduction steps
none
Additional Notes
No response
Log File
No response
Do you have a definition file that defines what Events.OnTriggerNPCEvent.Add()
accepts? It appears that you do. You would probably want to make the callback an @alias
so that you can tell the language server the expected signature of the function:
---@alias NPC_Event_Callback fun(type: string, data: table, def: BuildingDef): any
---@type NPC_Event_Callback
local function triggered() end
It can then be used for your definition of Events.OnTriggerNPCEvent.Add()
as well:
---@param callback NPC_Event_Callback
function Events.OnTriggerNPCEvent.Add(callback) end
Thank you, this works. Only issue with example is to use the alias as param name or in comment for better visibility.
---@param NPC_Event_Callback NPC_Event_Callback
function Events.OnTriggerNPCEvent.Add(NPC_Event_Callback) end
Has this been fixed to show automatically or is it not a planned feature?
Sorry, I thought you meant the only issue you had with my example was that the parameter was named different from the alias. Do you want the parameter to automatically receive the name of the alias? I'm not sure what you mean.
Maybe you mean expandAlias?
I was wondering if it was possible to achieve this automatically, without adding an alias at all.
I don't believe so. The anonymous function is receiving completion because Events.OnTriggerNPCEvent.Add()
is describing its callback
parameter. When you define the function separately, there is no association with Events.OnTriggerNPCEvent.Add()
.
I'm not really sure if this can be automatically supported because when you are writing the function separately like this, you are defining it right then and there, therefor its signature is as it is defined. Either way, I'll reopen this for sumneko to decide whether this is something that can be done.