diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/plugin.lua | 1 | ||||
-rw-r--r-- | script/plugins/ffi/c-parser/c99.lua (renamed from script/LuaJIT/c-parser/c99.lua) | 2 | ||||
-rw-r--r-- | script/plugins/ffi/c-parser/cdefines.lua (renamed from script/LuaJIT/c-parser/cdefines.lua) | 6 | ||||
-rw-r--r-- | script/plugins/ffi/c-parser/cdriver.lua (renamed from script/LuaJIT/c-parser/cdriver.lua) | 8 | ||||
-rw-r--r-- | script/plugins/ffi/c-parser/cpp.lua (renamed from script/LuaJIT/c-parser/cpp.lua) | 4 | ||||
-rw-r--r-- | script/plugins/ffi/c-parser/ctypes.lua (renamed from script/LuaJIT/c-parser/ctypes.lua) | 2 | ||||
-rw-r--r-- | script/plugins/ffi/c-parser/typed.lua (renamed from script/LuaJIT/c-parser/typed.lua) | 0 | ||||
-rw-r--r-- | script/plugins/ffi/cdefRerence.lua (renamed from script/LuaJIT/cdefRerence.lua) | 0 | ||||
-rw-r--r-- | script/plugins/ffi/init.lua (renamed from script/LuaJIT/init.lua) | 63 | ||||
-rw-r--r-- | script/plugins/ffi/searchCode.lua (renamed from script/LuaJIT/searchCode.lua) | 0 | ||||
-rw-r--r-- | script/plugins/init.lua | 1 |
11 files changed, 66 insertions, 21 deletions
diff --git a/script/plugin.lua b/script/plugin.lua index 870b68b6..7afcbc0a 100644 --- a/script/plugin.lua +++ b/script/plugin.lua @@ -6,6 +6,7 @@ local await = require 'await' local scope = require 'workspace.scope' local ws = require 'workspace' local fs = require 'bee.filesystem' +require 'plugins' ---@class plugin local m = {} diff --git a/script/LuaJIT/c-parser/c99.lua b/script/plugins/ffi/c-parser/c99.lua index 12ccee93..9735afa2 100644 --- a/script/LuaJIT/c-parser/c99.lua +++ b/script/plugins/ffi/c-parser/c99.lua @@ -28,7 +28,7 @@ local c99 = {} local re = require("parser.relabel") -local typed = require("LuaJIT.c-parser.typed") +local typed = require("plugins.ffi.c-parser.typed") local defs = {} diff --git a/script/LuaJIT/c-parser/cdefines.lua b/script/plugins/ffi/c-parser/cdefines.lua index b3a3bd24..55065f2d 100644 --- a/script/LuaJIT/c-parser/cdefines.lua +++ b/script/plugins/ffi/c-parser/cdefines.lua @@ -1,9 +1,9 @@ local cdefines = {} -local c99 = require("LuaJIT.c-parser.c99") -local cpp = require("LuaJIT.c-parser.cpp") -local typed = require("LuaJIT.c-parser.typed") +local c99 = require("plugins.ffi.c-parser.c99") +local cpp = require("plugins.ffi.c-parser.cpp") +local typed = require("plugins.ffi.c-parser.typed") local function add_type(lst, name, typ) lst[name] = typ diff --git a/script/LuaJIT/c-parser/cdriver.lua b/script/plugins/ffi/c-parser/cdriver.lua index c979f6eb..ab48d01a 100644 --- a/script/LuaJIT/c-parser/cdriver.lua +++ b/script/plugins/ffi/c-parser/cdriver.lua @@ -1,9 +1,9 @@ local cdriver = {} -local cpp = require("LuaJIT.c-parser.cpp") -local c99 = require("LuaJIT.c-parser.c99") -local ctypes = require("LuaJIT.c-parser.ctypes") -local cdefines = require("LuaJIT.c-parser.cdefines") +local cpp = require("plugins.ffi.c-parser.cpp") +local c99 = require("plugins.ffi.c-parser.c99") +local ctypes = require("plugins.ffi.c-parser.ctypes") +local cdefines = require("plugins.ffi.c-parser.cdefines") function cdriver.process_file(filename) local ctx, err = cpp.parse_file(filename) diff --git a/script/LuaJIT/c-parser/cpp.lua b/script/plugins/ffi/c-parser/cpp.lua index fbf1e717..f885e724 100644 --- a/script/LuaJIT/c-parser/cpp.lua +++ b/script/plugins/ffi/c-parser/cpp.lua @@ -1,8 +1,8 @@ local cpp = {} -local typed = require("LuaJIT.c-parser.typed") -local c99 = require("LuaJIT.c-parser.c99") +local typed = require("plugins.ffi.c-parser.typed") +local c99 = require("plugins.ffi.c-parser.c99") local SEP = package.config:sub(1,1) diff --git a/script/LuaJIT/c-parser/ctypes.lua b/script/plugins/ffi/c-parser/ctypes.lua index babb2cbb..72d19ab9 100644 --- a/script/LuaJIT/c-parser/ctypes.lua +++ b/script/plugins/ffi/c-parser/ctypes.lua @@ -2,7 +2,7 @@ local ctypes = { TESTMODE = false } local inspect = require("inspect") local utility = require 'utility' -local typed = require("LuaJIT.c-parser.typed") +local typed = require("plugins.ffi.c-parser.typed") local equal_declarations diff --git a/script/LuaJIT/c-parser/typed.lua b/script/plugins/ffi/c-parser/typed.lua index c84b87e3..c84b87e3 100644 --- a/script/LuaJIT/c-parser/typed.lua +++ b/script/plugins/ffi/c-parser/typed.lua diff --git a/script/LuaJIT/cdefRerence.lua b/script/plugins/ffi/cdefRerence.lua index 819a0dd1..819a0dd1 100644 --- a/script/LuaJIT/cdefRerence.lua +++ b/script/plugins/ffi/cdefRerence.lua diff --git a/script/LuaJIT/init.lua b/script/plugins/ffi/init.lua index c94295da..57a64958 100644 --- a/script/LuaJIT/init.lua +++ b/script/plugins/ffi/init.lua @@ -1,8 +1,14 @@ -local searchCode = require 'LuaJIT.searchCode' -local cdefRerence = require 'LuaJIT.cdefRerence' -local cdriver = require 'LuaJIT.c-parser.cdriver' +local searchCode = require 'plugins.ffi.searchCode' +local cdefRerence = require 'plugins.ffi.cdefRerence' +local cdriver = require 'plugins.ffi.c-parser.cdriver' local util = require 'utility' local SDBMHash = require 'SDBMHash' +local ws = require 'workspace' +local files = require 'files' +local await = require 'await' +local config = require 'config' +local fs = require 'bee.filesystem' +local scope = require 'workspace.scope' local namespace <const> = 'ffi.namespace*.' @@ -323,9 +329,16 @@ function m.compileCodes(codes) return lines end -function m.initBuilder() - local config = require 'config' - local fs = require 'bee.filesystem' +local function createDir(uri) + local dir = scope.getScope(uri).uri or 'default' + local fileDir = fs.path(METAPATH) / ('%08x'):format(SDBMHash():hash(dir)) + fs.create_directories(fileDir) + return fileDir +end + +local builder +function m.initBuilder(fileDir) + fileDir = fileDir or createDir() ---@async return function (uri) local refs = cdefRerence() @@ -342,14 +355,44 @@ function m.initBuilder() if not texts then return end - local hash = ('%08x'):format(SDBMHash():hash(uri)) local encoding = config.get(nil, 'Lua.runtime.fileEncoding') - local filePath = METAPATH .. '/ffi/' .. table.concat({ hash, encoding }, '_') + local filePath = fileDir / table.concat({ hash, encoding }, '_') - fs.create_directories(fs.path(filePath):parent_path()) - util.saveFile(filePath .. '.d.lua', table.concat(texts, '\n')) + util.saveFile(tostring(filePath) .. '.d.lua', table.concat(texts, '\n')) end end +files.watch(function (ev, uri) + if ev == 'compiler' or ev == 'update' then + if builder then + await.call(function () ---@async + builder(uri) + end) + end + end +end) + +ws.watch(function (ev, uri) + if ev == 'startReload' then + if config.get(uri, 'Lua.runtime.version') ~= 'LuaJIT' then + return + end + await.call(function () ---@async + ws.awaitReady(uri) + local fileDir = createDir(uri) + builder = m.initBuilder(fileDir) + local client = require 'client' + client.setConfig { + { + key = 'Lua.workspace.library', + action = 'add', + value = tostring(fileDir), + uri = uri, + } + } + end) + end +end) + return m diff --git a/script/LuaJIT/searchCode.lua b/script/plugins/ffi/searchCode.lua index 9e74e7c0..9e74e7c0 100644 --- a/script/LuaJIT/searchCode.lua +++ b/script/plugins/ffi/searchCode.lua diff --git a/script/plugins/init.lua b/script/plugins/init.lua new file mode 100644 index 00000000..28f902ea --- /dev/null +++ b/script/plugins/init.lua @@ -0,0 +1 @@ +require 'plugins.ffi'
\ No newline at end of file |