lukas-reineke / lsp-format.nvim

A wrapper around Neovims native LSP formatting.
559 stars 27 forks source link

No way to tell if auto-formatting is enabled #86

Closed elken closed 4 months ago

elken commented 4 months ago

As far as I can tell, there's no exposed API for determining if the current buffer will autosave.

It would be useful for me to have a modeline indicator so I can know before saving. Happy to submit a PR if it's easier for you, I figured you'd probably know the most sensible way to expose this though.

Thanks for a great package!

lukas-reineke commented 4 months ago

You can check require('lsp-format').disabled for if the plugin is disabled globally, and require('lsp-format').disabled_filetypes[vim.bo.filetype] for the current filetype. And you can also check require('lsp-format').buffers[vim.api.nvim_get_current_buf()] if there are any clients attached to a buffer.

elken commented 4 months ago

Huh, when I inspected the object before and after disabling they were both identical but okay I'll try that :smile:

elken commented 4 months ago

Yeah after running toggle twice, enable then disable I get the below for require('lsp-format').buffers[vim.api.nvim_get_current_buf()]

image

lukas-reineke commented 4 months ago

If you want to see if the plugin is disabled globally FormatToggle, you need to check require('lsp-format').disabled

elken commented 4 months ago

If you want to see if the plugin is disabled globally FormatToggle, you need to check require('lsp-format').disabled

Is it not handled per-buffer?

lukas-reineke commented 4 months ago

Is it not handled per-buffer?

No, it's not. Only globally, or per filetype.

elken commented 4 months ago

Ahh my bad then, thanks anyway!