mhartington/formatter.nvim

Support formatters in the form of an async function

Opened this issue · 0 comments

There are some issues requesting integration with lsp formatting. The problem with supporting this kind of integration is that lsp formatting comes in the form of an async function, and formatter.nvim doesn't have a mechanism for defining a formatter in the form of an async function (only sync functions seem to be supported).
I think that one way this could be implemented, is by checking the number of arguments on the formatter function being passed, and when there is 1 argument, assume it is a callback, and treat it as an async function. In that manner, we could define a formatter in terms of lsp-format.nvim, or something like neovim/neovim#24725 when it gets implemented.
Or maybe try out some other async mechanism, like plenary.async?

Edit: https://stackoverflow.com/questions/56883060/how-to-get-the-number-of-arguments-a-function-in-a-table-expect