diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/libs/lua/basic.lni | 24 | ||||
-rw-r--r-- | server/src/config.lua | 8 | ||||
-rw-r--r-- | server/src/core/library.lua | 80 | ||||
-rw-r--r-- | server/src/method/initialized.lua | 2 | ||||
-rw-r--r-- | server/src/method/workspace/didChangeConfiguration.lua | 56 | ||||
-rw-r--r-- | server/src/service.lua | 22 | ||||
-rw-r--r-- | server/src/utility.lua | 35 |
7 files changed, 149 insertions, 78 deletions
diff --git a/server/libs/lua/basic.lni b/server/libs/lua/basic.lni index de0ed4be..a66b703c 100644 --- a/server/libs/lua/basic.lni +++ b/server/libs/lua/basic.lni @@ -352,9 +352,29 @@ enum = 'thread' name = 'type' enum = 'userdata' -[_VERSION] +["_VERSION Lua 5.1"] +name = '_VERSION' type = 'string' -value = 'Lua5.3' +value = 'Lua 5.1' +version = 'Lua 5.1' + +["_VERSION Lua 5.2"] +name = '_VERSION' +type = 'string' +value = 'Lua 5.2' +version = 'Lua 5.2' + +["_VERSION Lua 5.3"] +name = '_VERSION' +type = 'string' +value = 'Lua 5.3' +version = 'Lua 5.3' + +["_VERSION Lua 5.4"] +name = '_VERSION' +type = 'string' +value = 'Lua 5.4' +version = 'Lua 5.4' [xpcall] [[.args]] diff --git a/server/src/config.lua b/server/src/config.lua index 85bcdb91..0979289c 100644 --- a/server/src/config.lua +++ b/server/src/config.lua @@ -12,6 +12,10 @@ local function Integer(v) return false end +local function String(v) + return true, tostring(v) +end + local function Str2Hash(sep) return function (v) if type(v) == 'string' then @@ -36,7 +40,7 @@ end local Template = { runtime = { - version = 'Lua 5.3', + version = {'Lua 5.3', String}, }, diagnostics = { globals = {{}, Str2Hash ';'}, @@ -46,7 +50,7 @@ local Template = { ignoreDir = {{}, Str2Hash ';'}, ignoreSubmodules= {true, Boolean}, useGitIgnore = {true, Boolean}, - maxPreload = {300, Integer}, + maxPreload = {300, Integer}, } } diff --git a/server/src/core/library.lua b/server/src/core/library.lua index 8d8309a3..75382912 100644 --- a/server/src/core/library.lua +++ b/server/src/core/library.lua @@ -2,6 +2,8 @@ local lni = require 'lni' local fs = require 'bee.filesystem' local config = require 'config' +local Library = {} + local function mergeEnum(lib, locale) if not lib or not locale then return @@ -63,19 +65,42 @@ local function mergeLocale(libs, locale) end end +local function insertGlobal(tbl, key, value) + if value.version then + local runtimeVersion = config.config.runtime.version + if type(value.version) == 'table' then + local ok + for _, version in ipairs(value.version) do + if version == runtimeVersion then + ok = true + break + end + end + if not ok then + return + end + else + if value.version ~= runtimeVersion then + return + end + end + end + tbl[key] = value +end + local function mergeSource(alllibs, name, lib) if not lib.source then - alllibs.global[name] = lib + insertGlobal(alllibs.global, name, lib) return end for _, source in ipairs(lib.source) do local sourceName = source.name or name if source.type == 'global' then - alllibs.global[sourceName] = lib + insertGlobal(alllibs.global, sourceName, lib) elseif source.type == 'library' then - alllibs.library[sourceName] = lib + insertGlobal(alllibs.library, sourceName, lib) elseif source.type == 'object' then - alllibs.object[sourceName] = lib + insertGlobal(alllibs.object, sourceName, lib) end end end @@ -88,12 +113,28 @@ local function copy(t) return new end -local function insert(tbl, name, key, value) +local function insertChild(tbl, name, key, value) if not name or not key then return end - if value.version and value.version == config.config.runtime.version then - return + if value.version then + local runtimeVersion = config.config.runtime.version + if type(value.version) == 'table' then + local ok + for _, version in ipairs(value.version) do + if version == runtimeVersion then + ok = true + break + end + end + if not ok then + return + end + else + if value.version ~= runtimeVersion then + return + end + end end if not tbl[name] then tbl[name] = { @@ -108,11 +149,11 @@ end local function mergeParent(alllibs, name, lib) for _, parent in ipairs(lib.parent) do if parent.type == 'global' then - insert(alllibs.global, parent.name, name, lib) + insertChild(alllibs.global, parent.name, name, lib) elseif parent.type == 'library' then - insert(alllibs.library, parent.name, name, lib) + insertChild(alllibs.library, parent.name, name, lib) elseif parent.type == 'object' then - insert(alllibs.object, parent.name, name, lib) + insertChild(alllibs.object, parent.name, name, lib) end end end @@ -169,11 +210,10 @@ end local function init() local lang = require 'language' local id = lang.id - local alllibs = { - global = table.container(), - library = table.container(), - object = table.container(), - } + Library.global = table.container() + Library.library = table.container() + Library.object = table.container() + for path in scan(ROOT / 'libs') do local libs local buf = io.load(path) @@ -190,10 +230,14 @@ local function init() locale = loadLocale(id, relative) mergeLocale(libs, locale) end - mergeLibs(alllibs, libs) + mergeLibs(Library, libs) end +end - return alllibs +function Library.reload() + init() end -return init() +init() + +return Library diff --git a/server/src/method/initialized.lua b/server/src/method/initialized.lua index 918e8da3..97cafe82 100644 --- a/server/src/method/initialized.lua +++ b/server/src/method/initialized.lua @@ -49,7 +49,7 @@ return function (lsp) }, }, }, function (configs) - config:setConfig(configs[1]) + lsp:onUpdateConfig(configs[1]) initAfterConfig(lsp) end) return true diff --git a/server/src/method/workspace/didChangeConfiguration.lua b/server/src/method/workspace/didChangeConfiguration.lua index 67737eec..58fc0079 100644 --- a/server/src/method/workspace/didChangeConfiguration.lua +++ b/server/src/method/workspace/didChangeConfiguration.lua @@ -1,45 +1,4 @@ local rpc = require 'rpc' -local config = require 'config' - -local EXISTS = {} - -local function eq(a, b) - if a == EXISTS and b ~= nil then - return true - end - local tp1, tp2 = type(a), type(b) - if tp1 ~= tp2 then - return false - end - if tp1 == 'table' then - local mark = {} - for k in pairs(a) do - if not eq(a[k], b[k]) then - return false - end - mark[k] = true - end - for k in pairs(b) do - if not mark[k] then - return false - end - end - return true - end - return a == b -end - -local function copyTable(a) - local t = {} - for k, v in pairs(a) do - if type(v) == 'table' then - t[k] = copyTable(v) - else - t[k] = v - end - end - return t -end return function (lsp) -- 请求配置 @@ -50,19 +9,6 @@ return function (lsp) }, }, }, function (configs) - local oldConfig = copyTable(config.config) - config:setConfig(configs[1]) - local newConfig = config.config - if not eq(oldConfig.runtime, newConfig.runtime) then - lsp:reCompile() - end - if not eq(oldConfig.diagnostics, newConfig.diagnostics) then - log.debug('reDiagnostic') - lsp:reDiagnostic() - end - if not eq(oldConfig.workspace, newConfig.workspace) then - lsp:clearAllFiles() - lsp.workspace:scanFiles() - end + lsp:onUpdateConfig(configs[1]) end) end diff --git a/server/src/service.lua b/server/src/service.lua index 1c8d55b4..869159be 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -255,6 +255,9 @@ function mt:getCachedFileCount() end function mt:reCompile() + self.global = core.global(self) + self.chain = chainMgr() + self.globalValue = nil local compiled = {} local n = 0 for uri in pairs(self._file) do @@ -633,6 +636,25 @@ function mt:restartDueToMemoryLeak() end) end +function mt:onUpdateConfig(updated) + local oldConfig = table.deepCopy(config.config) + config:setConfig(updated) + local newConfig = config.config + if not table.equal(oldConfig.runtime, newConfig.runtime) then + local library = require 'core.library' + library.reload() + self:reCompile() + end + if not table.equal(oldConfig.diagnostics, newConfig.diagnostics) then + log.debug('reDiagnostic') + self:reDiagnostic() + end + if not table.equal(oldConfig.workspace, newConfig.workspace) then + self:clearAllFiles() + self.workspace:scanFiles() + end +end + function mt:_testMemory() local clock = os.clock() collectgarbage() diff --git a/server/src/utility.lua b/server/src/utility.lua index a4072510..c59fa2eb 100644 --- a/server/src/utility.lua +++ b/server/src/utility.lua @@ -129,6 +129,41 @@ function table.container(tbl) return sort_table(tbl) end +function table.equal(a, b) + local tp1, tp2 = type(a), type(b) + if tp1 ~= tp2 then + return false + end + if tp1 == 'table' then + local mark = {} + for k in pairs(a) do + if not table.equal(a[k], b[k]) then + return false + end + mark[k] = true + end + for k in pairs(b) do + if not mark[k] then + return false + end + end + return true + end + return a == b +end + +function table.deepCopy(a) + local t = {} + for k, v in pairs(a) do + if type(v) == 'table' then + t[k] = table.deepCopy(v) + else + t[k] = v + end + end + return t +end + function io.load(file_path) local f, e = io.open(file_path:string(), 'rb') if not f then |