stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
3.18k stars 162 forks source link

bug: Conform cannot format code when the path to the formatter contains spaces. #506

Closed kubamus closed 1 month ago

kubamus commented 3 months ago

Neovim version (nvim -v)

NVIM v0.10.0

Operating system/version

windows 11

Add the debug logs

Log file

Log file: C:\Users\Kuba M\AppData\Local\nvim-data\conform.log

      17:01:50[ERROR] Formatter 'stylua' error: 'C:\Users\Kuba' is not recognized as an internal or external command,
      operable program or batch file.

      17:02:05[DEBUG] Running formatters on C:\Users\Kuba M\AppData\Local\nvim\lua\kuba\plugins\formatting.lua: { "stylua" }
      17:02:05[INFO] Run stylua on C:\Users\Kuba M\AppData\Local\nvim\lua\kuba\plugins\formatting.lua
      17:02:05[DEBUG] Run command: { "stylua", "--search-parent-directories", "--stdin-filepath", "C:\\Users\\Kuba M\\AppData\\Local\\nvim\\lua\\kuba\\plugins\\formatting.lua", "-" }
      17:02:05[DEBUG] Run default CWD: C:\Users\Kuba M\AppData\Local\nvim
      17:02:05[INFO] stylua exited with code 1
      17:02:05[DEBUG] stylua stdout: { "" }
      17:02:05[DEBUG] stylua stderr: { "'C:\\Users\\Kuba' is not recognized as an internal or external command,\r", "operable program or batch file.\r", "" }
      17:02:05[ERROR] Formatter 'stylua' error: 'C:\Users\Kuba' is not recognized as an internal or external command,
      operable program or batch file.

Formatters for this buffer: LSP: lua_ls stylua ready (lua) C:\Users\Kuba M\AppData\Local\nvim-data\mason\bin\stylua.CMD

Describe the bug

Conform can't use a formatter because of how it handles paths with spaces. Why do I think it's because of the spaces? Just look at the 1st error in the log file, it truncates "C:\Users\Kuba M" (my windows user) to "C:\Users\Kuba" (which is an invalid user). The "stylua" formatter is located in "C:\Users\Kuba M\Documents\kuba\path".

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

Just install this plugin, and have a path to the formatter in PATH variable that contains spaces, e.g. "C:\Users\Kuba M\Documents\kuba\path"

Expected Behavior

I expect it to handle spaces and format my code.

Minimal example file

Not applicable

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

No response

soham-slp commented 1 month ago

I would appreciate an update for this, I am facing the same issue... Is there any workaround for now?

kubamus commented 1 month ago

I would appreciate an update for this, I am facing the same issue... Is there any workaround for now?

Unfortunately I haven't found any workaround for this problem. Now I have a new Windows system with a fixed username, so I can't help any more.

stevearc commented 1 month ago

Duplicate of #252. Looks like an upstream issue in Neovim or libuv