local function clone_package_manager() local path = vim.fn.stdpath('data') .. '/site/pack/paqs/opt/paq-nvim' if not vim.uv.fs_stat(path) then local repo = 'https://github.com/savq/paq-nvim.git' local cmd = { 'git', 'clone', '--depth=1', repo, path } local result = vim.system(cmd):wait() if result.code == 0 then print('Package manager installed correctly') end end end local function install_packages() local done = false vim.api.nvim_create_autocmd('User', { pattern = 'PaqDoneInstall', once = true, callback = function() done = true end, }) vim.cmd.packadd('paq-nvim') local paq = require('paq') local packages = require('setup.packages').get() paq(packages) paq.install() local to_install = paq.query('to_install') if #to_install == 0 then return end vim.wait(60000, function() return done end, 200) if not done then print('Paq installation timeout or failed') else print('Paq installation completed') end end local function install_languages() vim.cmd.packadd('mason.nvim') require('mason').setup() local lm = require('plugins.language-manager') lm.invalidate_cache() lm.load_specs() lm.install() end vim.api.nvim_create_user_command('InstallAll', function() print('> Starting clone package manager...') clone_package_manager() print('\n> Starting installing packages...') install_packages() print('\n> Starting installing languages: ts parsers, language servers, linters, formatters...') install_languages() print('\n=== Install Finished ===\n\n') end, {}) vim.api.nvim_create_user_command('FetchLspConfigs', function() local base_url = 'https://raw.githubusercontent.com/neovim/nvim-lspconfig/master/lsp/' local lm = require('plugins.language-manager') lm.invalidate_cache() local general = lm.load_specs() local lsp_dir = vim.fs.joinpath(vim.fn.getcwd(), 'lsp') vim.fn.mkdir(lsp_dir, 'p') for _, name in ipairs(general.language_servers or {}) do local file = vim.fs.joinpath(lsp_dir, name .. '.lua') if vim.fn.filereadable(file) == 0 then local url = base_url .. name .. '.lua' local cmd = string.format('curl -fsSL -o %q %q', file, url) vim.fn.system(cmd) if vim.v.shell_error ~= 0 then vim.notify('Failed to fetch ' .. name .. '.lua', vim.log.levels.ERROR) vim.fn.delete(file) else vim.notify('Fetched ' .. name .. '.lua', vim.log.levels.INFO) end else vim.notify('Skipped existing ' .. name .. '.lua', vim.log.levels.INFO) end end end, { desc = 'Fetch default LSP configs into ./lsp in cwd' })