mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 17:21:49 +00:00
feat(fs): extend fs.find to accept predicate (#20193)
Makes it possible to use `vim.fs.find` to find files where only a substring is known. This is useful for `vim.lsp.start` to get the `root_dir` for languages where the project-file is only known by its extension, not by the full name. For example in .NET projects there is usually a `<projectname>.csproj` file in the project root. Example: vim.fs.find(function(x) return vim.endswith(x, '.csproj') end, { upward = true })
This commit is contained in:

committed by
GitHub

parent
1970d2ac43
commit
a8c9e721d9
@@ -78,6 +78,23 @@ describe('vim.fs', function()
|
||||
return vim.fs.find(nvim, { path = dir, type = 'file' })
|
||||
]], test_build_dir, nvim_prog_basename))
|
||||
end)
|
||||
|
||||
it('accepts predicate as names', function()
|
||||
eq({test_build_dir}, exec_lua([[
|
||||
local dir = ...
|
||||
local opts = { path = dir, upward = true, type = 'directory' }
|
||||
return vim.fs.find(function(x) return x == 'build' end, opts)
|
||||
]], nvim_dir))
|
||||
eq({nvim_prog}, exec_lua([[
|
||||
local dir, nvim = ...
|
||||
return vim.fs.find(function(x) return x == nvim end, { path = dir, type = 'file' })
|
||||
]], test_build_dir, nvim_prog_basename))
|
||||
eq({}, exec_lua([[
|
||||
local dir = ...
|
||||
local opts = { path = dir, upward = true, type = 'directory' }
|
||||
return vim.fs.find(function(x) return x == 'no-match' end, opts)
|
||||
]], nvim_dir))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('normalize()', function()
|
||||
|
Reference in New Issue
Block a user