diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-06-24 16:58:49 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-06-24 16:58:49 +0800 |
commit | 0e3c22455e4398541471351291522b200417e31c (patch) | |
tree | be27dee3e173adecaeaf04be307d1e4558f8a887 /server/src/service.lua | |
parent | cc97259ed0d37d964e16bc37c0be3e9e982e719f (diff) | |
download | lua-language-server-0e3c22455e4398541471351291522b200417e31c.zip |
实现library
Diffstat (limited to 'server/src/service.lua')
-rw-r--r-- | server/src/service.lua | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/server/src/service.lua b/server/src/service.lua index d2232086..3dfcb5a5 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -211,6 +211,9 @@ end ---@param uri uri function mt:close(uri) self._files:close(uri) + if self._files:isLibrary(uri) then + return + end if not self:isLua(uri) or self:isIgnored(uri) then self:removeText(uri) end @@ -224,24 +227,16 @@ end ---@param uri uri ---@param path path ----@param buf string ----@param compiled table -function mt:readText(uri, path, buf, compiled) - if self._files:get(uri) then - return - end - if not self:isLua(uri) or self:isIgnored(uri) then - return - end - local text = buf or io.load(path) +---@param text string +function mt:checkReadFile(uri, path, text) if not text then log.debug('No file: ', path) - return + return false end local size = #text / 1000.0 if size > config.config.workspace.preloadFileSize then log.info(('Skip large file, size: %.3f KB: %s'):format(size, uri)) - return + return false end if self:getCachedFileCount() >= config.config.workspace.maxPreload then if not self._hasShowHitMaxPreload then @@ -251,6 +246,24 @@ function mt:readText(uri, path, buf, compiled) message = lang.script('MWS_MAX_PRELOAD', config.config.workspace.maxPreload), }) end + return false + end + return true +end + +---@param uri uri +---@param path path +---@param buf string +---@param compiled table +function mt:readText(uri, path, buf, compiled) + if self._files:get(uri) then + return + end + if not self:isLua(uri) or self:isIgnored(uri) then + return + end + local text = buf or io.load(path) + if not self:checkReadFile(uri, path, text) then return end self._files:save(uri, text, 0) @@ -258,6 +271,19 @@ function mt:readText(uri, path, buf, compiled) end ---@param uri uri +---@param path path +---@param buf string +---@param compiled table +function mt:readLibrary(uri, path, buf, compiled) + if not self:checkReadFile(uri, path, buf) then + return + end + self._files:save(uri, buf, 0) + self._files:setLibrary(uri) + self:needCompile(uri, compiled) +end + +---@param uri uri function mt:removeText(uri) self._files:remove(uri) self:compileVM(uri) @@ -515,7 +541,9 @@ function mt:doDiagnostics(uri) if not file or file:isRemoved() or not file:getVM() - or file:getVM():isRemoved() then + or file:getVM():isRemoved() + or self._files:isLibrary(uri) + then self._needDiagnostics[uri] = nil self:clearDiagnostics(uri) return |