From 976aa4fbee8a070f362cab6f6ec84e9251a90cf9 Mon Sep 17 00:00:00 2001 From: William Boman Date: Fri, 8 Jul 2022 18:34:38 +0200 Subject: refactor: add mason-schemas and mason-core modules (#29) * refactor: add mason-schemas and move generated filetype map to mason-lspconfig * refactor: add mason-core module --- lua/mason-core/managers/dotnet/init.lua | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 lua/mason-core/managers/dotnet/init.lua (limited to 'lua/mason-core/managers/dotnet/init.lua') diff --git a/lua/mason-core/managers/dotnet/init.lua b/lua/mason-core/managers/dotnet/init.lua new file mode 100644 index 00000000..f89d61ca --- /dev/null +++ b/lua/mason-core/managers/dotnet/init.lua @@ -0,0 +1,64 @@ +local process = require "mason-core.process" +local installer = require "mason-core.installer" +local _ = require "mason-core.functional" +local platform = require "mason-core.platform" + +local M = {} + +local create_bin_path = _.if_else(_.always(platform.is.win), _.format "%s.exe", _.identity) + +---@param package string +local function with_receipt(package) + return function() + local ctx = installer.context() + ctx.receipt:with_primary_source(ctx.receipt.dotnet(package)) + end +end + +---@async +---@param pkg string +---@param opt { bin: string[] | nil } | nil +function M.package(pkg, opt) + return function() + return M.install(pkg, opt).with_receipt() + end +end + +---@async +---@param pkg string +---@param opt { bin: string[] | nil } | nil +function M.install(pkg, opt) + local ctx = installer.context() + ctx.spawn.dotnet { + "tool", + "update", + "--tool-path", + ".", + ctx.requested_version + :map(function(version) + return { "--version", version } + end) + :or_else(vim.NIL), + pkg, + } + + if opt and opt.bin then + if opt.bin then + _.each(function(executable) + ctx:link_bin(executable, create_bin_path(executable)) + end, opt.bin) + end + end + + return { + with_receipt = with_receipt(pkg), + } +end + +function M.env(root_dir) + return { + PATH = process.extend_path { root_dir }, + } +end + +return M -- cgit v1.2.3-70-g09d2