mason.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. local M = {}
  2. local join_paths = require("lvim.utils").join_paths
  3. function M.config()
  4. lvim.builtin.mason = {
  5. ui = {
  6. check_outdated_packages_on_open = true,
  7. width = 0.8,
  8. height = 0.9,
  9. border = "rounded",
  10. keymaps = {
  11. toggle_package_expand = "<CR>",
  12. install_package = "i",
  13. update_package = "u",
  14. check_package_version = "c",
  15. update_all_packages = "U",
  16. check_outdated_packages = "C",
  17. uninstall_package = "X",
  18. cancel_installation = "<C-c>",
  19. apply_language_filter = "<C-f>",
  20. },
  21. },
  22. icons = {
  23. package_installed = "◍",
  24. package_pending = "◍",
  25. package_uninstalled = "◍",
  26. },
  27. -- NOTE: should be available in $PATH
  28. install_root_dir = join_paths(vim.fn.stdpath "data", "mason"),
  29. -- NOTE: already handled in the bootstrap stage
  30. PATH = "skip",
  31. pip = {
  32. upgrade_pip = false,
  33. -- These args will be added to `pip install` calls. Note that setting extra args might impact intended behavior
  34. -- and is not recommended.
  35. --
  36. -- Example: { "--proxy", "https://proxyserver" }
  37. install_args = {},
  38. },
  39. -- Controls to which degree logs are written to the log file. It's useful to set this to vim.log.levels.DEBUG when
  40. -- debugging issues with package installations.
  41. log_level = vim.log.levels.INFO,
  42. -- Limit for the maximum amount of packages to be installed at the same time. Once this limit is reached, any further
  43. -- packages that are requested to be installed will be put in a queue.
  44. max_concurrent_installers = 4,
  45. -- [Advanced setting]
  46. -- The registries to source packages from. Accepts multiple entries. Should a package with the same name exist in
  47. -- multiple registries, the registry listed first will be used.
  48. registries = {
  49. "lua:mason-registry.index",
  50. "github:mason-org/mason-registry",
  51. },
  52. -- The provider implementations to use for resolving supplementary package metadata (e.g., all available versions).
  53. -- Accepts multiple entries, where later entries will be used as fallback should prior providers fail.
  54. providers = {
  55. "mason.providers.registry-api",
  56. "mason.providers.client",
  57. },
  58. github = {
  59. -- The template URL to use when downloading assets from GitHub.
  60. -- The placeholders are the following (in order):
  61. -- 1. The repository (e.g. "rust-lang/rust-analyzer")
  62. -- 2. The release version (e.g. "v0.3.0")
  63. -- 3. The asset name (e.g. "rust-analyzer-v0.3.0-x86_64-unknown-linux-gnu.tar.gz")
  64. download_url_template = "https://github.com/%s/releases/download/%s/%s",
  65. },
  66. on_config_done = nil,
  67. }
  68. end
  69. function M.get_prefix()
  70. local default_prefix = join_paths(vim.fn.stdpath "data", "mason")
  71. return vim.tbl_get(lvim.builtin, "mason", "install_root_dir") or default_prefix
  72. end
  73. ---@param append boolean|nil whether to append to prepend to PATH
  74. local function add_to_path(append)
  75. local p = join_paths(M.get_prefix(), "bin")
  76. if vim.env.PATH:match(p) then
  77. return
  78. end
  79. local string_separator = vim.loop.os_uname().version:match "Windows" and ";" or ":"
  80. if append then
  81. vim.env.PATH = vim.env.PATH .. string_separator .. p
  82. else
  83. vim.env.PATH = p .. string_separator .. vim.env.PATH
  84. end
  85. end
  86. function M.bootstrap()
  87. add_to_path()
  88. end
  89. function M.setup()
  90. local status_ok, mason = pcall(require, "mason")
  91. if not status_ok then
  92. return
  93. end
  94. add_to_path(lvim.builtin.mason.PATH == "append")
  95. mason.setup(lvim.builtin.mason)
  96. if lvim.builtin.mason.on_config_done then
  97. lvim.builtin.mason.on_config_done(mason)
  98. end
  99. end
  100. return M