94 lines
2.5 KiB
Lua
94 lines
2.5 KiB
Lua
-- inspired by (and partially yoinked from): github.com/gonstoll/dotfiles
|
|
|
|
local notify = vim.notify
|
|
--- overidden version of vim.notify
|
|
---@param msg string message
|
|
---@param level vim.log.levels? log level
|
|
---@param opts table? options
|
|
---@diagnostic disable-next-line: duplicate-set-field
|
|
vim.notify = function(msg, level, opts)
|
|
notify(msg, level or vim.log.levels.INFO, opts or {
|
|
title = require("core.misc").appid
|
|
})
|
|
end
|
|
|
|
--- check if the given table contains an item, and return the key value pair if
|
|
--- it does
|
|
---@param self table table
|
|
---@param item any item to find
|
|
---@return boolean, [any, any]? found true if found
|
|
table.contains = function(self, item)
|
|
for k, v in pairs(self) do
|
|
if v == item then
|
|
return true, { k, v }
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
local M = {
|
|
misc = require("core.misc"),
|
|
lsp = require("core.lsp"),
|
|
color = require("core.color"),
|
|
snippets = vim.fs.joinpath(vim.fn.stdpath("config"), "lua/core/snippets.lua"),
|
|
}
|
|
|
|
M.mason = {
|
|
packages = {
|
|
formatters = { "black" },
|
|
daps = { "debugpy" },
|
|
lsps = {
|
|
"clangd",
|
|
"mesonlsp",
|
|
"bashls",
|
|
"lua_ls",
|
|
"jdtls",
|
|
"basedpyright"
|
|
}
|
|
},
|
|
|
|
--- Attempt to install all desired packages. This only really works on first
|
|
--- install as mason seems to not remove the paths of the things we uninstall
|
|
--- and instead just removes the code, leaving behind it's metadata.
|
|
ensure_installed = function()
|
|
local to_install = {}
|
|
|
|
for _, type in pairs(M.mason.packages) do
|
|
for _, pkg in ipairs(type) do
|
|
-- HACK: some servers don't have the same name in mason as they do in
|
|
-- the vim lsp, we use the vim lsp names, and therefore need to
|
|
-- convert them in here when they're incorrect for mason
|
|
if pkg == "bashls" then pkg = "bash-language-server"
|
|
elseif pkg == "lua_ls" then pkg = "lua-language-server"
|
|
end
|
|
|
|
if vim.fn.isdirectory(M.mason.get_pkg_path(pkg)) == 0 then
|
|
table.insert(to_install, pkg)
|
|
end
|
|
end
|
|
end
|
|
|
|
if #to_install > 0 then
|
|
vim.cmd.MasonInstall(to_install)
|
|
end
|
|
end,
|
|
|
|
--- Gets a path to a package in the Mason registry.
|
|
--- Prefer this to `get_package`, since the package might not always be
|
|
--- available yet and trigger errors.
|
|
---@param pkg string
|
|
---@param path? string
|
|
get_pkg_path = function(pkg, path)
|
|
pcall(require, "mason") -- make sure Mason is loaded. Will fail when
|
|
-- generating docs
|
|
|
|
local root = vim.env.MASON or vim.fs.joinpath(vim.fn.stdpath("data"),
|
|
"mason")
|
|
path = path or ""
|
|
return vim.fs.joinpath(root, "packages", pkg, path)
|
|
end
|
|
}
|
|
|
|
return M
|