mhartington/formatter.nvim

Choosing formatter based on project types (deno.json and package.json)

Opened this issue · 1 comments

Greetings!

Is there an example of being able to choose which formatters based on the type of files inside the current working directory? I'm using deno and prettier based on the project and they both use the same exact file types -- which is confusing even for LSP.

I'd love some insight. For LSP we do something like this:

require('mason-lspconfig').setup_handlers {
    function (server_name)
      local opts = {
        capabilities = capabilities,
        on_attach = on_attach,
      }
      if server_name == "denols" then
        opts.root_dir = nvim_lsp.util.root_pattern("deno.json", "deno.jsonc")
      elseif server_name == "tsserver" then
        opts.root_dir = nvim_lsp.util.root_pattern("package.json")
        -- https://github.com/neovim/nvim-lspconfig/issues/2507#issuecomment-1471438640
        opts.single_file_support = false
      end
      nvim_lsp[server_name].setup(opts)
    end
  }
tjex commented

In the meantime, there is a manual way of doing it discussed here: #229