-
-
Notifications
You must be signed in to change notification settings - Fork 350
3rd-party libraries annotation is not automatically loaded #940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
My Also you must use the |
Wait! I thought you were using this line to avoid the error. Otherwise it is not surprising because there is no library named love in your project. You need to explicitly specify the type: ---@type love
local love = require("love") |
If you didn't touch any of that |
Yes, you're right, it is strange behavior. But, as I said, it is observed only in vscode and only if you don't explicitly specify You could definitely call this a bug if your project contained files with the full love-api descriptions and the client didn't recognize them, but since the api is located outside your project, it's not surprising. |
Interesting. This seems to be the exact same behavior I described in #932. As to whether its an LSP client problem or a lua-language-server quirk, I'm sympathetic to both views (mostly because I don't feel I have sufficient understanding of either one 🙃). As a user of lua-language-server and a common LSP client (neovim), here is what I would naturally expect to happen:
This seems like a logical and reasonable expectation to me, but it's possible I'm missing something. Re: @lua-rocks comment:
I agree, but I do not own all codebases that I work on, and some of them do not use/allow EmmyLua style annotations. |
In such cases I keep this code in a directory which is added to exceptions so that neither luacheck nor lsp tries to scan them. I require these libraries in a separate directory and I write the annotations there:
"Lua.workspace.ignoreDir": [".**", "git"] require ---@class lib.any.inspect-options:table
---@field depth integer? sets the maximum depth that will be printed out
---@field newline string? add custom newline each level of a table
---@field indent string? add an indent each level of a table
---@field process fun(...): any? additional handler
---Returns any lua variable in human-readable format.
---@alias lib.any.inspect fun(variable:any, options: lib.any.inspect-options): string
---@type lib.any.inspect
local inspect = require("git.inspect.inspect")
return inspect https://github.com/lua-rocks/love-template/tree/main/git |
Sorry for the late reply, I just finished the Chinese New Year holiday. |
I tried it and now everything works as intended, thanks. |
Describe the bug
On opening new directory (project) in VSCode, 3rd-party library annotation is not automatically loaded. In this case, it's LOVE library.
Any code (always
main.lua
in my case) that haslocal love = require("love")
doesn't load the LOVE annotation at first, but if therequire("love")
is retyped, the annotation is back. This is bit annoying to do everytime when opening my projects.To Reproduce
Reproducing this seems require a slightly larger workspace (and sadly mines are private), but thankfully my own livesim2 project can be used to reproduce this. You just need to tell VSCode to open the project to reproduce (but ensure the project is detected as LOVE project first). I've attached the log for this project.
Unfortunately, an empty project consist of main.lua that only contain
local love = require("love")
(which has been detected as LOVE project) doesn't seem get affected by this issue. I also have attached the log for this empty project too in case you need to compare the logs between.Expected behavior
LOVE library annotation should be loaded automatically on load, like the empty project described above.
Screenshots

Environment (please complete the following information):
Additional context
I slightly have no idea when this start to happend, as it seems it happends overnight to me.
I also have
${3rd}/love2d/library
in myLua.workspace.library
workspace setting for both projects, so this can be ruled out.Provide logs
"livesim2" project log
empty project log
The text was updated successfully, but these errors were encountered: