aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lua/mason-scripts/utils.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2025-05-19 07:56:31 +0200
committerGitHub <noreply@github.com>2025-05-19 07:56:31 +0200
commit1d6730459c42f591602500da994f01ae43a97dbc (patch)
treec78417dd383456d2ef8a00600375534d17a9cd45 /scripts/lua/mason-scripts/utils.lua
parentchore: fix references to williamboman/mason.nvim (#542) (diff)
downloadmason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar.gz
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar.bz2
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar.lz
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar.xz
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.tar.zst
mason-lspconfig-1d6730459c42f591602500da994f01ae43a97dbc.zip
perf: host pre-compiled filetype mappings (#555)
Generating the filetype mappings by accessing `vim.lsp.config` turns out to be a bad idea because: 1) performance 2) some `lsp/` configurations in nvim-lspconfig execute code immediately (see angularls) 3) accessing `vim.lsp.config[server_name]` seems to populate `:checkhealth vim.lsp`
Diffstat (limited to 'scripts/lua/mason-scripts/utils.lua')
-rw-r--r--scripts/lua/mason-scripts/utils.lua40
1 files changed, 40 insertions, 0 deletions
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