Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i install plugins in a synchronous way. #170

Closed
231tr0n opened this issue Jun 29, 2024 · 5 comments
Closed

How can i install plugins in a synchronous way. #170

231tr0n opened this issue Jun 29, 2024 · 5 comments

Comments

@231tr0n
Copy link

231tr0n commented Jun 29, 2024

Hello and first of all thank you for this amazing neovim plugin manager. I wanted to know if there is any method like installSync or similar functionality of sort since everytime i add a new plugin, I end up with an error and my config wont load. Is there any way to prevent this from happening.

@saccarosium saccarosium added the bug Something isn't working label Jun 30, 2024
@saccarosium
Copy link
Collaborator

Can you provide the error that it gives you and the config where you call paq?

@231tr0n
Copy link
Author

231tr0n commented Jun 30, 2024

image
When ever I add a new plugin, in my case it is a colorscheme called cyberdream.nvim and reopen neovim this error popups up and once i press enter, then the plugin is installed. But the require function is called before the plugin is installed sync paq.install() method runs asynchronously I guess.
Also below is my config
https://github.com/231tr0n/config/blob/main/nvim/init.lua

@saccarosium saccarosium removed the bug Something isn't working label Jul 1, 2024
@saccarosium
Copy link
Collaborator

Currently the best way to get this behavior in paq is using the setup option opt to set the default install directory to the opt directory (see :h packages) and then load the plugins using packadd.

I took the liberty to refactor your bootstrap_paq function, which is now the only function you need (you can remove clone_paq and paq_path)

local function bootstrap_paq(packages)
	local path = vim.fn.stdpath("data") .. "/site/pack/paqs/start/paq-nvim"
	if not vim.uv.fs_stat(path) then
        local url = "https://github.com/savq/paq-nvim.git"
		vim.fn.system({ "git", "clone", "--depth=1", url, path })
        vim.cmd.packadd("paq-nvim")
		vim.notify("Installing plugins")
	end
	local paq = require("paq"):setup({ opt = true })(packages)
    local to_install = paq.query("to_install")
    if not vim.tbl_isempty(to_install) then
        paq.install()
    end
    for _, p in pairs(packages) do
        if type(p) == "table" then
            p = p[1]
        end
        p = {vim.fs.basename(p)}
        vim.cmd.packadd({ args = p, bang = true })
    end
end

This should solve the problem.

@saccarosium
Copy link
Collaborator

The problem here is not that paq downloads packages asynchronously but rather that vim packages doesn't cope well with loading at runtime things from the start directory. Even if you force it with rtp. So for this reason the most manageble solution is to use the opt directory by default and then load the packages in bulk.

@231tr0n
Copy link
Author

231tr0n commented Jul 1, 2024

Yup! thank you for helping me out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants