From 775e4252f0ac4f53c9ffd017ed08e04cc996948e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Mon, 12 Sep 2022 06:56:48 +0100 Subject: [PATCH] feat(adapters): provide filter_dir function See #13 --- lua/neotest/adapters/interface.lua | 7 +++++++ lua/neotest/client/init.lua | 11 ++++++++++- lua/neotest/lib/file/find.lua | 1 - 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lua/neotest/adapters/interface.lua b/lua/neotest/adapters/interface.lua index 108ecc22..3a59f5ae 100644 --- a/lua/neotest/adapters/interface.lua +++ b/lua/neotest/adapters/interface.lua @@ -9,6 +9,13 @@ local NeotestAdapter = {} ---@return string | nil @Absolute root dir of test suite function NeotestAdapter.root(dir) end +---Filter directories when searching for test files +---@async +---@param name string Name of directory +---@param rel_path string Path to directory, relative to root +---@param root string Root directory of project +function NeotestAdapter.filter_dir(name, rel_path, root) end + ---@async ---@param file_path string ---@return boolean diff --git a/lua/neotest/client/init.lua b/lua/neotest/client/init.lua index 42340e99..4eb7d238 100644 --- a/lua/neotest/client/init.lua +++ b/lua/neotest/client/init.lua @@ -244,7 +244,16 @@ function NeotestClient:_update_positions(path, args) local root_path = existing_root and existing_root:data().path or path local files = lib.func_util.filter_list( adapter.is_test_file, - lib.files.find(path, { filter_dir = config.projects[root_path].discovery.filter_dir }) + + lib.files.find(path, { + filter_dir = function(...) + return (not adapter.filter_dir or adapter.filter_dir(...)) + and ( + not config.projects[root_path].discovery.filter_dir + or config.projects[root_path].discovery.filter_dir(...) + ) + end, + }) ) local positions = lib.files.parse_dir_from_files(path, files) logger.debug("Found", positions) diff --git a/lua/neotest/lib/file/find.lua b/lua/neotest/lib/file/find.lua index 9af5291c..94913ddf 100644 --- a/lua/neotest/lib/file/find.lua +++ b/lua/neotest/lib/file/find.lua @@ -3,7 +3,6 @@ local M = {} local ignored = vim.tbl_add_reverse_lookup({ "node_modules", - "venv", }) --- Find all files under the given directory.