summaryrefslogtreecommitdiff
path: root/lua/lvim/core/mason.lua
blob: bf46cb97c645cc4e665b2ceaaed470a328bbbc47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
local M = {}

local join_paths = require("lvim.utils").join_paths

function M.config()
  lvim.builtin.mason = {
    ui = {
      border = "rounded",
      keymaps = {
        toggle_package_expand = "<CR>",
        install_package = "i",
        update_package = "u",
        check_package_version = "c",
        update_all_packages = "U",
        check_outdated_packages = "C",
        uninstall_package = "X",
        cancel_installation = "<C-c>",
        apply_language_filter = "<C-f>",
      },
    },

    -- NOTE: should be available in $PATH
    install_root_dir = join_paths(vim.fn.stdpath "data", "mason"),

    -- NOTE: already handled in the bootstrap stage
    PATH = "skip",

    pip = {
      -- These args will be added to `pip install` calls. Note that setting extra args might impact intended behavior
      -- and is not recommended.
      --
      -- Example: { "--proxy", "https://proxyserver" }
      install_args = {},
    },

    -- Controls to which degree logs are written to the log file. It's useful to set this to vim.log.levels.DEBUG when
    -- debugging issues with package installations.
    log_level = vim.log.levels.INFO,

    -- Limit for the maximum amount of packages to be installed at the same time. Once this limit is reached, any further
    -- packages that are requested to be installed will be put in a queue.
    max_concurrent_installers = 4,

    github = {
      -- The template URL to use when downloading assets from GitHub.
      -- The placeholders are the following (in order):
      -- 1. The repository (e.g. "rust-lang/rust-analyzer")
      -- 2. The release version (e.g. "v0.3.0")
      -- 3. The asset name (e.g. "rust-analyzer-v0.3.0-x86_64-unknown-linux-gnu.tar.gz")
      download_url_template = "https://github.com/%s/releases/download/%s/%s",
    },
    null_ls = {
      ensure_installed = {},
      automatic_installation = false,
      automatic_setup = true,
    },
    dap = {
      ensure_installed = {},
      automatic_installation = false,
      automatic_setup = true,
    },
  }
end

function M.get_prefix()
  local default_prefix = join_paths(vim.fn.stdpath "data", "mason")
  return vim.tbl_get(lvim.builtin, "mason", "install_root_dir") or default_prefix
end

---@param append boolean|nil whether to append to prepend to PATH
local function add_to_path(append)
  local p = join_paths(M.get_prefix(), "bin")
  if vim.env.PATH:match(p) then
    return
  end
  local string_separator = vim.loop.os_uname().version:match "Windows" and ";" or ":"
  if append then
    vim.env.PATH = vim.env.PATH .. string_separator .. p
  else
    vim.env.PATH = p .. string_separator .. vim.env.PATH
  end
end

function M.bootstrap()
  add_to_path()
end

function M.setup()
  local status_ok, mason = pcall(reload, "mason")
  if not status_ok then
    return
  end
  local mason_null_ls_ok, mason_null_ls = pcall(reload, "mason-null-ls")
  if not mason_null_ls_ok then
    return
  end

  add_to_path(lvim.builtin.mason.PATH == "append")

  mason.setup(lvim.builtin.mason)
  mason_null_ls.setup(lvim.builtin.mason.null_ls)
  if lvim.builtin.mason.null_ls.automatic_setup then
    mason_null_ls.setup_handlers()
  end

  -- local mason_dap_ok, mason_dap = pcall(reload, "mason-nvim-dap")
  -- if mason_dap_ok then
  --   mason_dap.setup()
  --   if lvim.builtin.mason.dap.automatic_setup then
  --     mason_dap.setup_handlers()
  --   end
  -- end
end

return M