EmmyLua / IntelliJ-EmmyLua

Lua IDE/Debugger Plugin for IntelliJ IDEA
https://emmylua.github.io
Apache License 2.0
1.74k stars 293 forks source link

How to document named arguments (tables) #425

Closed arnoson closed 3 years ago

arnoson commented 3 years ago

Environment(环境)

name version
OS Windows 10

Is there any way to document named arguments that I haven't found yet? What im looking for is to document something like this:

function test(args)
  print(args.arg1)
  print(args.arg2)
end

test{ arg1 = 10, arg2 = "somestring" }

I guess a notation like this would be great:

---@param args table{ arg1: number, arg2: string }
function test(args) end
galsjel commented 3 years ago

I suppose you would define a class and give it the fields of the arguments you desire.

---@class MyArgs
---@field arg1 number
---@field arg2 string

---@param args MyArgs
function test(args)
    print(args.arg1)
    print(args.arg2)
end

test { arg1 = 10, arg2 = "somestring" }
CppCXY commented 3 years ago

---@param args {arg1: number, arg2: string} function test(args) end

arnoson commented 3 years ago

Thanks for your quick replies!

I use this lua plugin for vscode and both techniques don't seem to work properly, although the plugin uses EmmyLua.

Here the detailed param Information is not displayed, only the type of the MyArgs class:

screenshot-1

And here the syntax is not recognized:

screenshot-2

So I guess the second solution should work great if another part of the plugin wasn't interfering. I will try out to use EmmyLua directly to see if it solves the problem.

arnoson commented 3 years ago

There is already an issue filed for the plugin im using: sumneko/lua-language-server#511 So I'll close this issue as it doesn't seem to be related to EmmyLua. Thanks for your help :)