Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Help with eslint_d timeout #364

Open
1 task done
jacobrreed opened this issue Apr 4, 2024 · 11 comments
Open
1 task done

bug: Help with eslint_d timeout #364

jacobrreed opened this issue Apr 4, 2024 · 11 comments
Labels
bug Something isn't working

Comments

@jacobrreed
Copy link

jacobrreed commented Apr 4, 2024

Neovim version (nvim -v)

NVIM v0.10.0-dev-2258+g1405e5c8c

Operating system/version

MacOS 14.4.1

Add the debug logs

  • I have set log_level = vim.log.levels.DEBUG and pasted the log contents below.

Log file

10:31:21[DEBUG] Running formatters on /Users/jrreed/dev/networking-solutions/src/main.tsx: { "prettier", "eslint_d" }
10:31:21[INFO] Run prettier on /Users/jrreed/dev/networking-solutions/src/main.tsx
10:31:21[DEBUG] Run command: { "/Users/jrreed/dev/networking-solutions/node_modules/.bin/prettier", "--stdin-filepath", "/Users/jrreed/dev/networking-solutions/src/main.tsx" }
10:31:21[DEBUG] Run CWD: /Users/jrreed/dev/networking-solutions
10:31:22[DEBUG] prettier exited with code 0
10:31:22[INFO] Run eslint_d on /Users/jrreed/dev/networking-solutions/src/main.tsx
10:31:22[DEBUG] Run command: { "eslint_d", "--fix-to-stdout", "--stdin", "--stdin-filename", "/Users/jrreed/dev/networking-solutions/src/main.tsx" }
10:31:22[DEBUG] Run CWD: /Users/jrreed/dev/networking-solutions
10:31:22[DEBUG] eslint_d exited with code 0
10:31:22[DEBUG] Running formatters on /Users/jrreed/dev/networking-solutions/src/main.tsx: { "prettier", "eslint_d" }
10:31:22[INFO] Run prettier on /Users/jrreed/dev/networking-solutions/src/main.tsx
10:31:22[DEBUG] Run command: { "/Users/jrreed/dev/networking-solutions/node_modules/.bin/prettier", "--stdin-filepath", "/Users/jrreed/dev/networking-solutions/src/main.tsx" }
10:31:22[DEBUG] Run CWD: /Users/jrreed/dev/networking-solutions
10:31:23[DEBUG] prettier exited with code 0
10:31:23[INFO] Run eslint_d on /Users/jrreed/dev/networking-solutions/src/main.tsx
10:31:23[DEBUG] Run command: { "eslint_d", "--fix-to-stdout", "--stdin", "--stdin-filename", "/Users/jrreed/dev/networking-solutions/src/main.tsx" }
10:31:23[DEBUG] Run CWD: /Users/jrreed/dev/networking-solutions
10:31:23[WARN] Formatter 'eslint_d' timeout
10:31:23[INFO] eslint_d exited with code 143
10:31:23[DEBUG] eslint_d stdout: { "" }
10:31:23[DEBUG] eslint_d stderr: { "" }

Describe the bug

I have a typescriptreact file, and for my formatters i have :
typescriptreact = { "prettier", "eslint_d" },

I also use https://github.com/pmizio/typescript-tools.nvim

My format_on_save function:

      format_on_save = function()
        if vim.g.disable_autoformat then
          return
        end
        return {
          lsp_fallback = true,
          timeout_ms = 500,
        }
      end,

but I also have an autocmd setup because of tstools:

vim.api.nvim_create_autocmd("BufWritePre", {
  group = vim.api.nvim_create_augroup("ts_fix_imports", { clear = true }),
  desc = "Add missing imports and remove unused imports for TS",
  pattern = { "*.ts", "*.tsx", "*.js", "*.jsx" },
  callback = function(args)
    vim.cmd("TSToolsAddMissingImports sync")
    vim.cmd("TSToolsRemoveUnusedImports sync")
    if package.loaded["conform"] then
      require("conform").format({ bufnr = args.buf })
    end
  end,
})

this autocmd is setup because on save I want TSTools to add missing imports, remove unused imports, then call conforms format

The funny thing is, the eslint_d seems to format on save, but then says it times out after

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

  1. Open any typescript react file and save
  2. eslint_d will format but will then notify via timeout error

Expected Behavior

I expect eslint_d to not timeout

Minimal example file

Any typescript react file seems to do this

Minimal init.lua

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
 {
  "stevearc/conform.nvim",
  cond = not vim.g.vscode,
  lazy = true,
  event = { "BufReadPre", "BufNewFile" }, -- to disable, comment this out
  config = function()
    local conform = require("conform")

    vim.api.nvim_create_user_command("FormatToggle", function(args)
      if args.bang then
        -- FormatToggle! will disable formatting just for this buffer
        if vim.b.disable_autoformat then
          vim.b.disable_autoformat = false
          require("notify")("Formatting enabled for buffer")
        else
          vim.b.disable_autoformat = true
          require("notify")("Formatting disabled for buffer")
        end
      else
        if vim.g.disable_autoformat then
          vim.g.disable_autoformat = false
          vim.b.disable_autoformat = false
          require("notify")("Formatting enabled")
        else
          vim.g.disable_autoformat = true
          vim.b.disable_autoformat = true
          require("notify")("Formatting disabled")
        end
      end
    end, {
      desc = "Toggle autoformat",
      bang = true,
    })

    conform.setup({
      quiet = true,
      formatters_by_ft = {
        javascript = { "prettier", "eslint_d" },
        typescript = { "prettier", "eslint_d" },
        javascriptreact = { "prettier", "eslint_d" },
        typescriptreact = { "prettier", "eslint_d" },
        svelte = { "prettier" },
        css = { "prettier" },
        html = { "prettier" },
        json = { "prettier" },
        yaml = { "prettier" },
        markdown = { "prettier" },
        graphql = { "prettier" },
        lua = { "stylua" },
        python = { "isort", "black" },
        rust = { "rustfmt" },
      },
      format_on_save = function()
        if vim.g.disable_autoformat then
          return
        end
        return {
          lsp_fallback = true,
          timeout_ms = 500,
        }
      end,
      log_level = vim.log.levels.DEBUG,
    })

    vim.keymap.set({ "n", "v" }, "<leader>fv", function()
      conform.format({
        lsp_fallback = true,
        async = false,
        timeout_ms = 1000,
      })
    end, { desc = "Format file or range (in visual mode)" })

    vim.keymap.set({ "n" }, "<leader>cft", "<cmd>FormatToggle<cr>", { desc = "Toggle autoformat" })
    vim.keymap.set({ "n" }, "<leader>cfT", "<cmd>FormatToggle!<cr>", { desc = "Toggle autoformat for buffer" })
  end,
},
{
  "mfussenegger/nvim-lint",
  cond = not vim.g.vscode,
  lazy = true,
  event = { "BufReadPre", "BufNewFile" },
  config = function()
    local lint = require("lint")

    lint.linters_by_ft = {
      javascript = { "eslint_d" },
      typescript = { "eslint_d" },
      javascriptreact = { "eslint_d" },
      typescriptreact = { "eslint_d" },
      svelte = { "eslint_d" },
      python = { "pylint" },
    }

    local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })

    vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
      group = lint_augroup,
      callback = function()
        lint.try_lint(nil, { ignore_errors = true })
      end,
    })

    vim.keymap.set("n", "<leader>cl", function()
      lint.try_lint()
    end, { desc = "Trigger linting for current file" })
  end,
},
  {
    "pmizio/typescript-tools.nvim",
    cond = not vim.g.vscode,
    dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" },
    opts = {
      settings = {
        expose_as_code_action = { "fix_all", "add_missing_imports", "remove_unused", "remove_unused_imports" },
      },
    },
  },
 {
  "williamboman/mason.nvim",
  cond = not vim.g.vscode,
  opts = {},
  dependencies = {
    "williamboman/mason-lspconfig.nvim",
    "WhoIsSethDaniel/mason-tool-installer.nvim",
  },
  config = function()
    local mason = require("mason")
    local mason_lspconfig = require("mason-lspconfig")
    local mason_tool_installer = require("mason-tool-installer")

    mason.setup({
      ui = {
        icons = {
          package_installed = "",
          package_uninstalled = "",
          package_pending = "",
        },
      },
    })

    mason_lspconfig.setup({
      ensure_installed = {
        "tsserver",
        "html",
        "cssls",
        "lua_ls",
        "emmet_ls",
        "pyright",
        "jsonls",
        "gopls",
      },
    })

    mason_tool_installer.setup({
      ensure_installed = {
        "prettier", -- prettier formatter
        "stylua", -- lua formatter
        "eslint_d", -- js linter
        "jsonlint", -- json formatter
      },
    })
  end,
}
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

-- add anything else here
vim.api.nvim_create_autocmd("BufWritePre", {
  group = vim.api.nvim_create_augroup("ts_fix_imports", { clear = true }),
  desc = "Add missing imports and remove unused imports for TS",
  pattern = { "*.ts", "*.tsx", "*.js", "*.jsx" },
  callback = function(args)
    vim.cmd("TSToolsAddMissingImports sync")
    vim.cmd("TSToolsRemoveUnusedImports sync")
    if package.loaded["conform"] then
      require("conform").format({ bufnr = args.buf })
    end
  end,
})

Additional context

No response

@jacobrreed jacobrreed added the bug Something isn't working label Apr 4, 2024
@se-omar
Copy link

se-omar commented Apr 6, 2024

I had the same issue, adding async=true fixed it, conform.format({lsp_fallback=true, async=true})

@jacobrreed
Copy link
Author

I had the same issue, adding async=true fixed it, conform.format({lsp_fallback=true, async=true})

Thanks I'll give that a try

@jacobrreed
Copy link
Author

I had the same issue, adding async=true fixed it, conform.format({lsp_fallback=true, async=true})

I think this fixed it, haven't seen it again since

@Lippiece
Copy link

Lippiece commented May 5, 2024

I'm facing the same issue, and I think the solution is not yet found. The problem is that eslint_d takes too much time to format when using conform.nvim. Although, we have workarounds like waiting for 10 seconds each save or using unstable async formatting.

@jacobrreed
Copy link
Author

Same issue still, async workaround is buggy at best

@jacobrreed jacobrreed reopened this May 7, 2024
@stevearc
Copy link
Owner

stevearc commented May 7, 2024

In what way is async formatting buggy?

@stevearc stevearc added the question Further information is requested label May 7, 2024
@jacobrreed
Copy link
Author

In what way is async formatting buggy?

random timeouts mostly

@github-actions github-actions bot removed the question Further information is requested label May 7, 2024
@stevearc
Copy link
Owner

stevearc commented May 7, 2024

Timeouts? Async formatting doesn't have timeouts. Unless you're talking about eslint_d itself timing out?

@jacobrreed
Copy link
Author

Timeouts? Async formatting doesn't have timeouts. Unless you're talking about eslint_d itself timing out?

ya sorry, like the above comment from @Lippiece eslint_d timeouts, so is this whole issue eslint_d related and not related to conform?

@stevearc
Copy link
Owner

stevearc commented May 7, 2024

That's what it sounds like. If running the command directly on the command line doesn't time out, then maybe there's something we can do.

@stevearc stevearc added the question Further information is requested label May 7, 2024
@jacobrreed
Copy link
Author

Ok ill try to do some more isolated testing this weekend when i get time

@github-actions github-actions bot removed the question Further information is requested label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants