feat/pack (#1)
Reviewed-on: #1 Co-authored-by: Tomas Mirchev <contact@tomastm.com> Co-committed-by: Tomas Mirchev <contact@tomastm.com>
This commit was merged in pull request #1.
This commit is contained in:
93
lua/setup/init.lua
Normal file
93
lua/setup/init.lua
Normal file
@@ -0,0 +1,93 @@
|
||||
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')
|
||||
paq:setup({ lock = vim.fn.stdpath("config") .. "/paq-lock.json" })
|
||||
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' })
|
||||
20
lua/setup/packages.lua
Normal file
20
lua/setup/packages.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
local M = {}
|
||||
|
||||
function M.get()
|
||||
return {
|
||||
{ 'savq/paq-nvim', opt = true },
|
||||
{ 'https://github.com/mason-org/mason.nvim', opt = true },
|
||||
|
||||
{ 'https://github.com/triimd/invero.nvim' },
|
||||
{ 'https://gitea.tomastm.com/tomas.mirchev/nvim-tree.lua', version = 'master' },
|
||||
|
||||
{ 'https://github.com/windwp/nvim-ts-autotag' },
|
||||
{ 'https://github.com/windwp/nvim-autopairs' },
|
||||
|
||||
{ 'https://github.com/nvim-treesitter/nvim-treesitter', version = 'master' },
|
||||
{ 'https://github.com/mfussenegger/nvim-lint' },
|
||||
{ 'https://github.com/stevearc/conform.nvim' },
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user