aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-core/path.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-07-08 18:34:38 +0200
committerGitHub <noreply@github.com>2022-07-08 18:34:38 +0200
commit976aa4fbee8a070f362cab6f6ec84e9251a90cf9 (patch)
tree5e8d9c9c59444a25c7801b8f39763c4ba6e1f76d /lua/mason-core/path.lua
parentfeat: add gotests, gomodifytags, impl (#28) (diff)
downloadmason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.gz
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.bz2
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.lz
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.xz
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.zst
mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.zip
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
Diffstat (limited to 'lua/mason-core/path.lua')
-rw-r--r--lua/mason-core/path.lua51
1 files changed, 51 insertions, 0 deletions
diff --git a/lua/mason-core/path.lua b/lua/mason-core/path.lua
new file mode 100644
index 00000000..2060c186
--- /dev/null
+++ b/lua/mason-core/path.lua
@@ -0,0 +1,51 @@
+local sep = (function()
+ ---@diagnostic disable-next-line: undefined-global
+ if jit then
+ ---@diagnostic disable-next-line: undefined-global
+ local os = string.lower(jit.os)
+ if os == "linux" or os == "osx" or os == "bsd" then
+ return "/"
+ else
+ return "\\"
+ end
+ else
+ return package.config:sub(1, 1)
+ end
+end)()
+
+local M = {}
+
+---@param path_components string[]
+---@return string
+function M.concat(path_components)
+ return table.concat(path_components, sep)
+end
+
+---@path root_path string
+---@path path string
+function M.is_subdirectory(root_path, path)
+ return root_path == path or path:sub(1, #root_path + 1) == root_path .. sep
+end
+
+---@param dir string|nil
+function M.install_prefix(dir)
+ local settings = require "mason.settings"
+ return M.concat { settings.current.install_root_dir, dir }
+end
+
+---@param executable string|nil
+function M.bin_prefix(executable)
+ return M.concat { M.install_prefix "bin", executable }
+end
+
+---@param name string|nil
+function M.package_prefix(name)
+ return M.concat { M.install_prefix "packages", name }
+end
+
+---@param name string|nil
+function M.package_build_prefix(name)
+ return M.concat { M.install_prefix ".packages", name }
+end
+
+return M