lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

No IntelliSense for callbacks - named functions.

Open Poltergeist-ix opened this issue 1 year ago • 6 comments

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. pic1-Intellisense

Actual Behaviour

No Intellisense for function. pic1-no-IntelliSense

Reproduction steps

none

Additional Notes

No response

Log File

No response

Poltergeist-ix avatar Oct 13 '23 08:10 Poltergeist-ix

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

carsakiller avatar Oct 13 '23 19:10 carsakiller

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

Poltergeist-ix avatar Oct 14 '23 07:10 Poltergeist-ix

Has this been fixed to show automatically or is it not a planned feature?

Poltergeist-ix avatar Oct 24 '23 11:10 Poltergeist-ix

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?

carsakiller avatar Oct 24 '23 15:10 carsakiller

I was wondering if it was possible to achieve this automatically, without adding an alias at all.

Poltergeist-ix avatar Oct 24 '23 15:10 Poltergeist-ix

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.

carsakiller avatar Oct 24 '23 15:10 carsakiller