csharp-language-server icon indicating copy to clipboard operation
csharp-language-server copied to clipboard

disable the autoformater

Open Arrow-x opened this issue 1 year ago • 3 comments

I can't seem to disable the autoformater on the server usually passing

client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false

to the server configuration disables the formater in all other servers I use,

Arrow-x avatar Jul 01 '24 19:07 Arrow-x

Did you ever figure this out? I'm trying to use this with csharpier autoformatter and this LSP keeps overriding csharpier.

CobSammich avatar Aug 24 '24 02:08 CobSammich

Any updates on this? I'd prefer to use Csharpier but have been forced to work with the .editorconfig support that was recently released.

shawn-peery avatar May 01 '25 16:05 shawn-peery

The workaround should be easy, just wrap your formatting keymap/event to skip when current active client is csharp_ls, something like this:

    vim.keymap.set('n', [[<leader>k]], function()
      local lsp_methods = require('vim.lsp.protocol').Methods
      local csharp_ls = vim
        .iter(vim.lsp.get_clients {
          bufnr = 0,
          method = lsp_methods.textDocument_formatting,
        })
        :find(function(client) return client.name == 'csharp_ls' end)

      if not csharp_ls then
        vim.lsp.buf.format { async = false, timeout_ms = 5000, bufnr = 0 }
      end
    end)

sharpchen avatar Jul 09 '25 04:07 sharpchen