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(api): add MasonInstallComplete autocmd event #252

Closed
wants to merge 1 commit into from

Conversation

kylo252
Copy link
Contributor

@kylo252 kylo252 commented Aug 5, 2022

Description

add an autocmd-event that will trigger when the installer is done

the callback takes {name: string, success: boolean, result: table }

example usage:

vim.api.nvim_create_autocmd("User", {
  pattern = "MasonInstallComplete",
  callback = function(args)
    vim.notify("MasonInstallComplete was called!, got: " .. vim.inspect(args.data))
  end,
})

semi-related: #169

the callback takes `{name: string, success: boolean, result: table }`

example usage:
```lua
  vim.api.nvim_create_autocmd("User", {
    pattern = "MasonInstallComplete",
    callback = function(args)
      vim.notify("MasonInstallComplete was called!, got: " .. vim.inspect(args.data))
    end,
  })
```
@kylo252
Copy link
Contributor Author

kylo252 commented Aug 5, 2022

@williamboman 👋

what do you think of this approach? we didn't have the luxury of using the autocmds API before 0.7, but now we do!

there's another way to handle this as well, that might fit the current model more cleanly, which is execute the autocmd in the EventEmitter itself, but that would probably mean creating a few more events to avoid having to always parse the context to know what happened.

the EventEmitter approach could also be handled completely by the user, but we'd probably lose the context, unless I mis-interpreting how that class work, which is very likely 😄

@williamboman
Copy link
Owner

williamboman commented Aug 5, 2022

Hello! Hm what is the use case for this?

the EventEmitter approach could also be handled completely by the user, but we'd probably lose the context, unless I mis-interpreting how that class work, which is very likely 😄

Yeah that's the idea at least:

registry:on("package:install:success", function (pkg)
    print(pkg.name .. " was installed")
end)

@kylo252
Copy link
Contributor Author

kylo252 commented Aug 11, 2022

Yeah that's the idea at least:

registry:on("package:install:success", function (pkg)
    print(pkg.name .. " was installed")
end)

sorry for the delay, but this caused problems with certain calls, basically the same problem as the one in williamboman/nvim-lsp-installer#210

that said, using vim.schedule works well for now, so feel free to close this until there's a clearer need.

@williamboman
Copy link
Owner

williamboman commented Aug 11, 2022

Aah I see. Yeah those fast events will get ya. I realize my small example is also subject to this 🥲. In the Mason source (which in most places run in an async context) there's quite a few of:

if vim.in_fast_event() then
    a.scheduler()
end

and vim.schedule_wrap's. For the time being I've taken the stance that it's the responsibility of the caller to schedule methods that cannot be called within a fast event. I'll make sure to highlight this somewhere in the reference.

So, for posterity, here's a slightly modified version of my previous example:

registry:on("package:install:success", vim.schedule_wrap(function (pkg)
    print(pkg.name .. " was installed")
end))

vantaboard pushed a commit to vantaboard/mason.nvim that referenced this pull request Jan 10, 2024
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

2 participants