@@ -4,9 +4,6 @@ local cdriver = require 'plugins.ffi.c-parser.cdriver'
44local util = require ' plugins.ffi.c-parser.util'
55local utility = require ' utility'
66local SDBMHash = require ' SDBMHash'
7- local ws = require ' workspace'
8- local files = require ' files'
9- local await = require ' await'
107local config = require ' config'
118local fs = require ' bee.filesystem'
129local scope = require ' workspace.scope'
@@ -322,70 +319,18 @@ function m.compileCodes(codes)
322319 return lines
323320end
324321
325- local function createDir (uri )
326- local dir = scope .getScope (uri ).uri or ' default'
327- local fileDir = fs .path (METAPATH ) / (' %08x' ):format (SDBMHash ():hash (dir ))
328- fs .create_directories (fileDir )
329- return fileDir
330- end
331-
332- local builder
333- function m .initBuilder (fileDir )
334- fileDir = fileDir or createDir ()
335- --- @async
336- return function (uri )
337- local refs = cdefRerence ()
338- if not refs or # refs == 0 then
339- return
340- end
341-
342- local codes = searchCode (refs , uri )
343- if not codes then
344- return
345- end
346-
347- local texts = m .compileCodes (codes )
348- if not texts then
349- return
350- end
351- local hash = (' %08x' ):format (SDBMHash ():hash (uri ))
352- local encoding = config .get (nil , ' Lua.runtime.fileEncoding' )
353- local filePath = fileDir / table.concat ({ hash , encoding }, ' _' )
354-
355- utility .saveFile (tostring (filePath ) .. ' .d.lua' , table.concat (texts , ' \n ' ))
322+ function m .build_single (codes , fileDir , uri )
323+ local texts = m .compileCodes (codes )
324+ if not texts then
325+ return
356326 end
357- end
358327
359- files .watch (function (ev , uri )
360- if ev == ' compiler' or ev == ' update' then
361- if builder then
362- await .call (function () --- @async
363- builder (uri )
364- end )
365- end
366- end
367- end )
328+ local hash = (' %08x' ):format (SDBMHash ():hash (uri ))
329+ local encoding = config .get (nil , ' Lua.runtime.fileEncoding' )
330+ local filePath = fileDir / table.concat ({ hash , encoding }, ' _' )
368331
369- ws .watch (function (ev , uri )
370- if ev == ' startReload' then
371- if config .get (uri , ' Lua.runtime.version' ) ~= ' LuaJIT' then
372- return
373- end
374- await .call (function () --- @async
375- ws .awaitReady (uri )
376- local fileDir = createDir (uri )
377- builder = m .initBuilder (fileDir )
378- local client = require ' client'
379- client .setConfig {
380- {
381- key = ' Lua.workspace.library' ,
382- action = ' add' ,
383- value = tostring (fileDir ),
384- uri = uri ,
385- }
386- }
387- end )
388- end
389- end )
332+ utility .saveFile (tostring (filePath ) .. ' .d.lua' , table.concat (texts , ' \n ' ))
333+ return true
334+ end
390335
391336return m
0 commit comments