stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
2.72k stars 142 forks source link

Question: Configuring csharpier #379

Closed Catacomba closed 3 months ago

Catacomba commented 3 months ago

I've configured a c# formatter by adding c_sharp = 'csharpier'. Info:

My config:

{ -- Autoformat
    'stevearc/conform.nvim',
    opts = {
      notify_on_error = true,
      format_on_save = function(bufnr)
        return {
          timeout_ms = 500,
          lsp_fallback = false,
        }
      end,
      formatters_by_ft = {
        lua = { 'stylua' },
        c_sharp = { 'csharpier' },
    },
},

When I :w the formatter does nothing. If I set lsp_fallback to true however, the omnisharp formatter is used. What am i doing wrong?

msyavuz commented 3 months ago

I think the filetype for csharp is "cs" not "c_sharp". Maybe try with that?

Catacomba commented 3 months ago

Using "cs" instead of "c_sharp" worked! Apearently I wrongly assumed i had to use some keyword, because in the setup the example uses lua, python, javascript...

 formatters_by_ft = {
    lua = { "stylua" },
    -- Conform will run multiple formatters sequentially
    python = { "isort", "black" },
    -- Use a sub-list to run only the first available formatter
    javascript = { { "prettierd", "prettier" } },
  },

Afterwards i went and searched for cs/csharp/c_sharp and found a mapping in

lang_to_ext = {
  ...
  c_sharp = "cs",
  ...
}

after which I assumed I had to use c_sharp and that it will be mapped to .cs files. Anyway... thanks for the advice!

msyavuz commented 3 months ago

No problem! Feel free to close the issue