stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
3.15k stars 161 forks source link

bug: Formatter 'prettier' timeout - when using plugins #297

Closed MichalRsa closed 8 months ago

MichalRsa commented 8 months ago

Neovim version (nvim -v)

0.9.1

Operating system/version

Ubuntu 22.04.3

Add the debug logs

Log file

Log file: /home/michal/.local/state/nvim/conform.log 07:21:27[WARN] Formatter 'prettier' timeout 07:21:30[WARN] Formatter 'prettier' timeout 07:21:32[WARN] Formatter 'prettier' timeout 07:21:35[WARN] Formatter 'prettier' timeout 07:21:37[WARN] Formatter 'prettier' timeout 07:21:39[WARN] Formatter 'prettier' timeout 07:22:44[WARN] Delayed Neovim exit by 1014ms to wait for formatting to complete 07:22:51[WARN] Formatter 'prettier' timeout 07:22:54[WARN] Formatter 'prettier' timeout 07:23:17[WARN] Formatter 'prettier' timeout 07:23:24[WARN] Formatter 'prettier' timeout 07:23:26[WARN] Formatter 'prettier' timeout 07:23:27[WARN] Formatter 'prettier' timeout 07:23:32[WARN] Formatter 'prettier' timeout 07:23:35[WARN] Formatter 'prettier' timeout 07:23:53[WARN] Formatter 'prettier' timeout 07:23:56[WARN] Formatter 'prettier' timeout 07:30:56[WARN] Formatter 'prettier' timeout 07:32:02[WARN] Formatter 'prettier' timeout 07:32:04[WARN] Formatter 'prettier' timeout 07:32:05[WARN] Formatter 'prettier' timeout 07:32:06[WARN] Formatter 'prettier' timeout

Formatters for this buffer: LSP: astro prettier ready (astro, javascriptreact, typescriptreact, html, css, javascript, typescript) /home/michal/personal/astro-blog/node_modules/.bin/prettier

Other formatters: shfmt unavailable: Command not found stylua ready (lua) /home/michal/.local/share/nvim/mason/bin/stylua

Describe the bug

I am getting a prettier timeout when using (too many?) plugins. When I format a .tsx file timeout occurs sometimes. When I try to format .astro the timeout is always an outcome.

This issue happens only after adding the --plugin flag.

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

local options = {
  lsp_fallback = true,

  formatters_by_ft = {
    lua = { "stylua" },

    javascript = { "prettier" },
    javascriptreact = { "prettier" },
    css = { "prettier" },
    html = { "prettier" },
    astro = { "prettier" },
    typescript = { "prettier" },
    typescriptreact = { "prettier" },

    sh = { "shfmt" },
  },

  formatters = {
    prettier = {
      args = function(self, ctx)
        if vim.endswith(ctx.filename, ".astro") then
          return {
            "--stdin-filepath",
            "$FILENAME",
            "--plugin",
            "prettier-plugin-astro",
            "--plugin",
            "prettier-plugin-tailwindcss",
          }
        end
        return { "--stdin-filepath", "$FILENAME", "--plugin", "prettier-plugin-tailwindcss" }
      end,
    },
  },
}

require("conform").setup(options)

Expected Behavior

Prettier formats file with 'prettier-plugin-astro' and 'prettier-plugin-tailwindcss'

MichalRsa commented 8 months ago
require("conform").format { async = true, lsp_fallback = true }

That is how I call the format function and solve my issue.

Jarmos-san commented 6 months ago

It is possible to fix this issue by increasing the timeout_ms key. Here is an example code snippet I use to deal with the issue:

return {
  "stevearc/conform.nvim",
  event = { "LspAttach", "BufReadPost", "BufNewFile" },
  opts = {
    formatters_by_ft = {
      python = { "ruff_format" },
      vue = { "prettier" },
    },
    format_on_save = {
      timeout_ms = 2500,
      lsp_fallback = true,
    },
  },
  config = function(_, opts)
    local conform = require("conform")

    -- Setup "conform.nvim" to work
    conform.setup(opts)

    -- Customise the default "prettier" command to format Markdown files as well
    conform.formatters.prettier = {
      prepend_args = { "--prose-wrap", "always" },
    }
  end,
}