main.lua 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. local fs = require 'bee.filesystem'
  2. local util = require 'utility'
  3. local version = require 'version'
  4. local function getValue(value)
  5. if value == 'true' or value == nil then
  6. value = true
  7. elseif value == 'false' then
  8. value = false
  9. elseif tonumber(value) then
  10. value = tonumber(value)
  11. elseif value:sub(1, 1) == '"' and value:sub(-1, -1) == '"' then
  12. value = value:sub(2, -2)
  13. end
  14. return value
  15. end
  16. local function loadArgs()
  17. ---@type string?
  18. local lastKey
  19. for _, v in ipairs(arg) do
  20. ---@type string?
  21. local key, tail = v:match '^%-%-([%w_]+)(.*)$'
  22. local value
  23. if key then
  24. value = tail:match '=(.+)'
  25. lastKey = nil
  26. if not value then
  27. lastKey = key
  28. end
  29. else
  30. if lastKey then
  31. key = lastKey
  32. value = v
  33. lastKey = nil
  34. end
  35. end
  36. if key then
  37. _G[key:upper()] = getValue(value)
  38. end
  39. end
  40. end
  41. loadArgs()
  42. local currentPath = debug.getinfo(1, 'S').source:sub(2)
  43. local rootPath = currentPath:gsub('[/\\]*[^/\\]-$', '')
  44. rootPath = (rootPath == '' and '.' or rootPath)
  45. ROOT = fs.path(util.expandPath(rootPath))
  46. LOGPATH = LOGPATH and util.expandPath(LOGPATH) or (ROOT:string() .. '/log')
  47. METAPATH = METAPATH and util.expandPath(METAPATH) or (ROOT:string() .. '/meta')
  48. ---@diagnostic disable-next-line: deprecated
  49. debug.setcstacklimit(200)
  50. collectgarbage('generational', 10, 50)
  51. --collectgarbage('incremental', 120, 120, 0)
  52. ---@diagnostic disable-next-line: lowercase-global
  53. log = require 'log'
  54. log.init(ROOT, fs.path(LOGPATH) / 'service.log')
  55. if LOGLEVEL then
  56. log.level = tostring(LOGLEVEL):lower()
  57. end
  58. log.info('Lua Lsp startup, root: ', ROOT)
  59. log.info('ROOT:', ROOT:string())
  60. log.info('LOGPATH:', LOGPATH)
  61. log.info('METAPATH:', METAPATH)
  62. log.info('VERSION:', version.getVersion())
  63. require 'tracy'
  64. xpcall(dofile, log.debug, (ROOT / 'debugger.lua'):string())
  65. require 'cli'
  66. local _, service = xpcall(require, log.error, 'service')
  67. service.start()