Something went wrong. Try again.
My own personal NeoVim configuration. Powered by vim.pack and lz.n
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224local plugins_loaded = falselocal function load_plugins() if plugins_loaded then return end plugins_loaded = true require("lz.n").trigger_load({ "blink.cmp", "nvim-lspconfig", "mason-lspconfig.nvim", "mason.nvim" })end
local servers_for = { lua = { "lua_ls" }, python = { "ty" }, sh = { "bashls" }, bash = { "bashls" }, zsh = { "bashls" }, toml = { "taplo" }, markdown = { "marksman" }, json = { "jsonls" }, jsonc = { "jsonls" }, yaml = { "yamlls" }, ["yaml.docker-compose"] = { "docker_compose_language_service", "yamlls" }, dockerfile = { "dockerls" }, just = { "just" }, vim = { "vimls" }, c = { "clangd" }, cpp = { "clangd" }, go = { "gopls" }, zig = { "zls" },
html = { "html", "tailwindcss" }, css = { "cssls", "tailwindcss" }, scss = { "cssls", "tailwindcss" }, javascript = { "vtsls", "tailwindcss" }, javascriptreact = { "vtsls", "tailwindcss" }, typescript = { "vtsls", "tailwindcss" }, typescriptreact = { "vtsls", "tailwindcss" }, svelte = { "svelte", "tailwindcss" }, vue = { "vue_ls", "vtsls", "tailwindcss" },}
local not_real_servers = { ast_grep = true, codebook = true, harper_ls = true, snyk_ls = true, ltex = true, ltex_plus = true, vale_ls = true, typos_lsp = true, grammarly = true, dprint = true, oxfmt = true, biome = true, stylelint_lsp = true, htmx = true, unocss = true, emmet_ls = true, emmet_language_server = true, spectral = true, symfony_lsp = true, shuck = true, stylua = true, tsc = true, tailwindcss = true, prosemd_lsp = true, zk = true, mpls = true, rumdl = true, panache = true,}
local rust_ft = "rust"local rust_package = "rust-analyzer"
local state = {}
local function say(msg, level) vim.notify("[auto-install] " .. msg, level or vim.log.levels.INFO)end
local function mason_package(server) local ok, registry = pcall(require, "mason-registry") if not ok then return nil end local map = require("mason-lspconfig.mappings").get_mason_map().lspconfig_to_package local pkg_name = map[server] if not pkg_name then return nil end local found, pkg = pcall(registry.get_package, pkg_name) return found and pkg or nilend
local function ensure_installed(pkg, label, done) if pkg:is_installed() then return done(true) end say("installing " .. label .. " ...") pkg:install( {}, vim.schedule_wrap(function(success) if success then say(label .. " installed") else say(label .. " failed to install, see :Mason and :MasonLog", vim.log.levels.WARN) end done(success) end) )end
local function start_server(server) vim.lsp.enable(server) state[server] = "ready"end
local function handle_server(server) if state[server] then return end
local cmd = vim.lsp.config[server] and vim.lsp.config[server].cmd if type(cmd) == "table" and vim.fn.executable(cmd[1]) == 1 then return start_server(server) end local pkg = mason_package(server) if not pkg then return end state[server] = "installing" ensure_installed(pkg, server, function(ok) if ok then start_server(server) else state[server] = "failed" end end)end
local function servers_for_filetype(ft) if servers_for[ft] then return servers_for[ft] end local candidates = {} for _, name in ipairs(require("mason-lspconfig.mappings").get_filetype_map()[ft] or {}) do if not not_real_servers[name] and not vim.list_contains(candidates, name) then table.insert(candidates, name) end end
local map = require("mason-lspconfig.mappings").get_mason_map().lspconfig_to_package candidates = vim.tbl_filter(function(n) return map[n] end, candidates) return #candidates == 1 and candidates or {}end
local function on_filetype(ft) if ft == "" then return end if ft == rust_ft then if vim.fn.executable("rust-analyzer") == 0 and not state[rust_package] then local pkg = mason_package("rust_analyzer") if pkg then state[rust_package] = "installing" ensure_installed(pkg, rust_package, function(ok) state[rust_package] = ok and "ready" or "failed" if ok then say("reopen the rust file (:e) so rustaceanvim picks it up") end end) end end return end for _, server in ipairs(servers_for_filetype(ft)) do handle_server(server) endend
local ui_entered = falsevim.api.nvim_create_autocmd("UIEnter", { group = vim.api.nvim_create_augroup("auto-install-ui", { clear = true }), once = true, callback = function() ui_entered = true end,})
vim.api.nvim_create_autocmd("FileType", { group = vim.api.nvim_create_augroup("auto-install-lsp", { clear = true }), callback = function(ev) if vim.bo[ev.buf].buftype ~= "" then return end local ft = ev.match
local function run() load_plugins()
local ok, registry = pcall(require, "mason-registry") if not ok then return end registry.refresh(vim.schedule_wrap(function() on_filetype(ft) end)) end
if ui_entered then vim.schedule(run) else vim.api.nvim_create_autocmd("UIEnter", { once = true, callback = function() vim.schedule(run) end, }) end end,})