1

Neovim provides a convenient pretty-printer:

:lua vim.print(vim.lsp.get_active_clients())

However, the active lsp clients output is massive so I'd want to see it in a buffer.

With vim-scriptease, I can use :Verbose to capture that output into a buffer:

:Verbose lua vim.print(vim.lsp.get_active_clients())

That pretty prints the table, captures the output, and creates a buffer with that output. Great to use / to navigate around the output.

But it seems that capturing lua should be easier in nvim since it's a core config language.

I figured out a command, but it seems verbose:

:lua vim.api.nvim_put(vim.split(vim.inspect(vim.lsp.get_active_clients()), "\n"), "", true, false)

I expected to find something like vim.api.nvim_as_buffer(vim.lsp.get_active_clients()), but maybe I'm just having trouble finding it in lua.txt?

1 Answer 1

3

You could use v:lua:

:new | put =v:lua.vim.inspect(v:lua.vim.lsp.get_active_clients())

(which apparently doesn't work in nvim 0.10 because attached_buffers contains integer indexes (E5100: table should contain either only integer keys or only string keys))

or luaeval():

:new | put =luaeval('vim.inspect(vim.lsp.get_active_clients())')
8
  • vim.print echos the string but vim.inspect returns the string, so that might work. Not sure about lua as expressions. Maybe execute('lua vim.inspect(...))?
    – idbrii
    Commented Jul 22 at 18:17
  • @idbrii I'd forgotten about v:lua; try that one
    – D. Ben Knoble
    Commented Jul 22 at 21:10
  • In my testing, you need a return in luado: :new | luado return vim.inspect(vim.lsp.get_active_clients()) it will only update the buffer line if the contents are returned
    – filbranden
    Commented Jul 22 at 22:15
  • And for the v:lua syntax you also need it for the argument: :new | put =v:lua.vim.inspect(v:lua.vim.lsp.get_active_clients())
    – filbranden
    Commented Jul 22 at 22:15
  • 1
    If you want to consider execute() then go with luaeval() directly: :new | put =luaeval('vim.inspect(vim.lsp.get_active_clients())')
    – filbranden
    Commented Jul 22 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.