summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/config/config.lua6
-rw-r--r--script/core/definition.lua2
-rw-r--r--script/core/diagnostics/different-requires.lua2
-rw-r--r--script/core/hover/description.lua2
-rw-r--r--script/core/searcher.lua2
-rw-r--r--script/core/type-definition.lua2
-rw-r--r--script/library.lua37
-rw-r--r--script/provider/completion.lua25
-rw-r--r--script/provider/diagnostic.lua2
-rw-r--r--script/provider/provider.lua6
-rw-r--r--script/provider/semantic-tokens.lua10
-rw-r--r--script/service/telemetry.lua6
-rw-r--r--script/vm/getLinks.lua2
-rw-r--r--script/workspace/require-path.lua18
-rw-r--r--script/workspace/workspace.lua10
15 files changed, 70 insertions, 62 deletions
diff --git a/script/config/config.lua b/script/config/config.lua
index 4113e670..42af9ea1 100644
--- a/script/config/config.lua
+++ b/script/config/config.lua
@@ -390,12 +390,12 @@ function m.update(scp, new, null)
end
end
----@param callback fun(key: string, value: any, oldValue: any)
+---@param callback fun(uri: uri, key: string, value: any, oldValue: any)
function m.watch(callback)
m.watchList[#m.watchList+1] = callback
end
-function m.event(key, value, oldValue)
+function m.event(uri, key, value, oldValue)
if not m.delay then
m.delay = {}
timer.wait(0, function ()
@@ -403,7 +403,7 @@ function m.event(key, value, oldValue)
m.delay = nil
for _, info in ipairs(delay) do
for _, callback in ipairs(m.watchList) do
- callback(info.key, info.value, info.oldValue)
+ callback(uri, info.key, info.value, info.oldValue)
end
end
end)
diff --git a/script/core/definition.lua b/script/core/definition.lua
index eadae30f..6c6b3df3 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -75,7 +75,7 @@ local function checkRequire(source, offset)
return nil
end
if libName == 'require' then
- return rpath.findUrisByRequirePath(literal)
+ return rpath.findUrisByRequirePath(guide.getUri(source), literal)
elseif libName == 'dofile'
or libName == 'loadfile' then
return workspace.findUrisByFilePath(literal)
diff --git a/script/core/diagnostics/different-requires.lua b/script/core/diagnostics/different-requires.lua
index 3a49ceef..de063c9f 100644
--- a/script/core/diagnostics/different-requires.lua
+++ b/script/core/diagnostics/different-requires.lua
@@ -21,7 +21,7 @@ return function (uri, callback)
return
end
local literal = arg1[1]
- local results = rpath.findUrisByRequirePath(literal)
+ local results = rpath.findUrisByRequirePath(uri, literal)
if not results or #results ~= 1 then
return
end
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index 7f34f14d..c46b239d 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -15,7 +15,7 @@ local function collectRequire(mode, literal, uri)
local rootPath = ws.getRootUri(uri) or ''
local result, searchers
if mode == 'require' then
- result, searchers = rpath.findUrisByRequirePath(literal)
+ result, searchers = rpath.findUrisByRequirePath(uri, literal)
elseif mode == 'dofile'
or mode == 'loadfile' then
result = ws.findUrisByFilePath(literal)
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 68852062..6c832155 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -796,7 +796,7 @@ function m.searchRefsByID(status, suri, expect, mode)
if not requireName then
return
end
- local uris = rpath.findUrisByRequirePath(requireName)
+ local uris = rpath.findUrisByRequirePath(suri, requireName)
footprint(status, 'require:', requireName)
for i = 1, #uris do
local ruri = uris[i]
diff --git a/script/core/type-definition.lua b/script/core/type-definition.lua
index e9cf3e47..1f021fb3 100644
--- a/script/core/type-definition.lua
+++ b/script/core/type-definition.lua
@@ -76,7 +76,7 @@ local function checkRequire(source, offset)
return nil
end
if libName == 'require' then
- return rpath.findUrisByRequirePath(literal)
+ return rpath.findUrisByRequirePath(guide.getUri(source), literal)
elseif libName == 'dofile'
or libName == 'loadfile' then
return workspace.findUrisByFilePath(literal)
diff --git a/script/library.lua b/script/library.lua
index d0f19c30..9b31410c 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -11,6 +11,8 @@ local files = require 'files'
local await = require 'await'
local timer = require 'timer'
local encoder = require 'encoder'
+local ws = require 'workspace.workspace'
+local scope = require 'workspace.scope'
local m = {}
@@ -197,10 +199,8 @@ local function loadMetaLocale(langID, result)
return result
end
-local function initBuiltIn()
- if not m.inited then
- return
- end
+local function initBuiltIn(uri)
+ local scp = ws.getScope(uri)
local langID = lang.id
local version = config.get(uri, 'Lua.runtime.version')
local encoding = config.get(uri, 'Lua.runtime.fileEncoding')
@@ -214,19 +214,20 @@ local function initBuiltIn()
if langID ~= 'en-US' then
loadMetaLocale(langID, metaLang)
end
- --log.debug('metaLang:', util.dump(metaLang))
- if m.metaPath == metaPath:string() then
+
+ if scp:get('metaPath') == metaPath:string() then
return
end
- m.metaPath = metaPath:string()
- m.metaPaths = {}
- local suc = xpcall(function ()
+ scp:set('metaPath', metaPath:string())
+ local suc, ok = xpcall(function ()
if not fs.exists(metaPath) then
fs.create_directories(metaPath)
+ return true
end
+ return false
end, log.error)
- if not suc then
+ if not suc or not ok then
return
end
local out = fsu.dummyFS()
@@ -240,10 +241,8 @@ local function initBuiltIn()
local libPath = templateDir / libName
local metaDoc = compileSingleMetaDoc(uri, fsu.loadFile(libPath), metaLang, status)
if metaDoc then
- local outPath = metaPath / libName
metaDoc = encoder.encode(encoding, metaDoc, 'auto')
out:saveFile(libName, metaDoc)
- m.metaPaths[#m.metaPaths+1] = outPath:string()
end
::CONTINUE::
end
@@ -310,7 +309,7 @@ local function load3rdConfigInDir(dir, configs, inner)
end
end
-local function load3rdConfig()
+local function load3rdConfig(uri)
local configs = {}
load3rdConfigInDir(innerThirdDir, configs, true)
local thirdDirs = config.get(uri, 'Lua.workspace.userThirdParty')
@@ -459,7 +458,7 @@ local function check3rd(uri)
return
end
if thirdConfigs == nil then
- thirdConfigs = load3rdConfig() or false
+ thirdConfigs = load3rdConfig(uri) or false
end
if not thirdConfigs then
return
@@ -475,7 +474,7 @@ local function check3rd(uri)
end
end
-config.watch(function (key, value, oldValue)
+config.watch(function (uri, key, value, oldValue)
if key:find '^Lua.runtime' then
initBuiltIn(uri)
end
@@ -493,7 +492,13 @@ function m.init()
return
end
m.inited = true
- initBuiltIn()
+ if #ws.folders == 0 then
+ initBuiltIn(nil)
+ else
+ for _, scp in ipairs(ws.folders) do
+ initBuiltIn(scp.uri)
+ end
+ end
end
return m
diff --git a/script/provider/completion.lua b/script/provider/completion.lua
index 6c215f15..ec2ac6c7 100644
--- a/script/provider/completion.lua
+++ b/script/provider/completion.lua
@@ -2,6 +2,7 @@ local proto = require 'proto'
local nonil = require 'without-check-nil'
local client = require 'client'
local config = require 'config'
+local ws = require 'workspace'
local isEnable = false
@@ -13,15 +14,17 @@ local function allWords()
list[#list+1] = c
mark[c] = true
end
- local postfix = config.get(uri, 'Lua.completion.postfix')
- if postfix ~= '' and not mark[postfix] then
- list[#list+1] = postfix
- mark[postfix] = true
+ for _, scp in ipairs(ws.folders) do
+ local postfix = config.get(scp.uri, 'Lua.completion.postfix')
+ if postfix ~= '' and not mark[postfix] then
+ list[#list+1] = postfix
+ mark[postfix] = true
+ end
end
return list
end
-local function enable()
+local function enable(uri)
if isEnable then
return
end
@@ -46,7 +49,7 @@ local function enable()
})
end
-local function disable()
+local function disable(uri)
if not isEnable then
return
end
@@ -67,18 +70,18 @@ local function disable()
})
end
-config.watch(function (key, value)
+config.watch(function (uri, key, value)
if key == 'Lua.completion.enable' then
if value == true then
- enable()
+ enable(uri)
else
- disable()
+ disable(uri)
end
end
if key == 'Lua.completion.postfix' then
if config.get(uri, 'Lua.completion.enable') then
- disable()
- enable()
+ disable(uri)
+ enable(uri)
end
end
end)
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index 1be7d626..75a9fdae 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -442,7 +442,7 @@ await.watch(function (ev, co) ---@async
end
end)
-config.watch(function (key, value, oldValue)
+config.watch(function (uri, key, value, oldValue)
if key:find 'Lua.diagnostics' then
if value ~= oldValue then
m.diagnosticsAll()
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 9d853e06..7357240a 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -1019,7 +1019,7 @@ do
end)
end
-local function refreshStatusBar()
+local function refreshStatusBar(uri)
local value = config.get(uri, 'Lua.window.statusBar')
if value then
proto.notify('$/status/show')
@@ -1028,9 +1028,9 @@ local function refreshStatusBar()
end
end
-config.watch(function (key, value)
+config.watch(function (uri, key, value)
if key == 'Lua.window.statusBar' then
- refreshStatusBar()
+ refreshStatusBar(uri)
end
end)
diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua
index 2a8013db..f6acb280 100644
--- a/script/provider/semantic-tokens.lua
+++ b/script/provider/semantic-tokens.lua
@@ -20,7 +20,7 @@ local function toArray(map)
end
local dontShowAgain = false
-local function enable()
+local function enable(uri)
if isEnable then
return
end
@@ -80,7 +80,7 @@ local function enable()
end
end
-local function disable()
+local function disable(uri)
if not isEnable then
return
end
@@ -109,16 +109,16 @@ local function refresh()
proto.request('workspace/semanticTokens/refresh', json.null)
end
-config.watch(function (key, value, oldValue)
+config.watch(function (uri, key, value, oldValue)
if key == 'Lua.color.mode' then
if value == 'Semantic' or value == 'SemanticEnhanced' then
if isEnable and value ~= oldValue then
refresh()
else
- enable()
+ enable(uri)
end
else
- disable()
+ disable(uri)
end
end
if key:find '^Lua.runtime'
diff --git a/script/service/telemetry.lua b/script/service/telemetry.lua
index b61e565b..93e10487 100644
--- a/script/service/telemetry.lua
+++ b/script/service/telemetry.lua
@@ -102,7 +102,7 @@ end)
local m = {}
-function m.updateConfig()
+function m.updateConfig(uri)
if config.get(uri, 'Lua.telemetry.enable') ~= nil then
return
end
@@ -151,9 +151,9 @@ function m.updateConfig()
end)
end
-config.watch(function (key)
+config.watch(function (uri, key)
if key == 'Lua.telemetry.enable' then
- m.updateConfig()
+ m.updateConfig(uri)
end
end)
diff --git a/script/vm/getLinks.lua b/script/vm/getLinks.lua
index 77d869f8..7fe31e5e 100644
--- a/script/vm/getLinks.lua
+++ b/script/vm/getLinks.lua
@@ -20,7 +20,7 @@ local function getFileLinks(uri)
if not args or not args[1] or args[1].type ~= 'string' then
return
end
- local uris = rpath.findUrisByRequirePath(args[1][1])
+ local uris = rpath.findUrisByRequirePath(uri, args[1][1])
for _, u in ipairs(uris) do
if not links[u] then
links[u] = {}
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua
index a0313a58..84541808 100644
--- a/script/workspace/require-path.lua
+++ b/script/workspace/require-path.lua
@@ -8,7 +8,7 @@ local m = {}
m.cache = {}
--- `aaa/bbb/ccc.lua` 与 `?.lua` 将返回 `aaa.bbb.cccc`
-local function getOnePath(path, searcher)
+local function getOnePath(uri, path, searcher)
local separator = config.get(uri, 'Lua.completion.requireSeparator')
local stemPath = path
: gsub('%.[^%.]+$', '')
@@ -27,9 +27,9 @@ local function getOnePath(path, searcher)
return nil
end
-function m.getVisiblePath(path)
- local searchers = config.get(uri, 'Lua.runtime.path')
- local strict = config.get(uri, 'Lua.runtime.pathStrict')
+function m.getVisiblePath(suri, path)
+ local searchers = config.get(suri, 'Lua.runtime.path')
+ local strict = config.get(suri, 'Lua.runtime.pathStrict')
path = workspace.normalize(path)
local uri = furi.encode(path)
local libraryPath = files.getLibraryPath(uri)
@@ -63,7 +63,7 @@ function m.getVisiblePath(path)
else
searcher = searcher :gsub('[/\\]+', '/')
end
- local expect = getOnePath(cutedPath, searcher)
+ local expect = getOnePath(suri, cutedPath, searcher)
if expect then
local mySearcher = searcher
if head then
@@ -82,11 +82,11 @@ end
--- 查找符合指定require path的所有uri
---@param path string
-function m.findUrisByRequirePath(path)
+function m.findUrisByRequirePath(suri, path)
if type(path) ~= 'string' then
return {}
end
- local separator = config.get(uri, 'Lua.completion.requireSeparator')
+ local separator = config.get(suri, 'Lua.completion.requireSeparator')
local fspath = path:gsub('%' .. separator, '/')
local vm = require 'vm'
local cache = vm.getCache 'findUrisByRequirePath'
@@ -106,7 +106,7 @@ function m.findUrisByRequirePath(path)
end
for uri in files.eachFile() do
- local infos = m.getVisiblePath(furi.decode(uri))
+ local infos = m.getVisiblePath(suri, furi.decode(uri))
for _, info in ipairs(infos) do
local fsexpect = info.expect:gsub('%' .. separator, '/')
if fsexpect == fspath then
@@ -135,7 +135,7 @@ files.watch(function (ev)
end
end)
-config.watch(function (key, value, oldValue)
+config.watch(function (uri, key, value, oldValue)
if key == 'Lua.completion.requireSeparator'
or key == 'Lua.runtime.path'
or key == 'Lua.runtime.pathStrict' then
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index e8a67ccc..c037baaa 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -151,8 +151,8 @@ function m.getLibraryMatchers(scp)
end
end
-- TODO
- if library.metaPath then
- librarys[m.normalize(library.metaPath)] = true
+ if scp:get 'metaPath' then
+ librarys[m.normalize(scp:get 'metaPath')] = true
end
local matchers = {}
@@ -281,7 +281,7 @@ function m.findUrisByFilePath(path)
end
local myUri = furi.encode(path)
local vm = require 'vm'
- local resultCache = vm.getCache 'findUrisByRequirePath.result'
+ local resultCache = vm.getCache 'findUrisByFilePath.result'
if resultCache[path] then
return resultCache[path]
end
@@ -475,12 +475,12 @@ files.watch(function (ev, uri) ---@async
end
end)
-config.watch(function (key, value, oldValue)
+config.watch(function (uri, key, value, oldValue)
if key:find '^Lua.runtime'
or key:find '^Lua.workspace'
or key:find '^files' then
if value ~= oldValue then
- m.reload()
+ m.reload(m.getScope(uri))
end
end
end)