mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 05:51:06 +00:00
fix(extras/prettier): run "prettier" command in a shell
...instead of running it directly, which fails for installations where "prettier" is a shell script (and not an executable)
This commit is contained in:
parent
c64a61734f
commit
3d12333b31
1 changed files with 15 additions and 3 deletions
|
|
@ -30,8 +30,14 @@ 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 res = vim
|
||||||
return vim.v.shell_error == 0
|
.system({
|
||||||
|
vim.o.sh,
|
||||||
|
vim.o.shcf,
|
||||||
|
"prettier --find-config-path " .. vim.fn.shellescape(ctx.filename),
|
||||||
|
}, { 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 +51,13 @@ 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 ret = vim
|
||||||
|
.system({
|
||||||
|
vim.o.sh,
|
||||||
|
vim.o.shcf,
|
||||||
|
"prettier --file-info " .. vim.fn.shellescape(ctx.filename),
|
||||||
|
}, { 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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue