diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-18 17:02:45 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-18 17:02:45 +0800 |
commit | 9e8901c5d09b4537a5741fd20dc5cc77c5a23dce (patch) | |
tree | e51ba03f013fcb40b994737f48ed60f10622b1ce /script | |
parent | b7fdf179a9015e3bef83f89c5a0811f1a67ef4d0 (diff) | |
download | lua-language-server-9e8901c5d09b4537a5741fd20dc5cc77c5a23dce.zip |
`FIX` library files not recognized correctly
Diffstat (limited to 'script')
-rw-r--r-- | script/files.lua | 22 | ||||
-rw-r--r-- | script/workspace/loading.lua | 77 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 1 |
3 files changed, 58 insertions, 42 deletions
diff --git a/script/files.lua b/script/files.lua index 3ec942cb..009beba4 100644 --- a/script/files.lua +++ b/script/files.lua @@ -12,6 +12,7 @@ local guide = require 'parser.guide' local smerger = require 'string-merger' local progress = require "progress" local encoder = require 'encoder' +local scope = require 'workspace.scope' ---@class files local m = {} @@ -23,7 +24,6 @@ m.assocMatcher = nil function m.reset() m.openMap = {} - m.libraryMap = {} m.fileMap = {} m.dllMap = {} m.visible = {} @@ -110,12 +110,28 @@ end --- 是否是库文件 function m.isLibrary(uri) - return m.libraryMap[uri] ~= nil + for _, scp in ipairs(scope.folders) do + local map = scp:get 'libraryMap' + if map and map[uri] ~= nil then + return true + end + end + local map = scope.fallback:get 'libraryMap' + if map and map[uri] ~= nil then + return true + end + return false end --- 获取库文件的根目录 function m.getLibraryPath(uri) - return m.libraryMap[uri] + for _, scp in ipairs(scope.folders) do + local map = scp:get 'libraryMap' + if map and map[uri] ~= nil then + return scp.uri + end + end + return nil end ---@param scp scope diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua index 50a48038..19fe0728 100644 --- a/script/workspace/loading.lua +++ b/script/workspace/loading.lua @@ -4,7 +4,8 @@ local await = require 'await' local files = require 'files' local config = require 'config.config' local client = require 'client' -local pub = require 'pub.pub' +local util = require 'utility' +local furi = require 'file-uri' ---@class workspace.loading ---@field scp scope @@ -69,50 +70,48 @@ function mt:loadFile(uri, libraryUri) end self.max = self.max + 1 self:update() - pub.task('loadFile', uri, function (content) - self._stash[#self._stash+1] = function () - self.read = self.read + 1 - self:update() - if not content then - return - end - if self._cache[uri] then - return - end - log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1024.0)) - self._cache[uri] = true - files.setText(uri, content, false) - files.addRef(uri) - if libraryUri then - log.info('++++As library of:', libraryUri) - files.setLibraryUri(self.scp, uri, libraryUri) - end + self._stash[#self._stash+1] = function () + local content = util.loadFile(furi.decode(uri)) + self.read = self.read + 1 + self:update() + if not content then + return + end + if self._cache[uri] then + return end - end) + log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1024.0)) + self._cache[uri] = true + files.setText(uri, content, false) + files.addRef(uri) + if libraryUri then + log.info('++++As library of:', libraryUri) + files.setLibraryUri(self.scp, uri, libraryUri) + end + end elseif files.isDll(uri) then self.max = self.max + 1 self:update() - pub.task('loadFile', uri, function (content) - self._stash[#self._stash+1] = function () - self.read = self.read + 1 - self:update() - if not content then - return - end - if self._cache[uri] then - return - end - log.info(('Preload dll at: %s , size = %.3f KB'):format(uri, #content / 1024.0)) - self._cache[uri] = true - files.saveDll(uri, content) - files.addRef(uri) - if libraryUri then - log.info('++++As library of:', libraryUri) - end + self._stash[#self._stash+1] = function () + local content = util.loadFile(furi.decode(uri)) + self.read = self.read + 1 + self:update() + if not content then + return + end + if self._cache[uri] then + return end - end) - await.delay() + log.info(('Preload dll at: %s , size = %.3f KB'):format(uri, #content / 1024.0)) + self._cache[uri] = true + files.saveDll(uri, content) + files.addRef(uri) + if libraryUri then + log.info('++++As library of:', libraryUri) + end + end end + await.delay() end function mt:loadStashed() diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index c537d78b..159f397b 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -55,6 +55,7 @@ function m.reset() ---@type scope[] m.folders = {} m.rootUri = nil + m.inited = false end m.reset() |