IntelliJ-EmmyLua icon indicating copy to clipboard operation
IntelliJ-EmmyLua copied to clipboard

autocompletion is done without file require()

Open knoxfighter opened this issue 5 years ago • 4 comments

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?(重现步骤?)

  1. create two LUA files (test.lua , func.lua)
  2. write a function into func.lua
function test()
    print("test")
end
  1. 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.

knoxfighter avatar Jan 06 '20 16:01 knoxfighter

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).

winterwolf avatar Jan 30 '20 15:01 winterwolf

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 ?

LelouBil avatar Jan 13 '22 21:01 LelouBil

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



CppCXY avatar Jan 14 '22 02:01 CppCXY

Seems to work, thanks @CppCXY !

LelouBil avatar Jan 14 '22 08:01 LelouBil