From 7721205f6b8afc0dc6fa6f1f79d228c3714d6b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Thu, 3 Nov 2022 09:31:51 +0000 Subject: [PATCH] refactor: use vim.loop.cwd instead of vim.fn.getcwd --- lua/neotest/client/init.lua | 14 +++++++------- lua/neotest/consumers/summary/init.lua | 2 +- tests/unit/client/init_spec.lua | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lua/neotest/client/init.lua b/lua/neotest/client/init.lua index 1a8a0caf..69100c2d 100644 --- a/lua/neotest/client/init.lua +++ b/lua/neotest/client/init.lua @@ -384,7 +384,7 @@ function NeotestClient:_start(args) end) autocmd("DirChanged", function() - local dir = vim.fn.getcwd() + local dir = vim.loop.cwd() async.run(function() self:_update_adapters(dir) end) @@ -422,7 +422,7 @@ function NeotestClient:_start(args) end) end) - self:_update_adapters(async.fn.getcwd()) + self:_update_adapters(vim.loop.cwd()) local run_time = (vim.loop.now() - start) / 1000 logger.info("Initialisation finished in", run_time, "seconds") @@ -445,12 +445,12 @@ end function NeotestClient:_update_adapters(dir) local adapters_with_root = lib.files.is_dir(dir) and self._adapter_group:adapters_with_root_dir(dir) - or {} + or {} local adapters_with_bufs = - self._adapter_group:adapters_matching_open_bufs(lib.func_util.map(function(i, entry) - return i, entry.root - end, adapters_with_root)) + self._adapter_group:adapters_matching_open_bufs(lib.func_util.map(function(i, entry) + return i, entry.root + end, adapters_with_root)) local found = {} for adapter_id, _ in pairs(self._adapters) do @@ -470,7 +470,7 @@ function NeotestClient:_update_adapters(dir) end end end - local root = lib.files.is_dir(dir) and dir or async.fn.getcwd() + local root = lib.files.is_dir(dir) and dir or vim.loop.cwd() for _, adapter in ipairs(adapters_with_bufs) do local adapter_id = ("%s:%s"):format(adapter.name, root) if not found[adapter_id] then diff --git a/lua/neotest/consumers/summary/init.lua b/lua/neotest/consumers/summary/init.lua index d354bc6f..db778fed 100644 --- a/lua/neotest/consumers/summary/init.lua +++ b/lua/neotest/consumers/summary/init.lua @@ -74,7 +74,7 @@ async.run(function() if not client:has_started() then canvas:write("Parsing tests") else - local cwd = async.fn.getcwd() + local cwd = vim.loop.cwd() for _, adapter_id in ipairs(client:get_adapters()) do local tree = client:get_position(nil, { adapter = adapter_id }) canvas:write( diff --git a/tests/unit/client/init_spec.lua b/tests/unit/client/init_spec.lua index cf50725a..9a186d07 100644 --- a/tests/unit/client/init_spec.lua +++ b/tests/unit/client/init_spec.lua @@ -12,7 +12,7 @@ describe("neotest client", function() ---@type neotest.Adapter local mock_adapter local mock_strategy, attached, stopped, exit_test, provided_spec - local dir = async.fn.getcwd() + local dir = vim.loop.cwd() local files local dirs = { dir } ---@return neotest.Tree @@ -197,7 +197,6 @@ describe("neotest client", function() adapters = { mock_adapter }, discovery = { enabled = false }, }) - local x = get_pos(dir) assert.Nil(get_pos(dir)) assert.Nil(get_pos(dir .. "/test_file_1")) end)