summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/files.lua22
-rw-r--r--script/workspace/loading.lua77
-rw-r--r--script/workspace/workspace.lua1
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()