EmmyLua / IntelliJ-EmmyLua

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

Type definitions / declare type using comment, not possible to make new globals? #468

Open LoganDark opened 2 years ago

LoganDark commented 2 years ago

Environment(环境)

name version
IDEA version [e.g. IC2018.2 EAP, CL2018.1.2] IntelliJ IDEA Ultimate 2021.2.3
EmmyLua version [e.g. v1.2.5] 1.3.6.224-IDEA213
OS [e.g. OSX 10.13.4, Windows 10] Windows 10 2004 build 19041.928 x86_64

I want to use EmmyLua for type checking / documentation / autocomplete when making OpenResty scripts. For that I want to add typings for all of the globals that are added, like ngx, udpsock, tcpsock, etc. But I don't know how to do so.

Looking at the annotations documentation I can't see any annotation that can be used to declare that a variable already exists. I can define it like local ngx = {} and then function ngx.say(...) after, like the Lua standard library, but I don't think that would be a global and it would also create side effects at runtime.

Is there any way to do this or is it a missing feature? Thanks

CppCXY commented 2 years ago

Define these variables in pure comment files, put them in the workspace or package them as zips introduced through the project strucure module. a simple openresty doc

LoganDark commented 2 years ago

Define these variables in pure comment files, put them in the workspace or package them as zips introduced through the project strucure module. a simple openresty doc

So make a file named something .def.lua, then define global variables & functions inside them with empty bodies?