williamboman / mason.nvim

Portable package manager for Neovim that runs everywhere Neovim runs. Easily install and manage LSP servers, DAP servers, linters, and formatters.
Apache License 2.0
7.61k stars 271 forks source link

Add a :MasonUpdateAll command #445

Open baco opened 1 year ago

baco commented 1 year ago

I've searched open issues for similar requests

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

I'd like a way to update all the packages in Mason.nvim running Neovim in headless mode.

Describe the solution you'd like

I want to be able to run: :MasonUpdateAll in Neovim's command or: $ nvim --headless +"MasonUpdateAll"

to periodically update all my packages without having to launch :Mason and then Shift+U

Describe potential alternatives you've considered

No response

Additional context

No response

williamboman commented 1 year ago

Hello! I'd recommend looking into https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim for now. This will hopefully make it into core eventually!

jay-babu commented 1 year ago

Maybe this can be easily incorporated into core?

https://github.com/RubixDev/mason-update-all/blob/main/lua/mason-update-all/init.lua

jay-babu commented 1 year ago

@williamboman thoughts?

SyedFasiuddin commented 1 year ago

any update on this command?

miguno commented 1 year ago

+1

I, too, would appreciate a command like this so that I can run unattended updates as part of my script that manages all my dotfiles and local development setup.

anjos commented 1 year ago

This is effectively missing for unattended updates. The command MasonUpdate does not update the packages themselves, only the registry. Using mason-tool-installer includes yet another tool on the top of an increasingly large number of plugins to manage LSP things.

dimitarvp commented 6 months ago

Can anybody post a working setup for mason-tool-installer.nvim that does not automatically update on startup and needs a command to do it?

I have my homegrown script to update everything on my Mac and that also includes these LunarVim CLI updates:

lvim --headless "+Lazy! sync" +qa
lvim --headless "+TSUpdate" +qa

I'd be willing to add lvim --headless "+MasonToolsUpdate" +qa to it but I am a bit lazy on formulating the right configuration first. So, anybody has a working snippet that allows a headless NeoVim invocation to update all installed tools?

NeilGirdhar commented 6 months ago

@dimitarvp I do it all on one line: nvim --headless +Lazy! update +TSUpdate +q, and I update over sync.

Zeioth commented 6 months ago

You can use mason-extra-cmds. That way you just need to remove the plugin when this is eventually added.

NeilGirdhar commented 6 months ago

@Zeioth Doesn't seem to work for me. Do I need to call a setup function?

dimitarvp commented 6 months ago

@Zeioth Didn't work for me either, it says there is no such editor command after installing it with Lazy (and restarting NeoVim just in case). I checked that it's installed but still, no such editor command.

Zeioth commented 6 months ago

@NeilGirdhar @dimitarvp it is a plugin so you must start it. On lazy using opts = {} will do it automatically. screenshot_2024-03-11_14-19-22_574579660

dimitarvp commented 6 months ago

@Zeioth Okay, that worked, thank you.

Now I can do this and have my LunarVim update everything I care for from the CLI without having to launch it:

lvim --headless "+Lazy! update" "+TSUpdate" "+MasonUpdateAll" "+qa"

Also let me type out the Lua config so others can just copy it. This is what I have put inside my init file in the Lazy section:

  {
    "williamboman/mason.nvim",
    dependencies = { "Zeioth/mason-extra-cmds", opts = {} },
    cmd = {
      "Mason",
      "MasonInstall",
      "MasonUninstall",
      "MasonUninstallAll",
      "MasonLog",
      "MasonUpdate",
      "MasonUpdateAll", -- provided by `Zeioth/mason-extra-cmds`
    }
  }
dimitarvp commented 6 months ago

I spoke too soon. While the command can now indeed be ran headless (or just ran at all), it doesn't seem to do what I want it to do. I ran it, then started NeoVim and manually checked Mason and sure enough, I have non-upgraded plugins.

@Zeioth anything extra we should do? The non-upgraded plugins are language servers and formatters by the way.

Zeioth commented 6 months ago

@dimitarvp I just tested it and it works fine on my end: screenshot_2024-03-13_02-11-12_172976484

If I run it again you can see a couple packages were not installed screenshot_2024-03-13_02-11-36_385709645

By opening Mason we can see the problem was not the :MasonUpdateAll command, but the fact mason fail to install them screenshot_2024-03-13_02-13-54_820388022

Which is something you can get from time to time.

dimitarvp commented 6 months ago

@Zeioth I tried several times but no, it wasn't an occasional failure. BTW I am running the function in headless mode, maybe that has something to do with it? Maybe it's async and is not waiting for all updates to complete?

Zeioth commented 6 months ago

@dimitarvp please realize I'm not technical service.

The code is barely 50 lines. In the time you've spent polluting the thread you could have just fork the project and adapt it to your needs.

dimitarvp commented 6 months ago

@Zeioth You advertised your tool here, not me. If it doesn't work then of course you'll be told about it.

Zeioth commented 6 months ago

The code is shipped on a distro with several thousands of users. I can guarantee you it works.

anjos commented 6 months ago

I also tested the solution, and the plugin works, however not in headless mode. A synchronous MasonUpdateAll would be the solution for headless mode. @Zeioth's code could be used as a fork if somebody knows how to make it synchronous with minimal mods? Or add a synchronous version as a PR to that repo?

Zeioth commented 6 months ago

No problem, if you send a PR with the instructions to test it I will review it. Hopefuly the feature will be added natively to Mason eventually.

NeilGirdhar commented 6 months ago

@Zeioth Thank you for taking the time to make this tool. FYI I'm running into another major problem whereby :LspRestart is non-existent unless :Mason is called first. Removing the MasonUpdateAll code fixes things.

Zeioth commented 6 months ago

Please, take the time to read the code. It's barely a couple lines, and it does nothing that could provoke that.

https://github.com/Zeioth/mason-extra-cmds/blob/main/lua/masonextracmds/mason.lua

NeilGirdhar commented 6 months ago

@Zeioth Sorry, I can't understand Lua. I know that when I remove it, the LSP commands are back.