diff --git a/lua/lazyvim/plugins/extras/formatting/prettier.lua b/lua/lazyvim/plugins/extras/formatting/prettier.lua index a93f6ecf..3d9755e3 100644 --- a/lua/lazyvim/plugins/extras/formatting/prettier.lua +++ b/lua/lazyvim/plugins/extras/formatting/prettier.lua @@ -1,3 +1,16 @@ +if lazyvim_docs then + -- By default, prettier will only be used for formatting + -- if a prettier configuration file is found in the project. + -- Set to `false` to always use prettier for supported filetypes. + vim.g.lazyvim_prettier_needs_config = true +end + +local needs_config = vim.g.lazyvim_prettier_needs_config ~= false + +-- local check = vim.g.lazyvim_prettier + +local enabled = {} ---@type table + return { { "williamboman/mason.nvim", @@ -35,6 +48,22 @@ return { ["markdown.mdx"] = { "prettier" }, ["graphql"] = { "prettier" }, ["handlebars"] = { "prettier" }, + ["svelte"] = { "prettier" }, + }, + formatters = { + prettier = { + condition = function(_, ctx) + if not needs_config then + return true + end + if enabled[ctx.filename] == nil then + enabled[ctx.filename] = vim.fs.find(function(name, path) + return name:match("^%.prettierrc%.") or name:match("^prettier%.config%.") + end, { path = ctx.filename, upward = true })[1] ~= nil + end + return enabled[ctx.filename] + end, + }, }, }, }, diff --git a/lua/lazyvim/plugins/extras/lang/svelte.lua b/lua/lazyvim/plugins/extras/lang/svelte.lua index 33da0127..e7954137 100644 --- a/lua/lazyvim/plugins/extras/lang/svelte.lua +++ b/lua/lazyvim/plugins/extras/lang/svelte.lua @@ -58,14 +58,4 @@ return { }) end, }, - - -- { - -- "stevearc/conform.nvim", - -- optional = true, - -- opts = { - -- formatters_by_ft = { - -- ["svelte"] = { "prettier" }, - -- }, - -- }, - -- }, }