Skip to content

bug: file blanked out on error with rubyfmt #157

Description

@Roguelazer

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.

Activity

  1. stevearc commented on Oct 23, 2023

    @stevearc
    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.

  2. stevearc commented on Oct 24, 2023

    @stevearc
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions