Class not recognized when not opening
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?
Type Checking
Expected Behaviour
AttachNode is recognized as global and class.
Actual Behaviour
https://github.com/user-attachments/assets/d16ea267-6734-40a8-973c-13f9a6b46b32
Reproduction steps
I've no idea, maybe this is relative to my project.
Additional Notes
vscode settings are set to
"Lua.workspace.maxPreload": 500000,
"Lua.workspace.preloadFileSize": 500000,
Log File
From my own experience, this is usually due to the files being ignored😕 => the classes defined within that file will only be processed when it is opened, and will disappear after closing that file
- The files in question are under the path
Assets/Res/ship/build/* - Judging from the log file, I found that you have add
["build/"] = true,in yourfiles.excludevscode settings - By full searching LuaLS's code base, seems the server will utilize this settings to ignore those paths as well: https://github.com/LuaLS/lua-language-server/blob/606ea70d3608bf9cec8b007b7aa499dc94ffb02e/script/workspace/workspace.lua#L134-L146
- I know that a
build/pattern should not matchAssets/Res/ship/build/*, because the pattern isn't prefixed with a**/. But maybe the pattern matcher of LuaLS doesn't work this way, and it considers that abuild/will matchAssets/Res/ship/build/*🤦♂ 🐛
minimal reproduction env
- create the following file structure
test/
├─ lib/
│ ├─ build/
│ │ ├─ mylib.lua
├─ .vscode/
│ ├─ settings.json
main.lua
- .vscode/settings.json
{
"files.exclude": {
"build/": true
}
}
- lib/build/mylib.lua
---@class mylib
- main.lua
---@type mylib # --> Undefined type or alias `mylib`.
- only if I open
lib/build/mylib.luaor remove thefiles.excludesettings, themylibclass type will be defined
I have no idea how this can be fixed ...
-
files.excludeuses glob pattern - while
.gitignoreuses gitignore pattern - one of the main differences is that a single
build/matches any folder prefix in gitignore style, while it only matchesbuild/under project root in glob style
Although LuaLS's glob library has both matcheres:
https://github.com/LuaLS/lua-language-server/blob/606ea70d3608bf9cec8b007b7aa499dc94ffb02e/script/glob/init.lua#L1-L4
It only uses 1 of the matcher types to process both files.excludes and .gitignore ...
https://github.com/LuaLS/lua-language-server/blob/606ea70d3608bf9cec8b007b7aa499dc94ffb02e/script/workspace/workspace.lua#L189-L196
☹ ☹ ☹
@tomlau10 then it is a design mistake... The correct design could be:
- There's only one global matcher.
- The global matcher contains two sub-matcher: the gitignore matcher, and vscode config matcher. Sub-matchers are created from its own pattern. (so
build/won't be in gitignore matcher) - for each input, test if it is excluded/included by the two sub-matcher.
- compose the result and return. (rule can be: exclude when any exclude, include when any include, and default to include) So typically we need to wrap it into a higher level matcher.
then it is a design mistake
You're right.
I am not maintainer of this project, just a contributor, and I am not very familiar with this part of the code base.
Hopefully they can be aware of this issue, and have a better implementation in v4.0 🙂
(they are doing a big refactor currently)
@tomlau10 wow they are doing refactor? Then I should wait and hear though.
yeah~ it's been a long time though 😂 related announcement: https://github.com/LuaLS/lua-language-server/discussions/2366
and there is a 4.0.0 branch under construction 👀
https://github.com/LuaLS/lua-language-server/tree/4.0.0