diff options
| author | William Boman <william@redwill.se> | 2022-07-21 14:15:11 +0200 |
|---|---|---|
| committer | William Boman <william@redwill.se> | 2022-07-22 03:03:23 +0200 |
| commit | 1d459b6d19118b9944d5313e4439cb361d607366 (patch) | |
| tree | d48a07eaa5fddebc75ade8bb1d3861992e0c11a3 /scripts | |
| download | mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar.gz mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar.bz2 mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar.lz mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar.xz mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.tar.zst mason-lspconfig-1d459b6d19118b9944d5313e4439cb361d607366.zip | |
init
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/lua/mason-scripts/mason-lspconfig/generate.lua | 54 | ||||
| -rw-r--r-- | scripts/lua/mason-scripts/utils.lua | 21 | ||||
| -rwxr-xr-x | scripts/nvim.sh | 14 |
3 files changed, 89 insertions, 0 deletions
diff --git a/scripts/lua/mason-scripts/mason-lspconfig/generate.lua b/scripts/lua/mason-scripts/mason-lspconfig/generate.lua new file mode 100644 index 0000000..66c2ba6 --- /dev/null +++ b/scripts/lua/mason-scripts/mason-lspconfig/generate.lua @@ -0,0 +1,54 @@ +local a = require "mason-core.async" +local path = require "mason-core.path" +local _ = require "mason-core.functional" +local lspconfig_server_mapping = require "mason-lspconfig.mappings.server" +local script_utils = require "mason-scripts.utils" + +local MASON_LSPCONFIG_DIR = path.concat { vim.loop.cwd(), "lua", "mason-lspconfig" } + +local function get_lspconfig(name) + return require(("lspconfig.server_configurations.%s"):format(name)) +end + +---@async +local function create_lspconfig_filetype_map() + local filetype_map = {} + + for _, server_name in ipairs(_.keys(lspconfig_server_mapping.lspconfig_to_package)) do + local config = get_lspconfig(server_name) + for _, filetype in ipairs(config.default_config.filetypes or {}) do + if not filetype_map[filetype] then + filetype_map[filetype] = {} + end + table.insert(filetype_map[filetype], server_name) + table.sort(filetype_map[filetype]) + end + end + + script_utils.write_file( + path.concat { MASON_LSPCONFIG_DIR, "mappings", "filetype.lua" }, + "return " .. vim.inspect(filetype_map), + "w" + ) +end + +---@async +local function ensure_valid_mapping() + local server_mappings = require "mason-lspconfig.mappings.server" + local registry = require "mason-registry" + + for lspconfig_server, mason_package in pairs(server_mappings.lspconfig_to_package) do + local lspconfig_ok, server_config = + pcall(require, ("lspconfig.server_configurations.%s"):format(lspconfig_server)) + local mason_ok, pkg = pcall(registry.get_package, mason_package) + assert(lspconfig_ok and server_config ~= nil, lspconfig_server .. " is not a valid lspconfig server name.") + assert(mason_ok and pkg ~= nil, mason_package .. " is not a valid Mason package name.") + end +end + +a.run_blocking(function() + a.wait_all { + create_lspconfig_filetype_map, + ensure_valid_mapping, + } +end) diff --git a/scripts/lua/mason-scripts/utils.lua b/scripts/lua/mason-scripts/utils.lua new file mode 100644 index 0000000..771d419 --- /dev/null +++ b/scripts/lua/mason-scripts/utils.lua @@ -0,0 +1,21 @@ +local fs = require "mason-core.fs" + +local M = {} + +---@async +---@param path string +---@param contents string +---@param flags string +function M.write_file(path, contents, flags) + fs.async.write_file( + path, + table.concat({ + "-- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.", + "-- stylua: ignore start", + contents, + }, "\n"), + flags + ) +end + +return M diff --git a/scripts/nvim.sh b/scripts/nvim.sh new file mode 100755 index 0000000..c2dcb6b --- /dev/null +++ b/scripts/nvim.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -exuo pipefail + +declare -x DEPENDENCIES="${PWD}/dependencies" +declare -x MASON_DIR="$PWD" +declare -x MASON_SCRIPT_DIR="${PWD}/scripts" + +nvim -u NONE -E -R --headless \ + --cmd "set rtp^=${MASON_SCRIPT_DIR},${MASON_DIR}" \ + --cmd "set packpath^=${DEPENDENCIES}" \ + --cmd "packloadall" \ + --cmd "luafile $1" \ + --cmd "q" |
