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: auto-patch on plugin update #1355

Closed
1 task done
aarondill opened this issue Mar 9, 2024 · 2 comments
Closed
1 task done

feat: auto-patch on plugin update #1355

aarondill opened this issue Mar 9, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@aarondill
Copy link

aarondill commented Mar 9, 2024

Did you check the docs?

  • I have read all the lazy.nvim docs

Is your feature request related to a problem? Please describe.

I use several plugins to which I have submitted PRs that I actively use but have not yet been merged (an example being codota/tabnine-nvim#70).

I would like to keep my editor version of this plugin up-to-date, without having to maintain a separate fork for a 30 line change.

Describe the solution you'd like

I’d like to have a way to apply user supplied .patch files which will be auto applied on update.

my idea is to have a new patch-dir which is structured like the dev directory . For example:

> ls path/to/user/patch/dir
tabnine-nvim
lazy.nvim
lualine.nvim 
> ls path/to/user/patch/dir/tabnine-nvim
00-add-keymaps.patch
01-bin-support.patch

essentially the process would be

  1. Upgrade the plugin to latest git (we already do this)
  2. if the configuration specifies a patch-dir, and patch-dir/plugin-name exists do:
    1. list the patch-dir/plugin-name into a table
    2. sort the table to ensure consistent ordering (table.sort(files))
    3. for each patch file, spawn a patching process patch or git apply (user config?)
    4. if any patch fails, warn the user, but attempt other patches (this may flood notifications if patches are dependent? should we give up on one failed?)
  3. run the build command (we already do this) (after patching, since it may depend on the patch)

Describe alternatives you've considered

an auto command on LazyUpdate which does the above

  • this doesn’t allow the patches to be applied before building
  • the plugins updated aren’t provided to the callback, so you’d need a hack with LazyUpdatePre and checking file modification dates

A new auto command LazyBuildPre and LazyBuild

  • Passed the plugin as data
  • could be configured to do the above process

Additional context

I’m happy to begin to draft a PR, if you indicate that this is something you’d be willing to merge

should this be a key in LazySpec? like how we have dir which can override the global dev directory, we could have

-@class LazyPluginBase-@field patch?  LazyPatchSpec|boolean if true, patch using global config; if false, do *NOT* patch (default: true)

—-@class LazyPatchSpec-@field dir? string The path to the directory of patch files for *this* plugin-@field cmd? string[] the command to use to apply patches (default: either `patch` or `git apply`) FILE will be appended to this command before running it.

the global config could look something like this:

-@class LazyConfig
M.defaults = {
  patch = {
      ---@type string | fun(plugin: LazyPlugin): string directory where you store your local plugin patches
      path = "~/projects/patches", — note: dev.path default is ~/projects
   }
}
@aarondill aarondill added the enhancement New feature or request label Mar 9, 2024
@folke
Copy link
Owner

folke commented Mar 9, 2024

This is not something I'm willing to add to lazy. Lazy currently requires the plugin's directory to be clean, so that checks for updates etc always work as expected.

It's also easy to just fork a repo and then use that in lazy. Just sync your fork every now and then with the original repo

@folke folke closed this as not planned Won't fix, can't repro, duplicate, stale Mar 9, 2024
@aarondill
Copy link
Author

Would you be willing to add the LazyBuildPre and LazyBuild User events?

with these commands, i could hack my own implementation (albeit officially unsupported)

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

No branches or pull requests

2 participants