mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
fix(fs): use generics for better typing
This commit is contained in:
@@ -2848,7 +2848,7 @@ vim.fs.basename({file}) *vim.fs.basename()*
|
|||||||
Return the basename of the given path
|
Return the basename of the given path
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {file} (`string`) Path
|
• {file} (`string?`) Path
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
(`string?`) Basename of {file}
|
(`string?`) Basename of {file}
|
||||||
@@ -2876,7 +2876,7 @@ vim.fs.dirname({file}) *vim.fs.dirname()*
|
|||||||
Return the parent directory of the given path
|
Return the parent directory of the given path
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {file} (`string`) Path
|
• {file} (`string?`) Path
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
(`string?`) Parent directory of {file}
|
(`string?`) Parent directory of {file}
|
||||||
|
@@ -39,8 +39,9 @@ end
|
|||||||
|
|
||||||
--- Return the parent directory of the given path
|
--- Return the parent directory of the given path
|
||||||
---
|
---
|
||||||
---@param file (string) Path
|
---@generic T : string|nil
|
||||||
---@return string|nil Parent directory of {file}
|
---@param file T Path
|
||||||
|
---@return T Parent directory of {file}
|
||||||
function M.dirname(file)
|
function M.dirname(file)
|
||||||
if file == nil then
|
if file == nil then
|
||||||
return nil
|
return nil
|
||||||
@@ -53,6 +54,7 @@ function M.dirname(file)
|
|||||||
elseif file == '/' or file:match('^/[^/]+$') then
|
elseif file == '/' or file:match('^/[^/]+$') then
|
||||||
return '/'
|
return '/'
|
||||||
end
|
end
|
||||||
|
---@type string
|
||||||
local dir = file:match('[/\\]$') and file:sub(1, #file - 1) or file:match('^([/\\]?.+)[/\\]')
|
local dir = file:match('[/\\]$') and file:sub(1, #file - 1) or file:match('^([/\\]?.+)[/\\]')
|
||||||
if iswin and dir:match('^%w:$') then
|
if iswin and dir:match('^%w:$') then
|
||||||
return dir .. '/'
|
return dir .. '/'
|
||||||
@@ -62,8 +64,9 @@ end
|
|||||||
|
|
||||||
--- Return the basename of the given path
|
--- Return the basename of the given path
|
||||||
---
|
---
|
||||||
---@param file string Path
|
---@generic T : string|nil
|
||||||
---@return string|nil Basename of {file}
|
---@param file T Path
|
||||||
|
---@return T Basename of {file}
|
||||||
function M.basename(file)
|
function M.basename(file)
|
||||||
if file == nil then
|
if file == nil then
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user