mason.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. local M = {}
  2. local join_paths = require("lvim.utils").join_paths
  3. function M.config()
  4. lvim.builtin.mason = {
  5. ui = {
  6. border = "rounded",
  7. keymaps = {
  8. toggle_package_expand = "<CR>",
  9. install_package = "i",
  10. update_package = "u",
  11. check_package_version = "c",
  12. update_all_packages = "U",
  13. check_outdated_packages = "C",
  14. uninstall_package = "X",
  15. cancel_installation = "<C-c>",
  16. apply_language_filter = "<C-f>",
  17. },
  18. },
  19. -- NOTE: should be available in $PATH
  20. install_root_dir = join_paths(vim.fn.stdpath "data", "mason"),
  21. -- NOTE: already handled in the bootstrap stage
  22. PATH = "skip",
  23. pip = {
  24. -- These args will be added to `pip install` calls. Note that setting extra args might impact intended behavior
  25. -- and is not recommended.
  26. --
  27. -- Example: { "--proxy", "https://proxyserver" }
  28. install_args = {},
  29. },
  30. -- Controls to which degree logs are written to the log file. It's useful to set this to vim.log.levels.DEBUG when
  31. -- debugging issues with package installations.
  32. log_level = vim.log.levels.INFO,
  33. -- Limit for the maximum amount of packages to be installed at the same time. Once this limit is reached, any further
  34. -- packages that are requested to be installed will be put in a queue.
  35. max_concurrent_installers = 4,
  36. github = {
  37. -- The template URL to use when downloading assets from GitHub.
  38. -- The placeholders are the following (in order):
  39. -- 1. The repository (e.g. "rust-lang/rust-analyzer")
  40. -- 2. The release version (e.g. "v0.3.0")
  41. -- 3. The asset name (e.g. "rust-analyzer-v0.3.0-x86_64-unknown-linux-gnu.tar.gz")
  42. download_url_template = "https://github.com/%s/releases/download/%s/%s",
  43. },
  44. }
  45. end
  46. function M.get_prefix()
  47. local default_prefix = join_paths(vim.fn.stdpath "data", "mason")
  48. return vim.tbl_get(lvim.builtin, "mason", "install_root_dir") or default_prefix
  49. end
  50. ---@param append boolean|nil whether to append to prepend to PATH
  51. local function add_to_path(append)
  52. local p = join_paths(M.get_prefix(), "bin")
  53. if vim.env.PATH:match(p) then
  54. return
  55. end
  56. local string_separator = vim.loop.os_uname().version:match "Windows" and ";" or ":"
  57. if append then
  58. vim.env.PATH = vim.env.PATH .. string_separator .. p
  59. else
  60. vim.env.PATH = p .. string_separator .. vim.env.PATH
  61. end
  62. end
  63. function M.bootstrap()
  64. add_to_path()
  65. end
  66. function M.setup()
  67. local status_ok, mason = pcall(reload, "mason")
  68. if not status_ok then
  69. return
  70. end
  71. add_to_path(lvim.builtin.mason.PATH == "append")
  72. mason.setup(lvim.builtin.mason)
  73. end
  74. return M