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

feat(option): fallback to git when local plugin doesn't exist #446

Merged
merged 2 commits into from
Jan 24, 2023
Merged

feat(option): fallback to git when local plugin doesn't exist #446

merged 2 commits into from
Jan 24, 2023

Conversation

nullchilly
Copy link
Contributor

@nullchilly nullchilly commented Jan 24, 2023

Related: https://www.reddit.com/r/neovim/comments/zk187u/how_does_everyone_segment_plugin_development_from/

I used to have a custom use function in packer (Which is no longer possible in lazy.nvim):

local use = function(opts)
  if opts.dev and vim.fn.isdirectory(vim.fn.expand(opts.dev)) ~= 0 then opts[1] = opts.dev end
  require("packer").use(opts)
end
use { "catppuccin/nvim", dev = "~/code/git/catppuccin" }

With lazy.nvim there's an useful option known as dev and it even supports patterns! However, I can no longer (easily) sync my config between machines as local plugin dir wouldn't be found

This PR adds an option called dev.fallback to fallback to git plugin when local plugin dir doesn't exist

@max397574
Copy link
Contributor

I think there already is a closed issue for this somewhere

@nullchilly
Copy link
Contributor Author

nullchilly commented Jan 24, 2023

Found the old PR: #77

Upon benchmarking when dev.fallback is true this only took 0.005ms for each dev plugin

The if function stop right after plugin.dev is false so even if you develop more than 100 plugins it wouldn't even take more than 0.5ms

In case of confusion between dev plugin and downloaded one the dev.fallback is default to false

The benchmark:

image

@nullchilly nullchilly changed the title feat: fallback to git when local plugin isn't found feat(option): fallback to git when local plugin doesn't exist Jan 24, 2023
@EdenEast
Copy link
Contributor

Thanks @nullchilly for making this pr. I also had some checks that I did with packer for my local dev plugins but have been having issues when switching to lazy. I checked out your changes and has solved my local plugin issues on my other computers. I dont have to locally clone and manage my plugins myself anymore. 👍

@seblj
Copy link
Contributor

seblj commented Jan 24, 2023

In case this PR also gets closed, I have done this as a workaround since my PR:

local dev_path = string.format("%s/projects/plugins", os.getenv("HOME"))

local function walk_spec(config)
    for k, val in ipairs(config) do
        local plugin = type(val) == "table" and val[1] or val
        local author, name = unpack(vim.split(plugin, "/"))
        if val.dependencies then
            walk_spec(val.dependencies)
        end
        if author == "seblj" and vim.loop.fs_stat(string.format("%s/%s", dev_path, name)) then
            if type(val) == "table" then
                val.dev = true
            else
                config[k] = { val, dev = true }
            end
        end
    end
end

function M.setup(config)
    walk_spec(config)
    require("lazy").setup(config, {
        dev = {
            path = dev_path,
        },
    })
end

Then I can call M.setup with the plugin spec

@folke folke merged commit 772d888 into folke:main Jan 24, 2023
@folke
Copy link
Owner

folke commented Jan 24, 2023

I can live with the fallback as a config :)

TIL: vim.fn.isdirectory is almost 4 times faster than vim.loop.fs_stat

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

Successfully merging this pull request may close these issues.

None yet

5 participants