mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 20:55:18 -07:00
refactor(vim.fs): deduplicate by using vim.fn
Problem:61e99217e6
replaced usages of `vim.fn`. This duplicates non-trivial logic and may have introduced bugs like38e38d1b40
. Later on,b02eeb6a72
graduated `fnamemodify` to `fast`, so avoiding it in `vim.fs` is no longer necessary. Solution: - Use `vim.fn` to deduplicate logic and increase quality. - Use `nvim -l` instead of `nvim -ll` in the test runner.
This commit is contained in:
parent
845e563421
commit
8917da46e8
@ -68,7 +68,7 @@ endif()
|
||||
execute_process(
|
||||
# Note: because of "-ll" (low-level interpreter mode), some modules like
|
||||
# _editor.lua are not loaded.
|
||||
COMMAND ${NVIM_PRG} -ll ${WORKING_DIR}/test/lua_runner.lua ${DEPS_INSTALL_DIR} busted -v -o test.busted.outputHandlers.nvim
|
||||
COMMAND ${NVIM_PRG} -u NONE -l ${WORKING_DIR}/test/lua_runner.lua ${DEPS_INSTALL_DIR} busted -v -o test.busted.outputHandlers.nvim
|
||||
--lazy --helper=${TEST_DIR}/${TEST_TYPE}/preload.lua
|
||||
--lpath=${BUILD_DIR}/?.lua
|
||||
--lpath=${WORKING_DIR}/runtime/lua/?.lua
|
||||
|
@ -62,27 +62,8 @@ end
|
||||
---@param file T Path
|
||||
---@return T Parent directory of {file}
|
||||
function M.dirname(file)
|
||||
if file == nil then
|
||||
return nil
|
||||
end
|
||||
vim.validate('file', file, 'string')
|
||||
if iswin then
|
||||
file = file:gsub(os_sep, '/') --[[@as string]]
|
||||
if file:match('^%w:/?$') then
|
||||
return file
|
||||
end
|
||||
end
|
||||
if not file:match('/') then
|
||||
return '.'
|
||||
elseif file == '/' or file:match('^/[^/]+$') then
|
||||
return '/'
|
||||
end
|
||||
---@type string
|
||||
local dir = file:match('/$') and file:sub(1, #file - 1) or file:match('^(/?.+)/')
|
||||
if iswin and dir:match('^%w:$') then
|
||||
return dir .. '/'
|
||||
end
|
||||
return dir
|
||||
return vim.fn.fnamemodify(file, ':h')
|
||||
end
|
||||
|
||||
--- Return the basename of the given path
|
||||
@ -92,17 +73,8 @@ end
|
||||
---@param file T Path
|
||||
---@return T Basename of {file}
|
||||
function M.basename(file)
|
||||
if file == nil then
|
||||
return nil
|
||||
end
|
||||
vim.validate('file', file, 'string')
|
||||
if iswin then
|
||||
file = file:gsub(os_sep, '/') --[[@as string]]
|
||||
if file:match('^%w:/?$') then
|
||||
return ''
|
||||
end
|
||||
end
|
||||
return file:match('/$') and '' or (file:match('[^/]*$'))
|
||||
return vim.fn.fnamemodify(file, ':t')
|
||||
end
|
||||
|
||||
--- Concatenate directories and/or file paths into a single path with normalization
|
||||
|
Loading…
Reference in New Issue
Block a user