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: file blanked out on error with rubyfmt #157

Closed
1 task done
Roguelazer opened this issue Oct 22, 2023 · 3 comments
Closed
1 task done

bug: file blanked out on error with rubyfmt #157

Roguelazer opened this issue Oct 22, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Roguelazer
Copy link

Roguelazer commented Oct 22, 2023

Neovim version (nvim -v)

0.9.4

Operating system/version

macOS 14.0

Add the debug logs

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

Log file

10:20:26[DEBUG] Running formatters on /Users/jbrown/tmp/2023-10-22/test.rb: { "rubyfmt" }
10:20:26[INFO] Run rubyfmt on /Users/jbrown/tmp/2023-10-22/test.rb
10:20:26[DEBUG] Run command: { "rubyfmt" }
10:20:27[DEBUG] rubyfmt exited with code 1

Describe the bug

When run on a file with invalid syntax, rubyfmt outputs no text and exits with status 1. It looks like conform doesn't understand this, so replaces the buffer contents with the empty string.

Steps To Reproduce

  1. install rubyfmt and configure it in conform
  2. echo -e "clas Foo\nend" > test.rb
  3. nvim -u repro.lua test.rb
  4. :w

Expected Behavior

Buffer is unchanged and an error is reported

Minimal example file

clas Foo
end

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,
        formatters_by_ft = {
          ruby = {"rubyfmt"}
        },
        format_on_save = {
          lsp_fallback = true,
          timeout_ms = 500,
        },
        notify_on_error = true,
      })
    end,
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Additional context

I think this might just be a matter of changing exit_codes from {0, 1} to {0} in rubyfmt.lua but I don't know enough about this project to say for sure.

@Roguelazer Roguelazer added the bug Something isn't working label Oct 22, 2023
@stevearc
Copy link
Owner

@hahuang65 is there a reason you included exit_codes = { 0, 1 } as part of #139? I tried looking for documentation of rubyfmt exit codes but couldn't find anything.

@hahuang65
Copy link
Contributor

@stevearc
Copy link
Owner

Okay, in that case let's remove it. If anyone can find official documentation of the the meaning of certain exit codes we can change this again.

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

3 participants