aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core/installer/location.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-10-13 01:53:41 +0200
committerWilliam Boman <william@redwill.se>2025-02-19 09:23:19 +0100
commitf1e58d3ce7ab3bdb3036b791811896a0220703ad (patch)
treece44529583dcf72844b206fe8578f0ada5ef153f /lua/mason-core/installer/location.lua
parentrefactor(installer): move initializations to InstallContext constructor (diff)
downloadmason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar
mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar.gz
mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar.bz2
mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar.lz
mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar.xz
mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.tar.zst
mason-f1e58d3ce7ab3bdb3036b791811896a0220703ad.zip
refactor(path): use InstallLocation to produce paths, remove static path methods
Diffstat (limited to 'lua/mason-core/installer/location.lua')
-rw-r--r--lua/mason-core/installer/location.lua27
1 files changed, 25 insertions, 2 deletions
diff --git a/lua/mason-core/installer/location.lua b/lua/mason-core/installer/location.lua
index 694ae0f4..a77e2915 100644
--- a/lua/mason-core/installer/location.lua
+++ b/lua/mason-core/installer/location.lua
@@ -1,6 +1,5 @@
local Path = require "mason-core.path"
-local Result = require "mason-core.result"
-local fs = require "mason-core.fs"
+local platform = require "mason-core.platform"
local settings = require "mason.settings"
---@class InstallLocation
@@ -25,6 +24,9 @@ end
---@async
function InstallLocation:initialize()
+ local Result = require "mason-core.result"
+ local fs = require "mason-core.fs"
+
return Result.try(function(try)
for _, p in ipairs {
self.dir,
@@ -51,6 +53,11 @@ function InstallLocation:share(path)
end
---@param path string?
+function InstallLocation:opt(path)
+ return Path.concat { self.dir, "opt", path }
+end
+
+---@param path string?
function InstallLocation:package(path)
return Path.concat { self.dir, "packages", path }
end
@@ -65,4 +72,20 @@ function InstallLocation:lockfile(name)
return self:staging(("%s.lock"):format(name))
end
+---@param path string
+function InstallLocation:registry(path)
+ return Path.concat { self.dir, "registry", path }
+end
+
+---@param opts { PATH: '"append"' | '"prepend"' | '"skip"' }
+function InstallLocation:set_env(opts)
+ vim.env.MASON = self.dir
+
+ if opts.PATH == "prepend" then
+ vim.env.PATH = self:bin() .. platform.path_sep .. vim.env.PATH
+ elseif opts.PATH == "append" then
+ vim.env.PATH = vim.env.PATH .. platform.path_sep .. self:bin()
+ end
+end
+
return InstallLocation