From 567800e9f5e5623640e3b99d2f22633c1d0a9206 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Fri, 11 Oct 2024 14:06:46 -0500 Subject: fix(nvim): remove mason custom registry --- nvim/.config/nvim/lua/custom-registry/init.lua | 3 -- .../lua/custom-registry/packages/mdformat-gfm.lua | 12 ------- nvim/.config/nvim/lua/plugins/mason.lua | 38 ++++++++++++++++++---- 3 files changed, 32 insertions(+), 21 deletions(-) delete mode 100644 nvim/.config/nvim/lua/custom-registry/init.lua delete mode 100644 nvim/.config/nvim/lua/custom-registry/packages/mdformat-gfm.lua (limited to 'nvim') diff --git a/nvim/.config/nvim/lua/custom-registry/init.lua b/nvim/.config/nvim/lua/custom-registry/init.lua deleted file mode 100644 index a304a76..0000000 --- a/nvim/.config/nvim/lua/custom-registry/init.lua +++ /dev/null @@ -1,3 +0,0 @@ -return { - ["mdformat-gfm"] = "custom-registry.packages.mdformat-gfm", -} diff --git a/nvim/.config/nvim/lua/custom-registry/packages/mdformat-gfm.lua b/nvim/.config/nvim/lua/custom-registry/packages/mdformat-gfm.lua deleted file mode 100644 index 4d7325a..0000000 --- a/nvim/.config/nvim/lua/custom-registry/packages/mdformat-gfm.lua +++ /dev/null @@ -1,12 +0,0 @@ -local Pkg = require("mason-core.package") -local pip3 = require("mason-core.managers.pip3") - -return Pkg.new({ - name = "mdformat-gfm", - desc = "Mdformat plugin for GitHub Flavored Markdown compatibility.", - homepage = "https://github.com/hukkin/mdformat-gfm/", - licenses = { "MIT" }, - languages = { Pkg.Lang.Markdown }, - categories = { Pkg.Cat.Formatter }, - install = pip3.packages({ "mdformat-gfm", bin = { "mdformat" } }), -}) diff --git a/nvim/.config/nvim/lua/plugins/mason.lua b/nvim/.config/nvim/lua/plugins/mason.lua index 28833de..fe323f7 100644 --- a/nvim/.config/nvim/lua/plugins/mason.lua +++ b/nvim/.config/nvim/lua/plugins/mason.lua @@ -4,12 +4,6 @@ local M = { build = ":MasonUpdate", lazy = false, opts = { - registries = { - -- TODO: remove once mdformat-gfm is added to official registry - -- Ref: https://github.com/mason-org/mason-registry/pull/3900 - "lua:custom-registry", - "github:mason-org/mason-registry", - }, ui = { border = "single", icons = { @@ -21,4 +15,36 @@ local M = { }, } +---Install python package using pip +---@param package Package Mason base package +---@param module string Python module to install +---@return fun() +local function pip_install(package, module) + return vim.schedule_wrap(function() + local res = vim.system({ + vim.fs.joinpath(package:get_install_path(), "venv/bin/python"), + "-m", + "pip", + "install", + module, + }, { text = true }):wait() + if res.code == 0 then + local msg = string.format([["%s" was successfully installed.]], module) + vim.notify(msg, vim.log.levels.INFO, { title = "mason.nvim" }) + else + local msg = string.format([[Could not install "%s"]], module) + vim.notify(msg, vim.log.levels.ERROR, { title = "mason.nvim" }) + error(res.stderr) + end + end) +end + +function M:config(opts) + require("mason").setup(opts) + require("mason-registry").refresh(function() + local mdformat = require("mason-registry").get_package("mdformat") + mdformat:on("install:success", pip_install(mdformat, "mdformat-gfm")) + end) +end + return M -- cgit v1.2.3-70-g09d2