Skip to content

Commit dfe0088

Browse files
committed
fix(conform): evaluate function-form commands at probe time
Trusting a function-form command blindly as self-resolving let the prettier dep silently leave the install/warn contract: on a fresh machine with no node_modules copy and no global binary, nothing would ever install it or name it in the aggregated warning (a regression against main's ensure_installed loop). Evaluate the function against the probe-time buffer the way conform will: a project-local node_modules bin passes the $PATH check as-is, the bare-name fallback re-enters install/warn via the bin index, and a failed or non-string evaluation degrades to the previous self-resolving behavior — never a typo report.
1 parent 42a27f8 commit dfe0088

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

lua/modules/configs/completion/conform.lua

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,23 @@ return function()
189189
return { broken = tostring(config) }
190190
end
191191
if config then
192-
-- A function-form command resolves per buffer at format time (e.g. the
193-
-- builtin from_node_modules): treat it as self-resolving rather than
194-
-- evaluating it for a representative binary — a node_modules command
195-
-- shouldn't map to a Mason install anyway.
192+
-- A function-form command (the builtin from_node_modules) resolves per
193+
-- buffer at format time, so evaluate it against the probe-time buffer
194+
-- the same way conform will: a project-local node_modules bin passes
195+
-- the $PATH check as-is, and the bare-name FALLBACK ("prettier") keeps
196+
-- the dep inside the install/warn contract — trusting the function
197+
-- blindly would let a fresh machine with no copy anywhere silently
198+
-- skip both the Mason install and the aggregated warning. A failed or
199+
-- non-string evaluation degrades to self-resolving (no install/warn),
200+
-- never to a typo report.
196201
if type(config.command) == "function" then
197-
return { binary = nil }
202+
local fname = vim.api.nvim_buf_get_name(0)
203+
local cmd_ok, cmd = pcall(config.command, config, {
204+
buf = vim.api.nvim_get_current_buf(),
205+
filename = fname,
206+
dirname = fname ~= "" and vim.fs.dirname(fname) or vim.fn.getcwd(),
207+
})
208+
return { binary = (cmd_ok and type(cmd) == "string" and cmd ~= "") and cmd or nil }
198209
end
199210
return { binary = config.command }
200211
end

0 commit comments

Comments
 (0)