summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-02-04 16:08:54 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-02-04 16:08:54 +0800
commit4504ee2ff574ab378ecf70f0bbfc5f664012ef02 (patch)
treea6f443aa3ad6ae58a791f8dc494ac187db4cc930 /script
parent9ba615e2af45cfe98d59612eb058f78372aa2966 (diff)
downloadlua-language-server-4504ee2ff574ab378ecf70f0bbfc5f664012ef02.zip
improve peformance for scanning files
#1872
Diffstat (limited to 'script')
-rw-r--r--script/filewatch.lua7
-rw-r--r--script/glob/gitignore.lua6
-rw-r--r--script/meta/bee/filesystem.lua4
-rw-r--r--script/workspace/workspace.lua31
4 files changed, 36 insertions, 12 deletions
diff --git a/script/filewatch.lua b/script/filewatch.lua
index a95efe76..1ccb66ce 100644
--- a/script/filewatch.lua
+++ b/script/filewatch.lua
@@ -57,8 +57,11 @@ function m.watch(path, recursive, filter)
log.warn('Watching so many dirs:', count, dir:string())
end
end
- for fullpath in fs.pairs(dir) do
- if fs.is_directory(fullpath) then
+ for fullpath, status in fs.pairs(dir) do
+ local st = status:type()
+ if st == 'directory'
+ or st == 'symlink'
+ or st == 'junction' then
if not filter or filter(fullpath:string()) then
watch:add(fullpath:string())
log.trace('Watch add:', fullpath:string())
diff --git a/script/glob/gitignore.lua b/script/glob/gitignore.lua
index de8fd005..fef0a0d7 100644
--- a/script/glob/gitignore.lua
+++ b/script/glob/gitignore.lua
@@ -49,6 +49,7 @@ local parser = m.P {
---@field errors table[]
---@field matcher table
---@field interface function[]
+---@field data table
local mt = {}
mt.__index = mt
mt.__name = 'gitignore'
@@ -90,9 +91,9 @@ function mt:setInterface(key, func)
self.interface[key] = func
end
-function mt:callInterface(name, ...)
+function mt:callInterface(name, params)
local func = self.interface[name]
- return func(...)
+ return func(params, self.data)
end
function mt:hasInterface(name)
@@ -223,6 +224,7 @@ return function (pattern, options, interface)
matcher = {},
errors = {},
interface = {},
+ data = {},
}, mt)
if type(options) == 'table' then
diff --git a/script/meta/bee/filesystem.lua b/script/meta/bee/filesystem.lua
index 6190dac7..5ffeda4a 100644
--- a/script/meta/bee/filesystem.lua
+++ b/script/meta/bee/filesystem.lua
@@ -31,7 +31,7 @@ end
---@class fs.status
local fsStatus = {}
----@return string
+---@return 'none' | 'not_found' | 'regular' | 'directory' | 'symlink' | 'block' | 'character' | 'fifo' | 'junction' | 'unknown'
function fsStatus:type()
end
@@ -64,7 +64,7 @@ function fs.is_directory(path)
end
---@param path fs.path
----@return fun():fs.path
+---@return fun():fs.path, fs.status
function fs.pairs(path)
end
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index ad306beb..9d701167 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -84,26 +84,45 @@ function m.getRootUri(uri)
end
local globInteferFace = {
- type = function (path)
+ type = function (path, data)
+ if data[path] then
+ return data[path]
+ end
local result
pcall(function ()
- if fs.is_directory(path) then
+ if fs.is_directory(fs.path(path)) then
result = 'directory'
+ data[path] = 'directory'
else
result = 'file'
+ data[path] = 'file'
end
end)
return result
end,
- list = function (path)
+ list = function (path, data)
+ if data[path] == 'file' then
+ return nil
+ end
local fullPath = fs.path(path)
if not fs.is_directory(fullPath) then
+ data[path] = 'file'
return nil
end
+ data[path] = true
local paths = {}
pcall(function ()
- for fullpath in fs.pairs(fullPath) do
- paths[#paths+1] = fullpath:string()
+ for fullpath, status in fs.pairs(fullPath) do
+ local pathString = fullpath:string()
+ paths[#paths+1] = pathString
+ local st = status:type()
+ if st == 'directory'
+ or st == 'symlink'
+ or st == 'junction' then
+ data[pathString] = 'directory'
+ else
+ data[pathString] = 'file'
+ end
end
end)
return paths
@@ -225,7 +244,7 @@ function m.getLibraryMatchers(scp)
end
scp:set('libraryMatcher', matchers)
- log.debug('library matcher:', inspect(matchers))
+ --log.debug('library matcher:', inspect(matchers))
return matchers
end