From 882a4449e5a2e81f5441d837d74d356e03617660 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sun, 19 May 2024 13:22:23 +0200 Subject: [PATCH] feat: Add config opt 'ignore_install' This option allows the caller to define a list of conform formatters that should be ignored during the install process. This might be useful if the caller already have this tools installed and prefer not to have them downloaded again by mason. --- README.md | 4 +++- lua/mason-conform/auto_install.lua | 8 ++++++++ lua/mason-conform/init.lua | 12 ++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e127521..bedc80f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,9 @@ access the mason registry. # Configuration ```lua -require("mason-conform").setup() +require("mason-conform").setup({ + ignore_install = {'prettier'} -- List of formatters to ignore during install +}) ``` # Available formatters diff --git a/lua/mason-conform/auto_install.lua b/lua/mason-conform/auto_install.lua index 22d6aa9..be386ca 100644 --- a/lua/mason-conform/auto_install.lua +++ b/lua/mason-conform/auto_install.lua @@ -2,6 +2,7 @@ local registry = require("mason-registry") local mapping = require("mason-conform.mapping") local function auto_install() + local config = require("mason-conform").config local formatters_by_ft = require("conform").formatters_by_ft; local formatters_to_install = {} @@ -19,6 +20,13 @@ local function auto_install() end end + -- Filter out formatters that the user wants to ignore + for _, formatter_to_ignore in pairs(config.ignore_install) do + formatters_to_install[formatter_to_ignore] = nil + end + + print(vim.inspect(formatters_to_install)) + for conformFormatter, _ in pairs(formatters_to_install) do local package = mapping.conform_to_package[conformFormatter] if package ~= nil then diff --git a/lua/mason-conform/init.lua b/lua/mason-conform/init.lua index 8978775..ba3a954 100644 --- a/lua/mason-conform/init.lua +++ b/lua/mason-conform/init.lua @@ -1,7 +1,15 @@ local M = {} -function M.setup() - require "mason-conform.auto_install" () +M.config = { + ignore_install = {} +} + +function M.setup(cfg) + if cfg and cfg.ignore_install then + M.config.ignore_install = cfg.ignore_install + end + + require("mason-conform.auto_install")() end return M