diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-10 16:43:07 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-10 16:43:07 +0800 |
commit | 426b30ed25c597554169474ff26543b8ac500652 (patch) | |
tree | 94ab1194e7359b8e51881d4c1898dddb1578d1ba /script-beta/workspace/require-path.lua | |
parent | 45dd1c9bde526108b53be554be82a8daca098599 (diff) | |
download | lua-language-server-426b30ed25c597554169474ff26543b8ac500652.zip |
暂存
Diffstat (limited to 'script-beta/workspace/require-path.lua')
-rw-r--r-- | script-beta/workspace/require-path.lua | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/script-beta/workspace/require-path.lua b/script-beta/workspace/require-path.lua index a9bd6fc0..c21f598a 100644 --- a/script-beta/workspace/require-path.lua +++ b/script-beta/workspace/require-path.lua @@ -1,7 +1,38 @@ local m = {} ---- `aaa/bbb/ccc.lua` 与 `?.lua` 将返回 `a.b.c` -function m.getVisiblePath(path, searcher) +m.cache = {} + +--- `aaa/bbb/ccc.lua` 与 `?.lua` 将返回 `aaa.bbb.cccc` +local function getOnePath(path, searcher) + local stemPath = path + : gsub('%.[^%.]+$', '') + : gsub('[/\\]+', '.') + local stemSearcher = searcher + : gsub('%.[^%.]+$', '') + : gsub('[/\\]+', '.') + local start = stemSearcher:match '()%?' or 1 + for pos = start, #stemPath do + local word = stemPath:sub(start, pos) + local newSearcher = stemSearcher:gsub('%?', word) + if newSearcher == stemPath then + return word + end + end + return nil +end + +function m.getVisiblePath(path, searchers) + if not m.cache[path] then + local result = {} + m.cache[path] = result + for _, searcher in ipairs(searchers) do + end + end + return m.cache[path] +end + +function m.flush() + m.cache = {} end return m |