stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
3.02k stars 156 forks source link

Account for spaces in the file path when formatting with stylua #421

Closed msabathier closed 4 months ago

msabathier commented 4 months ago

Hi,

I found a bug when formatting a file that has spaces in its path using stylua on Windows. The command that was being executed was something like: stylua --search-parent-directories --stdin-filepath C:\\some\\path with\\spaces.lua This was causing stylua to search for C:\\some\\path and with\\spaces.lua as two separate files and crash. I simply added simple quotes around the $FILENAME environment variable so the executed command would be: stylua --search-parent-directories --stdin-filepath 'C:\\some\\path with\\spaces.lua'

I don't think this should break anything but i didn't do much testing. Let me know if you want me to look at some particular test cases.

stevearc commented 4 months ago

I find this very surprising. From :help jobstart

jobstart({cmd} [, {opts}]) If {cmd} is a List it runs directly (no 'shell').

That means that quoting shouldn't matter at all because it's not getting parsed by a shell. What happens if you run this directly with jobstart?

local jid = vim.fn.jobstart(
  { "stylua", "--search-parent-directories", "--stdin-filepath", "C:\\some\\path with\\spaces.lua" },
  {
    stdout_buffered = true,
    stderr_buffered = true,
    stdin = "pipe",
    on_stdout = function(_, data)
      print("STDOUT:", table.concat(data, "\n"))
    end,
    on_stderr = function(_, data)
      print("STDERR:", table.concat(data, "\n"))
    end,
    on_exit = function(_, code)
      print("EXIT:", code)
    end,
  }
)

local buffer_text = [[
local foo  = 1
]]
vim.api.nvim_chan_send(jid, buffer_text)
vim.fn.chanclose(jid, "stdin")
LifeAdventurer commented 4 months ago

the whitespace in the account name is a big issue... cannot use any of the formatters...

msabathier commented 4 months ago

Okay so this goes deeper than i thought, it might be an issue with Mason because it works fine if i expose the stylua.exe to conform rather than the Mason stylua.cmd. I will be looking into it and report back my findings in issue #252. In anycase, my PR is not the way to go so i will close it.