diff --git a/lua/glaze/init.lua b/lua/glaze/init.lua index 41d17e4..bb439dc 100644 --- a/lua/glaze/init.lua +++ b/lua/glaze/init.lua @@ -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 diff --git a/tests/run.lua b/tests/run.lua index b82de28..a65f015 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -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")