aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lua')
-rw-r--r--scripts/lua/mason-scripts/mason-lspconfig/generate.lua42
-rw-r--r--scripts/lua/mason-scripts/utils.lua40
2 files changed, 82 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..75584aa
--- /dev/null
+++ b/scripts/lua/mason-scripts/mason-lspconfig/generate.lua
@@ -0,0 +1,42 @@
+local Optional = require "mason-core.optional"
+
+local _ = require "mason-core.functional"
+local a = require "mason-core.async"
+local path = require "mason-core.path"
+local script_utils = require "mason-scripts.utils"
+
+local MASON_LSPCONFIG_DIR = path.concat { "lua", "mason-lspconfig" }
+
+require("mason").setup()
+local registry = require "mason-registry"
+registry.refresh()
+
+---@async
+local function create_lspconfig_filetype_map()
+ local lspconfig_servers =
+ _.filter_map(_.compose(Optional.of_nilable, _.path { "neovim", "lspconfig" }), registry.get_all_package_specs())
+ ---@type table<string, string[]>
+ local filetype_map = {}
+
+ for _, server_name in ipairs(lspconfig_servers) do
+ local filetypes = vim.tbl_get(vim.lsp.config, server_name, "filetypes")
+ if filetypes then
+ for _, filetype in ipairs(filetypes) do
+ if not filetype_map[filetype] then
+ filetype_map[filetype] = {}
+ end
+ table.insert(filetype_map[filetype], server_name)
+ end
+ end
+ end
+
+ script_utils.write_file(
+ path.concat { MASON_LSPCONFIG_DIR, "filetype_mappings.lua" },
+ "return " .. vim.inspect(filetype_map),
+ "w"
+ )
+end
+
+a.run_blocking(function()
+ create_lspconfig_filetype_map()
+end)
diff --git a/scripts/lua/mason-scripts/utils.lua b/scripts/lua/mason-scripts/utils.lua
new file mode 100644
index 0000000..ee6ab10
--- /dev/null
+++ b/scripts/lua/mason-scripts/utils.lua
@@ -0,0 +1,40 @@
+local _ = require "mason-core.functional"
+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)
+ local header = _.cond({
+ {
+ _.matches "%.lua$",
+ _.always {
+ "-- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.",
+ "-- stylua: ignore start",
+ },
+ },
+ {
+ _.matches "%.md$",
+ _.always {
+ "<!--- THIS FILE IS GENERATED. DO NOT EDIT MANUALLY. -->",
+ },
+ },
+ {
+ _.matches "doc/.+%.txt$",
+ _.always {},
+ },
+ {
+ _.T,
+ _.always {
+ "# THIS FILE IS GENERATED. DO NOT EDIT MANUALLY.",
+ },
+ },
+ }, path)
+
+ fs.async.write_file(path, table.concat(_.concat(header, { contents }), "\n"), flags)
+end
+
+return M