IntelliJ-EmmyLua
IntelliJ-EmmyLua copied to clipboard
'Return value assumption' doesn't work until you open the file
Environment(环境)
name | version |
---|---|
IDEA version | 2020.2.4 |
EmmyLua version | 1.3.4 |
OS | MacOS 10.15.7 |
What are the steps to reproduce this issue?(重现步骤?)
myClassBuilder.lua
local t = {}
function t:new()
local myClass = {} ---@class myClass
return myClass
end
return t
mySubClassBuilder.lua
local t = {}
local myClassBuilder = require("myClassBuilder")
function t:new()
local mySubClass = myClassBuilder:new()
return mySubClass
end
return t
What happens?(出现什么问题?)
Inspecting the mySubClass
variable without opening the myClassBuilder.lua doesn't know it is of the myClass
type
After opening the myClassBuilder.lua mySubClass
variable does indicate its type is myClass
What were you expecting to happen?(期望?)
I would expect mySubClass
to always know what type it is. Or if there are performance reasons why this is happening I would like to be able to force index all files.
Any other comments?(其它说明)
Using a ---@return myClass
Intellij does know the type from the start, but since I have more than 300 of these type of Builders I would like to prevent every builder to require a @return definition when it already has the ---@class definition on the table which is being returned.
Upon further investigation it seems even with a @return definition EmmyLua is just roughly estimating what local mySubClass
is. (local t|local myClassBuilder|myClass)
If the @return of myClassBuilder:new() is defined as myClass
, shouldn't it be sure about the type of local mySubClass
?
Using idea project structure > module > mark as source, you can get a better experience
I did already have that configured, so it changes nothing in this case. I've attached a sample project where I created a new Lua project with Intellij and included the examples mentioned in the issue description.
When you open Intellij with only mySubClassBuilder.lua open, hovering over myClassBuilder:new
says it is a function with a return of void
. After clicking on new
it will open myClassBuilder whereafter hovering over myClassBuilder:new
will indicate its a function with a return of myClass
. But still, typing mySubClass:
will suggest :new()
because it is not sure about the type of the mySubClass
variable