bug: Can't format with Rubocop and keep getting formatter timeout
Neovim version (nvim -v)
NVIM v0.9.5
Operating system/version
Ubuntu 22.04
Add the debug logs
- [X] I have set
log_level = vim.log.levels.DEBUGand pasted the log contents below.
Log file: /home/lucas/.local/state/nvim/conform.log 17:27:33[WARN] No formatters found for /home/lucas/repos/rubyTest/calculo.rb 17:27:36[WARN] No formatters found for /home/lucas/repos/rubyTest/calculo.rb 17:53:10[WARN] Formatter 'rubocop' timeout 18:19:23[WARN] Formatter 'rubocop' timeout 18:21:15[WARN] Formatter 'rubocop' timeout 18:25:07[WARN] Formatter 'rubocop' timeout 18:41:30[WARN] Formatter 'rubocop' timeout 19:43:19[WARN] Formatter 'rubocop' timeout 19:46:15[WARN] Formatter 'rubocop' timeout 19:56:23[WARN] Formatter 'rubocop' timeout 19:56:32[DEBUG] Running formatters on /home/lucas/repos/rubyTest/calculo.rb: { "rubocop" } 19:56:32[INFO] Run rubocop on /home/lucas/repos/rubyTest/calculo.rb 19:56:32[DEBUG] Run command: { "rubocop", "--server", "-a", "-f", "quiet", "--stderr", "--stdin", "/home/lucas/repos/rubyTest/calculo.rb" } 19:56:33[WARN] Formatter 'rubocop' timeout 19:56:33[INFO] rubocop exited with code 143 19:56:33[DEBUG] rubocop stdout: { "" } 19:56:33[DEBUG] rubocop stderr: { "" }
Formatters for this buffer: LSP: solargraph rubocop ready (ruby) /home/lucas/.local/share/nvim/mason/bin/rubocop solargraph unavailable: No config found
Other formatters: prettier ready (css, javascript, html) /home/lucas/.local/share/nvim/mason/bin/prettier shfmt ready (sh) /home/lucas/.local/share/nvim/mason/bin/shfmt stylua ready (lua) /home/lucas/.local/share/nvim/mason/bin/stylua
Describe the bug
I'm trying to use rubocop to format my ruby files, i can run rubocop on the terminal but i get a timeout when running with conform. i use nvchad
What is the severity of this bug?
breaking (some functionality is broken)
Steps To Reproduce
use Rubocop to format a ruby file with conform
Expected Behavior
Format my ruby file
Minimal example file
No response
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 = {
"folke/tokyonight.nvim",
{
"stevearc/conform.nvim",
config = function()
require("conform").setup({
log_level = vim.log.levels.DEBUG,
-- add your config here
})
end,
},
-- add any other plugins here
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
vim.cmd.colorscheme("tokyonight")
-- add anything else here
Additional context
this is my config
--type conform.options local options = { lsp_fallback = true,
formatters_by_ft = { lua = { "stylua" },
javascript = { "prettier" },
css = { "prettier" },
html = { "prettier" },
sh = { "shfmt" },
ruby = { "rubocop", "solargraph" },
},
-- adding same formatter for multiple filetypes can look too much work for some -- instead of the above code you could just use a loop! the config is just a table after all!
format_on_save = { -- These options will be passed to conform.format() timeout_ms = 500, lsp_fallback = true, }, }
require("conform").setup(options)
Its probably taking longer and 500ms you set with timeout_ms. Try removing it.
I removed and keep getting the timeout, I even set the timeout to 5000 and 10000 ms, and still with the error, and rubocop is working outside of conform, I can run rubocop -a in the terminal and will format and correct the file
Conform runs this command: { "rubocop", "--server", "-a", "-f", "quiet", "--stderr", "--stdin"} with file as last argument.
I think either these flags are outdated or it takes longer than 10s(unlikely).
You can try to debug by running the command with the flags yourself or try setting async=true in case it takes longer.
I even tried to config conform to only use -a flag but didn't work(tried the async too), I think i will just format manualy, but conform works amazing on other languages
Sounds like some sort of issue with rubocop...I would guess that most likely it's to do with the --server option. You can customize the args that conform passes like so:
require("conform").setup({
formatters = {
rubocop = {
args = { "-a", "-f", "quiet", "--stderr", "--stdin", "$FILENAME" }
}
}
})
You can also try messing with whether it formats via stdin or not to see if that makes a difference.
Its probably taking longer and 500ms you set with timeout_ms. Try removing it.
I was having the same issue and this had fixed it for me by bumping to 1000ms. Afterward I went to an async configuration and that worked as well.
I changed the formatter options as well. I'm currently using these:
{ "--server", "--auto-correct-all", "--stderr", "--force-exclusion", "--stdin", "$FILENAME" }
It's working fine now.
I'm on WSL2 now, and conform + rubocop is working as intended, I have no idea what happened on my Ubuntu.
@Lucashdml I'm not a contributor or anything but still receive notifications. In regards to tidiness, can we consider this issue closed? If so, would you mind closing it?
Sure man, I don't mind, ty guys.