diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/files.lua | 22 | ||||
-rw-r--r-- | script/workspace/loading.lua | 77 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 1 | ||||
-rw-r--r-- | test/tclient/lclient.lua | 11 | ||||
-rw-r--r-- | test/tclient/tests/library-ignore-limit.lua | 8 |
6 files changed, 74 insertions, 46 deletions
diff --git a/changelog.md b/changelog.md index 48f79551..9a1a455f 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## 2.6.1 * `FIX` modify luarc failed +* `FIX` library files not recognized correctly ## 2.6.0 `2022-1-13` 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() diff --git a/test/tclient/lclient.lua b/test/tclient/lclient.lua index 52b72290..fa94481f 100644 --- a/test/tclient/lclient.lua +++ b/test/tclient/lclient.lua @@ -63,6 +63,11 @@ function mt:start(callback) local finished = false + await.setErrorHandle(function (...) + local msg = log.error(...) + error(msg) + end) + ---@async await.call(function () callback(self) @@ -144,7 +149,7 @@ function mt:update() if callback then proto.doResponse { id = out.id, - params = callback(out.params), + result = callback(out.params), } elseif out.method:sub(1, 2) ~= '$/' then error('Unknown method: ' .. out.method) @@ -164,10 +169,12 @@ end function mt:registerFakers() for _, method in ipairs { + 'textDocument/publishDiagnostics', 'workspace/configuration', 'workspace/semanticTokens/refresh', 'window/workDoneProgress/create', - 'textDocument/publishDiagnostics', + 'window/showMessage', + 'window/logMessage', } do self:register(method, function () return nil diff --git a/test/tclient/tests/library-ignore-limit.lua b/test/tclient/tests/library-ignore-limit.lua index 66d6cc09..baf42978 100644 --- a/test/tclient/tests/library-ignore-limit.lua +++ b/test/tclient/tests/library-ignore-limit.lua @@ -3,6 +3,7 @@ local util = require 'utility' local ws = require 'workspace' local files = require 'files' local furi = require 'file-uri' +local fs = require 'bee.filesystem' local libraryPath = LOGPATH .. '/large-file-library' local largeFilePath = LOGPATH .. '/large-file-library/large-file.lua' @@ -13,11 +14,14 @@ lclient():start(function (client) client:register('workspace/configuration', function () return { - ['Lua.workspace.library'] = { libraryPath } + { + ['workspace.library'] = { libraryPath } + }, } end) - util.saveFile(largeFilePath, string.rep('--this is a large file\n', 20000)) + fs.create_directories(fs.path(libraryPath)) + util.saveFile(largeFilePath, string.rep('--this is a large file\n', 100000)) client:initialize() |