diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-13 18:22:25 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-13 18:22:25 +0800 |
commit | 0354b01b082384279945c6ef02be8f297b3e9919 (patch) | |
tree | dc978663da73550efe2bcb861a7906def3819e7a /script-beta/workspace | |
parent | 426b30ed25c597554169474ff26543b8ac500652 (diff) | |
download | lua-language-server-0354b01b082384279945c6ef02be8f297b3e9919.zip |
自动完成require路径
Diffstat (limited to 'script-beta/workspace')
-rw-r--r-- | script-beta/workspace/require-path.lua | 27 | ||||
-rw-r--r-- | script-beta/workspace/workspace.lua | 5 |
2 files changed, 29 insertions, 3 deletions
diff --git a/script-beta/workspace/require-path.lua b/script-beta/workspace/require-path.lua index c21f598a..283e0112 100644 --- a/script-beta/workspace/require-path.lua +++ b/script-beta/workspace/require-path.lua @@ -22,11 +22,34 @@ local function getOnePath(path, searcher) end function m.getVisiblePath(path, searchers) + path = path:gsub('^[/\\]+', '') if not m.cache[path] then local result = {} m.cache[path] = result - for _, searcher in ipairs(searchers) do - end + local pos = 1 + repeat + local cutedPath = path:sub(pos) + local head + if pos > 1 then + head = path:sub(1, pos - 1) + end + pos = path:match('[/\\]+()', pos) + for _, searcher in ipairs(searchers) do + local expect = getOnePath(cutedPath, searcher) + if expect then + if head then + searcher = head .. searcher + end + result[#result+1] = { + searcher = searcher, + expect = expect, + } + end + end + if not pos then + break + end + until not pos end return m.cache[path] end diff --git a/script-beta/workspace/workspace.lua b/script-beta/workspace/workspace.lua index 59a42f2b..85221aca 100644 --- a/script-beta/workspace/workspace.lua +++ b/script-beta/workspace/workspace.lua @@ -7,6 +7,7 @@ local glob = require 'glob' local platform = require 'bee.platform' local await = require 'await' local diagnostic = require 'provider.diagnostic' +local rpath = require 'workspace.require-path' local m = {} m.type = 'workspace' @@ -193,12 +194,14 @@ end function m.getRelativePath(uri) local path = furi.decode(uri) - return fs.relative(fs.path(path), fs.path(m.path)):string() + local relative = fs.relative(fs.path(path), fs.path(m.path)):string() + return relative:gsub('^[/\\]+', '') end function m.reload() m.preloadVersion = m.preloadVersion + 1 files.removeAll() + rpath.flush() await.create(function () await.setDelayer(function () return m.preloadVersion |