diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-07 00:48:13 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-07 00:48:13 +0800 |
commit | d4281c472d88b4c69ea1f2c76703a974aca940c2 (patch) | |
tree | 6629c274f390f4e2f61a38fd57fba9d7096bf8f8 /script | |
parent | 7c9503e0f1d2566a9a6df9f5c309af48972cabb3 (diff) | |
download | lua-language-server-d4281c472d88b4c69ea1f2c76703a974aca940c2.zip |
more `bee.filesystem`
Diffstat (limited to 'script')
-rw-r--r-- | script/files.lua | 6 | ||||
-rw-r--r-- | script/filewatch.lua | 6 | ||||
-rw-r--r-- | script/fs-utility.lua | 22 | ||||
-rw-r--r-- | script/meta/bee/filesystem.lua | 73 |
4 files changed, 85 insertions, 22 deletions
diff --git a/script/files.lua b/script/files.lua index f3a11185..1961a4d4 100644 --- a/script/files.lua +++ b/script/files.lua @@ -56,11 +56,11 @@ local uriMap = {} function m.getRealUri(uri) local filename = furi.decode(uri) local path = fs.path(filename) - local suc, res = pcall(fs.exists, path) - if not suc or not res then + local suc, exsits = pcall(fs.exists, path) + if not suc or not exsits then return uri end - suc, res = pcall(fs.canonical, path) + local suc, res = pcall(fs.canonical, path) if not suc then return uri end diff --git a/script/filewatch.lua b/script/filewatch.lua index 5e3a0322..1d75d1b3 100644 --- a/script/filewatch.lua +++ b/script/filewatch.lua @@ -7,11 +7,11 @@ local RENAME = 1 << 1 local function exists(filename) local path = fs.path(filename) - local suc, res = pcall(fs.exists, path) - if not suc or not res then + local suc, exsits = pcall(fs.exists, path) + if not suc or not exsits then return false end - suc, res = pcall(fs.canonical, path) + local suc, res = pcall(fs.canonical, path) if not suc or res:string() ~= path:string() then return false end diff --git a/script/fs-utility.lua b/script/fs-utility.lua index fec862e2..b789177c 100644 --- a/script/fs-utility.lua +++ b/script/fs-utility.lua @@ -16,7 +16,7 @@ _ENV = nil ---@class fs-utility local m = {} --- 读取文件 ----@param path string|fspath +---@param path string|fs.path function m.loadFile(path, keepBom) if type(path) ~= 'string' then ---@diagnostic disable-next-line: undefined-field @@ -256,9 +256,9 @@ function dfs:saveFile(path, text) dir[filename] = text end ----@param path string|fspath +---@param path string|fs.path ---@param option table ----@return fspath? +---@return fs.path? local function fsAbsolute(path, option) if type(path) == 'string' then local suc, res = pcall(fs.path, path) @@ -448,8 +448,8 @@ local function fileRemove(path, option) end end ----@param source fspath? ----@param target fspath? +---@param source fs.path? +---@param target fs.path? ---@param option table local function fileCopy(source, target, option) if not source or not target then @@ -484,8 +484,8 @@ local function fileCopy(source, target, option) end end ----@param source fspath? ----@param target fspath? +---@param source fs.path? +---@param target fs.path? ---@param option table local function fileSync(source, target, option) if not source or not target then @@ -593,8 +593,8 @@ function m.fileRemove(path, option) end --- 复制文件(夹) ----@param source string|fspath ----@param target string|fspath +---@param source string|fs.path +---@param target string|fs.path ---@return table function m.fileCopy(source, target, option) option = buildOption(option) @@ -607,8 +607,8 @@ function m.fileCopy(source, target, option) end --- 同步文件(夹) ----@param source string|fspath ----@param target string|fspath +---@param source string|fs.path +---@param target string|fs.path ---@return table function m.fileSync(source, target, option) option = buildOption(option) diff --git a/script/meta/bee/filesystem.lua b/script/meta/bee/filesystem.lua index 54c17c37..f6cdff79 100644 --- a/script/meta/bee/filesystem.lua +++ b/script/meta/bee/filesystem.lua @@ -1,12 +1,12 @@ ----@class fspath ----@operator div: fspath +---@class fs.path +---@operator div: fs.path local fsPath = {} ---@return string function fsPath:string() end ----@return fspath +---@return fs.path function fsPath:parent_path() end @@ -14,15 +14,78 @@ end function fsPath:is_relative() end ----@return fspath +---@return fs.path function fsPath:filename() end +---@class fs.status +local fsStatus = {} + +---@return string +function fsStatus:type() +end + +---@class fs local fs = {} +---@class fs.copy_options +---@field overwrite_existing integer +local copy_options + +fs.copy_options = copy_options + ---@param path string ----@return fspath +---@return fs.path function fs.path(path) end +---@return fs.path +function fs.exe_path() +end + +---@param path fs.path +---@return boolean +function fs.exists(path) +end + +---@param path fs.path +---@return boolean +function fs.is_directory(path) +end + +---@param path fs.path +---@return fun():fs.path +function fs.pairs(path) +end + +---@param path fs.path +---@return fs.path +function fs.canonical(path) +end + +---@param path fs.path +---@return fs.path +function fs.absolute(path) +end + +---@param path fs.path +function fs.create_directories(path) +end + +---@param path fs.path +---@return fs.status +function fs.symlink_status(path) +end + +---@param path fs.path +---@return boolean +function fs.remove(path) +end + +---@param source fs.path +---@param target fs.path +---@param options? `fs.copy_options.overwrite_existing` +function fs.copy_file(source, target, options) +end + return fs |