autocompletion is done without file require()
Environment(环境)
| name | version |
|---|---|
| IDEA version | #IU-193.5662.53 |
| EmmyLua version | 1.3.1.136-IDEA182 |
| OS | Ubuntu 18.04 |
What are the steps to reproduce this issue?(重现步骤?)
- create two LUA files (
test.lua,func.lua) - write a function into
func.lua
function test()
print("test")
end
- Then open the test.lua file and notice, that the function
test()is being autocompleted.
What were you expecting to happen?(期望?)
The autocompletion for the function test() should only be shown, when the file, where the function is, is required. require("func.lua")
That is also how Lua works, when executing files. It will only now about files, that are included in the file.
This is correct behavior because you define your function in global scope. Add local keyword before the function declaration:
local function test()
print("test")
end
Require is doesn't matter because auto-completion don't know how you will use your code - is it standalone program or just a plugin which connects with other plugins from other program (which is not part of your project).
Is there a way to specify files from which it will look up the global scope ?
I'm currently using the EmmyLua plugin to help development of script that run using MoonSharp, and I know each file will have its own global scope.
However, I still need to have stuff global to be able to access it via MoonSharp.
I would like a way to make the EmmyLua plugin only look up the global scope of specific files ? Maybe the ones present in the “Lua additional sources root” configuration property ?
Is there a way to specify files from which it will look up the global scope ?
I'm currently using the EmmyLua plugin to help development of script that run using MoonSharp, and I know each file will have its own global scope.
However, I still need to have stuff global to be able to access it via MoonSharp.
I would like a way to make the EmmyLua plugin only look up the global scope of specific files ? Maybe the ones present in the “Lua additional sources root” configuration property ?
maybe ---@module [modulename] can help, However, this is a deprecated feature and is no longer maintained。 use like
---@module m1
aaa = 132
bbb = 12567
Seems to work, thanks @CppCXY !