This commit is contained in:
akioweh 2026-06-04 17:42:48 +00:00 committed by GitHub
commit dc6b4157d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -30,8 +30,11 @@ local supported = {
--- Checks if a Prettier config file exists for the given context --- Checks if a Prettier config file exists for the given context
---@param ctx ConformCtx ---@param ctx ConformCtx
function M.has_config(ctx) function M.has_config(ctx)
vim.fn.system({ "prettier", "--find-config-path", ctx.filename }) local args = { vim.o.sh }
return vim.v.shell_error == 0 vim.list_extend(args, vim.split(vim.o.shcf, " ", { trimempty = true }))
table.insert(args, "prettier --find-config-path " .. vim.fn.shellescape(ctx.filename))
local res = vim.system(args, { text = true }):wait()
return res.code == 0
end end
--- Checks if a parser can be inferred for the given context: --- Checks if a parser can be inferred for the given context:
@ -45,7 +48,10 @@ function M.has_parser(ctx)
return true return true
end end
-- otherwise, check if a parser can be inferred -- otherwise, check if a parser can be inferred
local ret = vim.fn.system({ "prettier", "--file-info", ctx.filename }) local args = { vim.o.sh }
vim.list_extend(args, vim.split(vim.o.shcf, " ", { trimempty = true }))
table.insert(args, "prettier --file-info " .. vim.fn.shellescape(ctx.filename))
local ret = vim.system(args, { text = true }):wait().stdout
---@type boolean, string? ---@type boolean, string?
local ok, parser = pcall(function() local ok, parser = pcall(function()
return vim.fn.json_decode(ret).inferredParser return vim.fn.json_decode(ret).inferredParser