summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/files.lua25
-rw-r--r--script/workspace/loading.lua1
-rw-r--r--script/workspace/require-path.lua11
-rw-r--r--script/workspace/scope.lua14
-rw-r--r--script/workspace/workspace.lua2
5 files changed, 20 insertions, 33 deletions
diff --git a/script/files.lua b/script/files.lua
index bd7ae819..5e86d217 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -99,14 +99,6 @@ function m.getOpenedCache(uri)
return data.cache
end
---- 标记为库文件
----@param scp scope
----@param uri uri
----@param libraryUri uri
-function m.setLibraryUri(scp, uri, libraryUri)
- scp:get 'libraryMap' [uri] = libraryUri
-end
-
--- 是否是库文件
function m.isLibrary(uri, excludeFolder)
if excludeFolder then
@@ -117,13 +109,11 @@ function m.isLibrary(uri, excludeFolder)
end
end
for _, scp in ipairs(scope.folders) do
- local map = scp:get 'libraryMap'
- if map and map[uri] ~= nil then
+ if scp:isLinkedUri(uri) then
return true
end
end
- local map = scope.fallback:get 'libraryMap'
- if map and map[uri] ~= nil then
+ if scope.fallback:isLinkedUri(uri) then
return true
end
return false
@@ -132,16 +122,7 @@ end
--- 获取库文件的根目录
function m.getLibraryUri(suri, uri)
local scp = scope.getScope(suri)
- local map = scp:get 'libraryMap'
- if map and map[uri] ~= nil then
- return map[uri]
- end
- return nil
-end
-
----@param scp scope
-function m.flushAllLibrary(scp)
- scp:set('libraryMap', {})
+ return scp:getLinkedUri(uri)
end
--- 是否存在
diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua
index 0ef94320..5fc5a134 100644
--- a/script/workspace/loading.lua
+++ b/script/workspace/loading.lua
@@ -99,7 +99,6 @@ function mt:loadFile(uri, libraryUri)
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
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua
index c3dc92d3..f0a75eb1 100644
--- a/script/workspace/require-path.lua
+++ b/script/workspace/require-path.lua
@@ -56,9 +56,7 @@ function m.getVisiblePath(suri, path)
local result = cache[path]
if not result then
result = {}
- if libraryPath then
- cache[path] = result
- end
+ cache[path] = result
for _, searcher in ipairs(searchers) do
local isAbsolute = searcher:match '^[/\\]'
or searcher:match '^%a+%:'
@@ -71,11 +69,7 @@ function m.getVisiblePath(suri, path)
if libraryPath then
currentPath = currentPath:sub(#libraryPath + 2)
else
- local isRelative
- currentPath, isRelative = workspace.getRelativePath(uri)
- if not isAbsolute and not isRelative then
- goto CONTINUE
- end
+ currentPath = workspace.getRelativePath(uri)
end
end
repeat
@@ -100,7 +94,6 @@ function m.getVisiblePath(suri, path)
addRequireName(suri, uri, expect)
end
until not pos or strict
- ::CONTINUE::
end
end
return result
diff --git a/script/workspace/scope.lua b/script/workspace/scope.lua
index 711fc1a1..304e875e 100644
--- a/script/workspace/scope.lua
+++ b/script/workspace/scope.lua
@@ -56,6 +56,20 @@ function mt:isLinkedUri(uri)
return false
end
+---@param uri uri
+---@return uri?
+function mt:getLinkedUri(uri)
+ if not uri then
+ return nil
+ end
+ for linkUri in pairs(self._links) do
+ if uri:sub(1, #linkUri) == linkUri then
+ return linkUri
+ end
+ end
+ return nil
+end
+
---@param k string
---@param v any
function mt:set(k, v)
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 9b8cb703..e8a61665 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -428,8 +428,8 @@ function m.awaitReload(scp)
scp:set('ready', false)
scp:set('nativeMatcher', nil)
scp:set('libraryMatcher', nil)
+ scp:removeAllLinks()
m.flushFiles(scp)
- files.flushAllLibrary(scp)
plugin.init(scp)
m.awaitPreload(scp)
scp:set('ready', true)