Skip to content
Merged
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
9 changes: 8 additions & 1 deletion lua/glaze/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,18 @@ end

---@param opts? GlazeConfig
function M.setup(opts)
local should_detect_goenv = not opts or opts.go_cmd == nil
M.config = vim.tbl_deep_extend("force", M.config, opts or {})
M._ns = vim.api.nvim_create_namespace("glaze")

-- go_cmd is a list; replace it wholesale so index-wise deep merge cannot
-- leave stale trailing elements from a previous value.
if opts and opts.go_cmd ~= nil then
M.config.go_cmd = vim.deepcopy(opts.go_cmd)
end

-- Auto-detect goenv
if vim.fn.executable("goenv") == 1 then
if should_detect_goenv and vim.fn.executable("goenv") == 1 then
M.config.go_cmd = { "goenv", "exec", "go" }
end

Expand Down
59 changes: 59 additions & 0 deletions tests/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,65 @@ test("setup is idempotent and preserves updated config", function()
assert_truthy(vim.fn.exists(":GlazeCheck") == 2, "GlazeCheck command should exist")
end)

test("setup preserves explicit go command when goenv is installed", function()
local glaze = reset_glaze()
local original_executable = vim.fn.executable

vim.fn.executable = function(name)
if name == "goenv" then
return 1
end
return original_executable(name)
end

glaze.setup({
auto_check = { enabled = false },
go_cmd = { "custom-go", "wrapper" },
})
vim.fn.executable = original_executable

assert_eq(glaze.config.go_cmd[1], "custom-go", "explicit go command should not be replaced by goenv")
assert_eq(glaze.config.go_cmd[2], "wrapper", "explicit go command arguments should be preserved")
end)

test("setup auto-detects goenv when go command is omitted", function()
local glaze = reset_glaze()
local original_executable = vim.fn.executable

vim.fn.executable = function(name)
if name == "goenv" then
return 1
end
return original_executable(name)
end

glaze.setup({ auto_check = { enabled = false } })
vim.fn.executable = original_executable

assert_eq(glaze.config.go_cmd[1], "goenv", "omitted go command should use detected goenv")
assert_eq(glaze.config.go_cmd[2], "exec", "goenv command should include exec")
assert_eq(glaze.config.go_cmd[3], "go", "goenv command should run go")
end)

test("setup replaces goenv-detected go command wholesale on later explicit setup", function()
local glaze = reset_glaze()
local original_executable = vim.fn.executable

vim.fn.executable = function(name)
if name == "goenv" then
return 1
end
return original_executable(name)
end

glaze.setup({ auto_check = { enabled = false } })
glaze.setup({ go_cmd = { "go" } })
vim.fn.executable = original_executable

assert_eq(#glaze.config.go_cmd, 1, "explicit go command should not retain stale trailing elements")
assert_eq(glaze.config.go_cmd[1], "go", "explicit go command should be used verbatim")
end)

test("register batches auto-install requests into one install call", function()
local glaze = reset_glaze()
local runner = require("glaze.runner")
Expand Down
Loading