diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-12-21 10:40:44 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-12-21 10:40:44 +0800 |
commit | b87a61234cef1122089de943b946b1b6cb7c0d57 (patch) | |
tree | f6319f26c5ffab5fd81fdf1004fd991c9b14c97f /script/workspace | |
parent | 2c59b675487e493bdcfc528f2cab654e6de1c262 (diff) | |
download | lua-language-server-b87a61234cef1122089de943b946b1b6cb7c0d57.zip |
update scan
Diffstat (limited to 'script/workspace')
-rw-r--r-- | script/workspace/workspace.lua | 67 |
1 files changed, 30 insertions, 37 deletions
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index fe709453..c493823d 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -34,34 +34,32 @@ function m.init(uri) log.init(ROOT, logPath) end -local function interfaceFactory(root) - return { - type = function (path) - local result - pcall(function () - if fs.is_directory(path) then - result = 'directory' - else - result = 'file' - end - end) - return result - end, - list = function (path) - local fullPath = fs.path(root .. '/' .. path) - if not fs.exists(fullPath) then - return nil +local globInteferFace = { + type = function (path) + local result + pcall(function () + if fs.is_directory(fs.path(path)) then + result = 'directory' + else + result = 'file' end - local paths = {} - pcall(function () - for fullpath in fullPath:list_directory() do - paths[#paths+1] = fullpath:string() - end - end) - return paths + end) + return result + end, + list = function (path) + local fullPath = fs.path(path) + if not fs.exists(fullPath) then + return nil end - } -end + local paths = {} + pcall(function () + for fullpath in fullPath:list_directory() do + paths[#paths+1] = fullpath:string() + end + end) + return paths + end +} --- 创建排除文件匹配器 function m.getNativeMatcher() @@ -72,7 +70,6 @@ function m.getNativeMatcher() return m.nativeMatcher end - local interface = interfaceFactory(m.path) local pattern = {} -- config.workspace.ignoreDir for path in pairs(config.config.workspace.ignoreDir) do @@ -123,7 +120,7 @@ function m.getNativeMatcher() pattern[#pattern+1] = path end - m.nativeMatcher = glob.gitignore(pattern, m.matchOption, interface) + m.nativeMatcher = glob.gitignore(pattern, m.matchOption, globInteferFace) m.nativeVersion = config.version return m.nativeMatcher @@ -146,7 +143,7 @@ function m.getLibraryMatchers() for path, pattern in pairs(librarys) do if fs.exists(fs.path(path)) then local nPath = fs.absolute(fs.path(path)):string() - local matcher = glob.gitignore(pattern, m.matchOption) + local matcher = glob.gitignore(pattern, m.matchOption, globInteferFace) if platform.OS == 'Windows' then matcher:setOption 'ignoreCase' end @@ -174,7 +171,7 @@ end local function loadFileFactory(root, progress, isLibrary) return function (path) - local uri = furi.encode(root .. '/' .. path) + local uri = furi.encode(path) if not files.isLua(uri) then return end @@ -252,15 +249,11 @@ function m.awaitPreload() local native = m.getNativeMatcher() local librarys = m.getLibraryMatchers() if native then - native:scan(nativeLoader) + native:scan(m.path, nativeLoader) end for _, library in ipairs(librarys) do - local libraryInterface = interfaceFactory(library.path) - local libraryLoader = loadFileFactory(library.path, progress, true) - for k, v in pairs(libraryInterface) do - library.matcher:setInterface(k, v) - end - library.matcher:scan(libraryLoader) + local libraryLoader = loadFileFactory(library.path, progress, true) + library.matcher:scan(library.path, libraryLoader) end log.info(('Found %d files.'):format(progress.max)) |