diff --git a/README.md b/README.md index 87ab70e..8700732 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,19 @@ require("neotest").setup({ }) ``` +## Using `.runsettings` files + +The plugin provides commands to select and clear the runsettings files (if any are available in the Neovim working director tree). + +To select the runsettings file in a Neovim session run: +`:NeotestSelectRunsettingsFile` + +- This will apply the runsettings to all tests run via the neotest-adapter + +To clear the runsettings file in the same session run: +`:NeotestClearRunsettings` + + ## Additional `dotnet test` arguments As well as the `dotnet_additional_args` option in the adapter setup above, you may also provide additional CLI arguments as a table to each `neotest` command. diff --git a/lua/neotest-dotnet/init.lua b/lua/neotest-dotnet/init.lua index 550ffef..8ff806b 100644 --- a/lua/neotest-dotnet/init.lua +++ b/lua/neotest-dotnet/init.lua @@ -188,6 +188,49 @@ setmetatable(DotnetNeotestAdapter, { if type(opts.discovery_root) == "string" then discovery_root = opts.discovery_root end + + local function find_runsettings_files() + local files = {} + for _, runsettingsFile in + ipairs(vim.fn.glob(vim.fn.getcwd() .. "**/*.runsettings", false, true)) + do + table.insert(files, runsettingsFile) + end + + for _, runsettingsFile in + ipairs(vim.fn.glob(vim.fn.getcwd() .. "**/.runsettings", false, true)) + do + table.insert(files, runsettingsFile) + end + + return files + end + + local function select_runsettings_file() + local files = find_runsettings_files() + if #files == 0 then + print("No .runsettings files found") + vim.g.neotest_dotnet_runsettings_path = nil + return + end + + vim.ui.select(files, { + prompt = "Select runsettings file:", + format_item = function(item) + return vim.fn.fnamemodify(item, ":p:.") + end, + }, function(choice) + if choice then + vim.g.neotest_dotnet_runsettings_path = choice + print("Selected runsettings file: " .. choice) + end + end) + end + + vim.api.nvim_create_user_command("NeotestSelectRunsettingsFile", select_runsettings_file, {}) + vim.api.nvim_create_user_command("NeotestClearRunsettings", function() + vim.g.neotest_dotnet_runsettings_path = nil + end, {}) return DotnetNeotestAdapter end, }) diff --git a/lua/neotest-dotnet/utils/build-spec-utils.lua b/lua/neotest-dotnet/utils/build-spec-utils.lua index e71ce34..b272dd0 100644 --- a/lua/neotest-dotnet/utils/build-spec-utils.lua +++ b/lua/neotest-dotnet/utils/build-spec-utils.lua @@ -47,6 +47,11 @@ function BuildSpecUtils.create_single_spec(position, proj_root, filter_arg, dotn end end + if vim.g.neotest_dotnet_runsettings_path then + table.insert(command, "--settings") + table.insert(command, vim.g.neotest_dotnet_runsettings_path) + end + local command_string = table.concat(command, " ") logger.debug("neotest-dotnet: Running tests using command: " .. command_string)