summaryrefslogtreecommitdiff
path: root/script/workspace/require-path.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-11-29 18:44:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-11-29 18:44:52 +0800
commitac3be36d170dfbfaa7c9f9a5d3ace10ccce8cfe4 (patch)
tree671bc8c6bc5ea5a02478b64491b1c65e71dcbbd2 /script/workspace/require-path.lua
parent943b86f06af58216e2f99eee2a45547080980efa (diff)
downloadlua-language-server-ac3be36d170dfbfaa7c9f9a5d3ace10ccce8cfe4.zip
improve
Diffstat (limited to 'script/workspace/require-path.lua')
-rw-r--r--script/workspace/require-path.lua30
1 files changed, 30 insertions, 0 deletions
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)