diff options
author | fesily <fesil@foxmail.com> | 2023-05-25 15:52:12 +0800 |
---|---|---|
committer | fesily <fesil@foxmail.com> | 2023-05-25 15:52:12 +0800 |
commit | 622b1745973b409e16a9a0db5ed25a0548337e59 (patch) | |
tree | 8a44422de8a12481533705c471e3b0a86ae4fb2e /script/core | |
parent | 86916250304abc76b4b54486851f33ac12e64caf (diff) | |
download | lua-language-server-622b1745973b409e16a9a0db5ed25a0548337e59.zip |
command:add reloadFFIMeta
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/command/reloadFFIMeta.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/script/core/command/reloadFFIMeta.lua b/script/core/command/reloadFFIMeta.lua new file mode 100644 index 00000000..d00929ad --- /dev/null +++ b/script/core/command/reloadFFIMeta.lua @@ -0,0 +1,56 @@ +local config = require 'config' +local ws = require 'workspace' +local fs = require 'bee.filesystem' +local scope = require 'workspace.scope' +local SDBMHash = require 'SDBMHash' +local searchCode = require 'plugins.ffi.searchCode' +local cdefRerence = require 'plugins.ffi.cdefRerence' +local ffi = require 'plugins.ffi' + +local function createDir(uri) + local dir = scope.getScope(uri).uri or 'default' + local fileDir = fs.path(METAPATH) / ('%08x'):format(SDBMHash():hash(dir)) + if fs.exists(fileDir) then + return fileDir, true + end + fs.create_directories(fileDir) + return fileDir +end + +---@async +return function (uri) + if config.get(uri, 'Lua.runtime.version') ~= 'LuaJIT' then + return + end + + ws.awaitReady(uri) + + local fileDir, exists = createDir(uri) + + local refs = cdefRerence() + if not refs or #refs == 0 then + return + end + + for i, v in ipairs(refs) do + local target_uri = v.uri + local codes = searchCode(refs, target_uri) + if not codes then + return + end + + ffi.build_single(codes, fileDir, target_uri) + end + + if not exists then + local client = require 'client' + client.setConfig { + { + key = 'Lua.workspace.library', + action = 'add', + value = tostring(fileDir), + uri = uri, + } + } + end +end |