Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: use nio.process.run instead of vim.system #251

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions lua/neotest-golang/lib/cmd.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--- Helper functions building the command to execute.

local async = require("neotest.async")
---@type nio
local nio = require("nio") -- require("neotest.async")

local logger = require("neotest-golang.logging")
local options = require("neotest-golang.options")
Expand All @@ -14,24 +15,32 @@ function M.golist_data(cwd)
local cmd = M.golist_command()
local go_list_command_concat = table.concat(cmd, " ")
logger.info("Running Go list: " .. go_list_command_concat .. " in " .. cwd)
local result = vim.system(cmd, { cwd = cwd, text = true }):wait()

local err = nil
if result.code == 1 then
err = "go list:"
if result.stdout ~= nil and result.stdout ~= "" then
err = err .. " " .. result.stdout
local task = nio.run(function()
local result = vim.system(cmd, { cwd = cwd, text = true }):wait()

local err = nil
if result.code == 1 then
err = "go list:"
if result.stdout ~= nil and result.stdout ~= "" then
err = err .. " " .. result.stdout
end
if result.stdout ~= nil and result.stderr ~= "" then
err = err .. " " .. result.stderr
end
logger.warn({ "Go list error: ", err })
end
if result.stdout ~= nil and result.stderr ~= "" then
err = err .. " " .. result.stderr
end
logger.warn({ "Go list error: ", err })
end

local output = result.stdout or ""
local output = result.stdout or ""

local golist_output = json.decode_from_string(output)
logger.debug({ "JSON-decoded 'go list' output: ", golist_output })

return golist_output, err
end)

local golist_output, err = task.wait()

local golist_output = json.decode_from_string(output)
logger.debug({ "JSON-decoded 'go list' output: ", golist_output })
return golist_output, err
end

Expand Down Expand Up @@ -91,7 +100,7 @@ function M.test_command(go_test_required_args)
if runner == "go" then
cmd = M.go_test(go_test_required_args)
elseif runner == "gotestsum" then
json_filepath = vim.fs.normalize(async.fn.tempname())
json_filepath = vim.fs.normalize(nio.fn.tempname())
cmd = M.gotestsum(go_test_required_args, json_filepath)
end

Expand Down
1 change: 1 addition & 0 deletions lua/neotest-golang/process.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--- This file is centered around the parsing/processing of test execution output
--- and assembling of the final results to hand back over to Neotest.

---@type nio
local async = require("neotest.async")

local logger = require("neotest-golang.logging")
Expand Down
Loading