mason.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. null_ls = {
  45. ensure_installed = {},
  46. automatic_installation = false,
  47. automatic_setup = true,
  48. },
  49. dap = {
  50. ensure_installed = {},
  51. automatic_installation = false,
  52. automatic_setup = true,
  53. },
  54. }
  55. end
  56. function M.get_prefix()
  57. local default_prefix = join_paths(vim.fn.stdpath "data", "mason")
  58. return vim.tbl_get(lvim.builtin, "mason", "install_root_dir") or default_prefix
  59. end
  60. ---@param append boolean|nil whether to append to prepend to PATH
  61. local function add_to_path(append)
  62. local p = join_paths(M.get_prefix(), "bin")
  63. if vim.env.PATH:match(p) then
  64. return
  65. end
  66. local string_separator = vim.loop.os_uname().version:match "Windows" and ";" or ":"
  67. if append then
  68. vim.env.PATH = vim.env.PATH .. string_separator .. p
  69. else
  70. vim.env.PATH = p .. string_separator .. vim.env.PATH
  71. end
  72. end
  73. function M.bootstrap()
  74. add_to_path()
  75. end
  76. function M.setup()
  77. local status_ok, mason = pcall(reload, "mason")
  78. if not status_ok then
  79. return
  80. end
  81. local mason_null_ls_ok, mason_null_ls = pcall(reload, "mason-null-ls")
  82. if not mason_null_ls_ok then
  83. return
  84. end
  85. add_to_path(lvim.builtin.mason.PATH == "append")
  86. mason.setup(lvim.builtin.mason)
  87. mason_null_ls.setup(lvim.builtin.mason.null_ls)
  88. if lvim.builtin.mason.null_ls.automatic_setup then
  89. mason_null_ls.setup_handlers()
  90. end
  91. -- local mason_dap_ok, mason_dap = pcall(reload, "mason-nvim-dap")
  92. -- if mason_dap_ok then
  93. -- mason_dap.setup()
  94. -- if lvim.builtin.mason.dap.automatic_setup then
  95. -- mason_dap.setup_handlers()
  96. -- end
  97. -- end
  98. end
  99. return M