Vim.lsp.buf.format notifications with disabled client

Hey,
with the newest vim.lsp.buf.format, there is an option to disable formatting for a specific client.
Let’s say I don’t want to format specific languages at all.
If I disable formatting for a specific LSP (let’s say solargraph) according to the docs, each time I save ruby file I get notification about “[LSP] Format request failed, no matching language servers.”.
Is there an option to disable those notifications?

1 Like

You need some way to tell the LSP client the LSP server doesn’t have formatting capabilities. This is hacky but in your attach function you can say the server can’t format so the client won’t try. I do that for tsserver. Here it is from my dotfiles.

if client.name == 'tsserver' then
    -- HACK: neovim 0.8 change client_capabilities => server_capabilities
    client.server_capabilities.document_formatting = false
    client.server_capabilities.document_range_formatting = false
  end

For Solargraph you can turn off formatting on server init. An example from my dotfiles.

require('lspconfig').solargraph.setup({
    cmd = { 'bundle', 'exec', 'solargraph', 'stdio' },
    init_options = {
      formatting = false,
    },
    settings = {
      solargraph = {
        diagnostics = true,
      },
    },
    capabilities = capabilities,
    on_attach = on_attach,
  })
1 Like