From ac3be36d170dfbfaa7c9f9a5d3ace10ccce8cfe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 29 Nov 2022 18:44:52 +0800 Subject: improve --- script/workspace/require-path.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'script/workspace/require-path.lua') diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua index cfe89b28..f65af868 100644 --- a/script/workspace/require-path.lua +++ b/script/workspace/require-path.lua @@ -250,6 +250,36 @@ function m.findUrisByRequireName(uri, name) return mgr:findUrisByRequireName(uri, name) end +---@param suri uri +---@param uri uri +---@param name string +---@return boolean +function m.isMatchedUri(suri, uri, name) + local searchers = config.get(suri, 'Lua.runtime.path') + local strict = config.get(suri, 'Lua.runtime.pathStrict') + local separator = config.get(suri, 'Lua.completion.requireSeparator') + local path = name:gsub('%' .. separator, '/') + + for _, searcher in ipairs(searchers) do + local fspath = searcher:gsub('%?', (path:gsub('%%', '%%%%'))) + fspath = workspace.normalize(fspath) + local tail = '/' .. furi.encode(fspath):gsub('^file:[/]*', '') + if util.stringEndWith(uri, tail) then + local parentUri = files.getLibraryUri(suri, uri) or uri + if parentUri == nil or parentUri == '' then + parentUri = furi.encode '/' + end + local relative = uri:sub(#parentUri + 1):sub(1, - #tail) + if not strict + or relative == '/' + or relative == '' then + return true + end + end + end + return false +end + files.watch(function (ev, uri) for _, scp in ipairs(workspace.folders) do scp:set('requireManager', nil) -- cgit v1.2.3