Open MikuAuahDark opened 1 year ago
See my response on the cross post
If the global variable love
and require("love")
is exactly the same, why the different diagnostic result? Shouldn't it be same, either giving inject-field warning or no warning at all on both?
Aside that, IMO having require("love")
makes it clear to user who reads the source code that in the specific file, LOVE is being used.
If the global variable love and require("love") is exactly the same, why the different diagnostic result?
It seems that you have configured your project to use the love2d
meta definition as library, i.e. in the .luarc.json
you may have setup something like this:
"workspace.library": [
"${3rd}/love2d/library"
]
=> this will include the built-in definition files for love2d
https://github.com/LuaCATS/love2d/blob/dad72a7eae31f35bf4c6529e5b81f6187b5b7377/library/love.lua
love = {}
as a global variable with a ---@class love
annotation, and returns it at the bottominject-field
diagnostic is disabled on global variablelocal love = require "love"
, it becomes a local variable with ---@type love
(as returned by aforementioned meta definition file)
=> inject-field
diagnostic is triggeredIMO having require("love") makes it clear to user who reads the source code that in the specific file, LOVE is being used.
If you really wants to write require("love")
in the file, I suggest writing it as:
love = love or require("love")
function love.load() -- no more warning now
end
=> this makes use of the fact that inject-field
diagnostic is disabled on global variable 😄
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Diagnostics/Syntax Checking, Libraries
Expected Behaviour
This should be clean.
Actual Behaviour
Reproduction steps
main.lua
with content above.Additional Notes
LOVE addon
@class
is not defined with(exact)
.Log File
file_d%3A_Data_Development_love-11.3-win64_inochi2d.log