lua-language-server
lua-language-server copied to clipboard
require("ffi") returning unknown
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
MacOS
What is the issue affecting?
Type Checking, Completion, Libraries
Expected Behaviour
Actual Behaviour
Reproduction steps
local ffi = require("ffi")
Additional Notes
No response
Log File
[17:01:26.978][info] [#0:/Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/main.lua:65]: Lua Lsp startup, root: /Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server
[17:01:26.978][info] [#0:/Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/main.lua:66]: ROOT: /Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server
[17:01:26.978][info] [#0:/Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/main.lua:67]: LOGPATH: /Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/log
[17:01:26.978][info] [#0:/Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/main.lua:68]: METAPATH: /Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/meta
[17:01:26.979][info] [#0:/Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/main.lua:69]: VERSION: 3.5.6
[17:01:27.012][info] [#0:script/service/service.lua:141]:
========= Medical Examination Report =========
--------------- Memory ---------------
Total: 1.489 MB
# 00 : 1.489 MB
# 01 : 0.000 MB
# 02 : 0.000 MB
# 03 : 0.000 MB
# 04 : 0.000 MB
--------------- Coroutine ---------------
Total: 0
Running: 0
Suspended: 0
Normal: 0
Dead: 0
--------------- Cache ---------------
Total: 1
Dead: 0
--------------- RPC ---------------
Holdon: 0
Waiting: 0
==============================================
[17:01:27.023][info] [#0:script/language.lua:137]: VSC language: en-us
[17:01:27.023][info] [#0:script/language.lua:138]: LS language: en-us
[17:01:27.023][info] [#0:script/workspace/workspace.lua:38]: Workspace init root: file:///Users/frityet/Documents/LuaUITest
[17:01:27.023][info] [#0:script/workspace/workspace.lua:42]: Log path: /Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/log/file_Users_frityet_Documents_LuaUITest.log
[17:01:27.025][info] [#0:script/workspace/workspace.lua:51]: Workspace create: file:///Users/frityet/Documents/LuaUITest
[17:01:27.335][info] [#0:script/provider/provider.lua:41]: Load config from client file:///Users/frityet/Documents/LuaUITest
[17:01:27.336][info] [#0:script/provider/provider.lua:42]: {
Lua = {
IntelliSense = {
traceBeSetted = true,
traceFieldInject = true,
traceLocalSet = true,
traceReturn = true
},
color = {
mode = "SemanticEnhanced"
},
completion = {
autoRequire = true,
callSnippet = "Replace",
displayContext = 0,
enable = true,
keywordSnippet = "Replace",
postfix = "@",
requireSeparator = ".",
showParams = true,
showWord = "Fallback",
workspaceWord = true
},
diagnostics = {
disable = {},
disableScheme = { "git" },
enable = true,
globals = {},
groupFileStatus = {},
groupSeverity = {},
ignoredFiles = "Enable",
libraryFiles = "Opened",
neededFileStatus = {},
severity = {},
unusedLocalExclude = {},
workspaceDelay = 3000,
workspaceRate = 100
},
format = {
defaultConfig = {},
enable = true
},
hint = {
arrayIndex = "Enable",
await = true,
enable = false,
paramName = "All",
paramType = true,
semicolon = "SameLine",
setType = true
},
hover = {
enable = true,
enumsLimit = 5,
expandAlias = true,
previewFields = 50,
viewNumber = true,
viewString = true,
viewStringMax = 1000
},
misc = {
parameters = {}
},
runtime = {
builtin = {},
fileEncoding = "utf8",
meta = "${version} ${language} ${encoding}",
nonstandardSymbol = {},
path = { "?.lua", "?/init.lua", "?/?.lua", "/usr/local/share/lua/?/?.lua" },
pathStrict = false,
plugin = "",
pluginArgs = {},
special = {
['"ffi.load"'] = "require"
},
unicodeName = false,
version = "Lua 5.4"
},
semantic = {
annotation = true,
enable = true,
keyword = false,
variable = true
},
signatureHelp = {
enable = true
},
spell = {
dict = {}
},
telemetry = {
enable = true
},
type = {
castNumberToInteger = true,
weakNilCheck = false,
weakUnionCheck = false
},
typeFormat = {
config = {}
},
window = {
progressBar = true,
statusBar = true
},
workspace = {
checkThirdParty = true,
ignoreDir = { ".vscode" },
ignoreSubmodules = true,
library = { "/usr/local/share/lua/", "/usr/local/lib/lua/", "?/?.so", "?.so", "/Users/frityet/Documents/libCraftOS/" },
maxPreload = 5000,
preloadFileSize = 500,
supportScheme = { "file", "untitled", "git" },
useGitIgnore = true,
userThirdParty = {}
}
},
["editor.acceptSuggestionOnEnter"] = "on",
["editor.semanticHighlighting.enabled"] = true,
["files.associations"] = {
["*.asm"] = "nasm",
["*.h"] = "c",
["*.inc"] = "nasm",
["*.lua"] = "lua",
["*.mpp"] = "cpp",
["*.rockspec"] = "lua"
},
["files.exclude"] = {
["**/.DS_Store"] = true,
["**/.git"] = true,
["**/.hg"] = true,
["**/.svn"] = true,
["**/CVS"] = true,
["**/Thumbs.db"] = true
}
}
[17:01:27.336][info] [#0:script/provider/provider.lua:48]: Load config from .luarc.json/.luarc.jsonc file:///Users/frityet/Documents/LuaUITest
[17:01:27.336][info] [#0:script/provider/provider.lua:49]: {
["diagnostics.groupSeverity"] = {
ambiguity = "Error",
await = "Error",
codestyle = "Error",
duplicate = "Error",
global = "Error",
luadoc = "Error",
redefined = "Error",
strict = "Error",
strong = "Error",
["type-check"] = "Error",
unbalanced = "Error"
},
["runtime.path"] = { "?.lua", "?/init.lua" },
["runtime.pathStrict"] = true,
["runtime.special"] = {
<metatable> = {}
},
["runtime.version"] = "LuaJIT",
["workspace.ignoreDir"] = {},
["workspace.useGitIgnore"] = false
}
[17:01:27.439][info] [#0:script/provider/provider.lua:56]: Load config from client fallback
[17:01:27.441][info] [#0:script/provider/provider.lua:57]: {
Lua = {
IntelliSense = {
traceBeSetted = true,
traceFieldInject = true,
traceLocalSet = true,
traceReturn = true
},
color = {
mode = "SemanticEnhanced"
},
completion = {
autoRequire = true,
callSnippet = "Replace",
displayContext = 0,
enable = true,
keywordSnippet = "Replace",
postfix = "@",
requireSeparator = ".",
showParams = true,
showWord = "Fallback",
workspaceWord = true
},
diagnostics = {
disable = {},
disableScheme = { "git" },
enable = true,
globals = {},
groupFileStatus = {},
groupSeverity = {},
ignoredFiles = "Enable",
libraryFiles = "Opened",
neededFileStatus = {},
severity = {},
unusedLocalExclude = {},
workspaceDelay = 3000,
workspaceRate = 100
},
format = {
defaultConfig = {},
enable = true
},
hint = {
arrayIndex = "Enable",
await = true,
enable = false,
paramName = "All",
paramType = true,
semicolon = "SameLine",
setType = true
},
hover = {
enable = true,
enumsLimit = 5,
expandAlias = true,
previewFields = 50,
viewNumber = true,
viewString = true,
viewStringMax = 1000
},
misc = {
parameters = {}
},
runtime = {
builtin = {},
fileEncoding = "utf8",
meta = "${version} ${language} ${encoding}",
nonstandardSymbol = {},
path = { "?.lua", "?/init.lua", "?/?.lua", "/usr/local/share/lua/?/?.lua" },
pathStrict = false,
plugin = "",
pluginArgs = {},
special = {
['"ffi.load"'] = "require"
},
unicodeName = false,
version = "Lua 5.4"
},
semantic = {
annotation = true,
enable = true,
keyword = false,
variable = true
},
signatureHelp = {
enable = true
},
spell = {
dict = {}
},
telemetry = {
enable = true
},
type = {
castNumberToInteger = true,
weakNilCheck = false,
weakUnionCheck = false
},
typeFormat = {
config = {}
},
window = {
progressBar = true,
statusBar = true
},
workspace = {
checkThirdParty = true,
ignoreDir = { ".vscode" },
ignoreSubmodules = true,
library = { "/usr/local/share/lua/", "/usr/local/lib/lua/", "?/?.so", "?.so", "/Users/frityet/Documents/libCraftOS/" },
maxPreload = 5000,
preloadFileSize = 500,
supportScheme = { "file", "untitled", "git" },
useGitIgnore = true,
userThirdParty = {}
}
},
["editor.acceptSuggestionOnEnter"] = "on",
["editor.semanticHighlighting.enabled"] = true,
["files.associations"] = {
["*.asm"] = "nasm",
["*.h"] = "c",
["*.inc"] = "nasm",
["*.lua"] = "lua",
["*.mpp"] = "cpp",
["*.rockspec"] = "lua"
},
["files.exclude"] = {
["**/.DS_Store"] = true,
["**/.git"] = true,
["**/.hg"] = true,
["**/.svn"] = true,
["**/CVS"] = true,
["**/Thumbs.db"] = true
}
}
[17:01:27.442][info] [#0:script/provider/completion.lua:43]: Enable completion.
[17:01:27.544][info] [#0:script/library.lua:207]: Init builtin library at: file:///Users/frityet/Documents/LuaUITest
[17:01:27.566][info] [#0:script/plugin.lua:86]: plugin path: /Users/frityet/Documents/LuaUITest
[17:01:27.567][warn] [#0:script/plugin.lua:101]: plugin not found: /Users/frityet/Documents/LuaUITest
[17:01:27.567][info] [#0:script/library.lua:207]: Init builtin library at: nil
[17:01:27.586][info] [#0:script/workspace/workspace.lua:305]: Preload start: file:///Users/frityet/Documents/LuaUITest
[17:01:27.589][info] [#0:script/workspace/workspace.lua:311]: Scan files at: file:///Users/frityet/Documents/LuaUITest
[17:01:27.589][info] [#0:script/workspace/workspace.lua:305]: Preload start: <fallback>
[17:01:27.593][info] [#0:script/workspace/workspace.lua:328]: Scan library at: file:///usr/local/lib/lua
[17:01:27.599][info] [#0:script/workspace/workspace.lua:328]: Scan library at: file:///usr/local/share/lua
[17:01:27.599][info] [#0:script/workspace/workspace.lua:328]: Scan library at: file:///Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/meta/Lua%205.4%20en-us%20utf8
[17:01:27.600][info] [#0:script/workspace/workspace.lua:328]: Scan library at: file:///usr/local/lib/lua
[17:01:27.603][info] [#0:script/workspace/workspace.lua:328]: Scan library at: file:///usr/local/share/lua
[17:01:27.603][info] [#0:script/workspace/workspace.lua:328]: Scan library at: file:///Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/meta/LuaJIT%20en-us%20utf8
[17:01:27.606][info] [#0:script/workspace/workspace.lua:328]: Scan library at: file:///Users/frityet/Documents/libCraftOS
[17:01:27.610][info] [#0:script/workspace/workspace.lua:328]: Scan library at: file:///Users/frityet/Documents/libCraftOS
[17:01:28.438][info] [#0:script/workspace/workspace.lua:348]: Found 20 files at: <fallback>
[17:01:28.439][info] [#0:script/workspace/loading.lua:153]: Load files from disk: <fallback>
[17:01:28.439][info] [#0:script/workspace/workspace.lua:348]: Found 29 files at: file:///Users/frityet/Documents/LuaUITest
[17:01:28.439][info] [#0:script/workspace/loading.lua:153]: Load files from disk: file:///Users/frityet/Documents/LuaUITest
[17:01:28.888][info] [#0:script/workspace/loading.lua:165]: Loaded files takes [0.145] sec: <fallback>
[17:01:28.888][info] [#0:script/workspace/loading.lua:174]: Compile files takes [0.000] sec: <fallback>
[17:01:28.888][info] [#0:script/workspace/loading.lua:175]: Loaded finish: <fallback>
[17:01:28.888][info] [#0:script/workspace/workspace.lua:350]: Preload finish at: <fallback>
[17:01:28.902][info] [#0:script/workspace/loading.lua:165]: Loaded files takes [0.157] sec: file:///Users/frityet/Documents/LuaUITest
[17:01:28.902][info] [#0:script/workspace/loading.lua:174]: Compile files takes [0.000] sec: file:///Users/frityet/Documents/LuaUITest
[17:01:28.902][info] [#0:script/workspace/loading.lua:175]: Loaded finish: file:///Users/frityet/Documents/LuaUITest
[17:01:28.902][info] [#0:script/workspace/workspace.lua:350]: Preload finish at: file:///Users/frityet/Documents/LuaUITest
[17:01:28.921][info] [#0:script/provider/diagnostic.lua:486]: Diagnostics scope [<fallback>], files count:[35]
[17:01:28.921][info] [#0:script/provider/diagnostic.lua:486]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest], files count:[24]
[17:01:28.953][info] [#0:script/provider/diagnostic.lua:503]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest] finished, takes [0.029] sec.
[17:01:28.953][info] [#0:script/provider/diagnostic.lua:503]: Diagnostics scope [<fallback>] finished, takes [0.030] sec.
[17:01:39.060][info] [#0:script/provider/diagnostic.lua:486]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest], files count:[24]
[17:01:39.066][info] [#0:script/provider/diagnostic.lua:503]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest] finished, takes [0.006] sec.
[17:02:14.451][info] [#0:script/provider/diagnostic.lua:486]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest], files count:[24]
[17:02:14.456][info] [#0:script/provider/diagnostic.lua:503]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest] finished, takes [0.005] sec.
[17:02:14.875][info] [#0:script/provider/diagnostic.lua:486]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest], files count:[24]
[17:02:14.881][info] [#0:script/provider/diagnostic.lua:503]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest] finished, takes [0.006] sec.
[17:02:16.637][info] [#0:script/provider/diagnostic.lua:486]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest], files count:[24]
[17:02:16.643][info] [#0:script/provider/diagnostic.lua:503]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest] finished, takes [0.005] sec.
[17:02:18.242][info] [#0:script/provider/diagnostic.lua:486]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest], files count:[24]
[17:02:18.248][info] [#0:script/provider/diagnostic.lua:503]: Diagnostics scope [file:///Users/frityet/Documents/LuaUITest] finished, takes [0.006] sec.
[17:05:49.714][info] [#0:script/provider/diagnostic.lua:486]: Diagnostics scope [<fallback>], files count:[15]
[17:05:49.715][info] [#0:script/provider/diagnostic.lua:503]: Diagnostics scope [<fallback>] finished, takes [0.001] sec.
[17:05:51.377][info] [#0:script/provider/diagnostic.lua:160]: clearDiagnostics file:///Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/log/middleScript.lua
[17:05:56.820][info] [#0:script/provider/diagnostic.lua:486]: Diagnostics scope [<fallback>], files count:[15]
[17:05:56.820][info] [#0:script/provider/diagnostic.lua:503]: Diagnostics scope [<fallback>] finished, takes [0.001] sec.
[17:01:26.978][info] [#0:/Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/main.lua:65]: Lua Lsp startup, root: /Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server
[17:01:26.978][info] [#0:/Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/main.lua:66]: ROOT: /Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server
[17:01:26.978][info] [#0:/Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/main.lua:67]: LOGPATH: /Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/log
[17:01:26.978][info] [#0:/Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/main.lua:68]: METAPATH: /Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/meta
[17:01:26.979][info] [#0:/Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/main.lua:69]: VERSION: 3.5.6
[17:01:27.012][info] [#0:script/service/service.lua:141]:
========= Medical Examination Report =========
--------------- Memory ---------------
Total: 1.489 MB
# 00 : 1.489 MB
# 01 : 0.000 MB
# 02 : 0.000 MB
# 03 : 0.000 MB
# 04 : 0.000 MB
--------------- Coroutine ---------------
Total: 0
Running: 0
Suspended: 0
Normal: 0
Dead: 0
--------------- Cache ---------------
Total: 1
Dead: 0
--------------- RPC ---------------
Holdon: 0
Waiting: 0
==============================================
[17:01:27.023][info] [#0:script/language.lua:137]: VSC language: en-us
[17:01:27.023][info] [#0:script/language.lua:138]: LS language: en-us
[17:01:27.023][info] [#0:script/workspace/workspace.lua:38]: Workspace init root: file:///Users/frityet/Documents/LuaUITest
[17:01:27.023][info] [#0:script/workspace/workspace.lua:42]: Log path: /Users/frityet/.vscode/extensions/sumneko.lua-3.5.6-darwin-x64/server/log/file_Users_frityet_Documents_LuaUITest.log
Hello 👋
The server does not have definitions for ffi built-in currently. I also don't see any reference to definition files for ffi in your log file.
Without definition files, the server is unable to provide type checking, completion, hover, etc. for those undefined values.
Definitions for the ffi module are included with the server, but they are not enabled unless using luajit. Your logs show this:
version = "Lua 5.4"
Try switching that to LuaJIT and let us know if that does the trick.
Right, my bad, completely glossed over that 🥴
Definitions for the
ffimodule are included with the server, but they are not enabled unless using luajit. Your logs show this:version = "Lua 5.4"
Try switching that to
LuaJITand let us know if that does the trick.
It is, in the .luarc.json as shown in the first screenshot
In my case, this can be simply solved by changing Lua Version in Preferences.

In my case, this can be simply solved by changing Lua Version in Preferences.
I am using .luarc.json to do that
@Frityet has your issue been resolved?
What I'm seeing by looking at the logs is that the lua runtime version is defined in two different ways here. One is nested:
{
"Lua": {
"runtime": {
"version": "...",
}
}
}
and one is not:
{
"runtime.version": "..."
}
I don't use .luarc.json or the vscode plugin so I dunno how they are supposed to work with regards to settings management/serialization, but I'm pretty sure that's source of the problem here.
@Frityet has your issue been resolved?
Sometimes it works, other times it doenst
I think @flrgh might be onto something here. I was able to reproduce by doing the following:
.vscode/settings.json
"Lua.runtime.version": "Lua 5.4"
.luarc.json
{
"runtime": { "version": "LuaJIT" }
}
test.lua
local ffi = require("ffi")
ffi is unknown... until I refresh the window, then it loads. Seems like when a change is detected in .luarc.json it isn't diagnosing the workspace correctly.
ffiis unknown... until I refresh the window, then it loads. Seems like when a change is detected in.luarc.jsonit isn't diagnosing the workspace correctly.

I can not reproduce it.
Now I am questioning everything 😵💫. I was able to reproduce it reliably:
- Start VS Code
- Change to
Lua 5.4in.luarc.json ffiis unknown- Change to
LuaJITin.luarc.json ffiis unknown- Reload VS Code
ffiis known
Now I do it and it works perfectly. I also tried adding in another json file to see if that was messing with the file watching and it had no effect.
@carsakiller Are you testing in multi-workspace?
No, but I was on Ubuntu initially. Works in Windows as expected. Testing again in WSL results in the same unexpected behaviour, although add in another step of reloading VS Code in order for ffi to become unknown when it is already known??
Reporter is on macOS, so maybe this is a Unix issue with file watching? Going to jump into a very basic WSL workspace and watch the output of the extension...
Hmm, I thought I remembered seeing a message in the Output window when a change was detected in .luarc.json but I think that is only when there is a syntax error in the file.
Not able to reproduce in a very simple WSL workspace. However, I am still able to reproduce in WSL when in a workspace with many unrelated TS/YAML/JSON files and some node_modules. That is hardly a normal use case, though. Maybe too many files for the language server... but I thought it would ignore all non-Lua files?

Try wait few seconds after modification?
The configuration files are behaving very weirdly. Setting the status bar state doesn't seem to work in .luarc.json, and setting it in settings.json is forcing ffi to be applied? 🥴

The configuration files are behaving very weirdly. Setting the status bar state doesn't seem to work in
.luarc.json, and setting it insettings.jsonis forcingffito be applied? 🥴
Watching settings.json is provided by VSCode, watching .luarc.json is provided by this server.
I will check the filewatching in WSL/Linux.
The configuration files are behaving very weirdly. Setting the status bar state doesn't seem to work in
.luarc.json, and setting it insettings.jsonis forcingffito be applied? 🥴
window.statusBar should be default to true, that means when your comment out all the settings, the status bar should be displayed.
Can you check if there are other setting files in your workspace?
The configuration files are behaving very weirdly. Setting the status bar state doesn't seem to work in
.luarc.json, and setting it insettings.jsonis forcingffito be applied? 🥴
window.statusBarshould be default totrue, that means when your comment out all the settings, the status bar should be displayed. Can you check if there are other setting files in your workspace?
none
Can you check if there are other setting files in your workspace?
My user settings disable the status bar, but .luarc.json should overwrite it, no?
If the problem persists, please provide your operation description and corresponding log