Open GitMurf opened 11 months ago
Above was from a couple days ago. Below is still from today after the recent update (still not working):
Thanks for all your hard work on this plugin :) let me know if you need anymore details.
curious if you have had a chance to look at this yet? also I am happy to take a look at doing a PR to try and fix it if you are able to point me in the right direction. I am a TS developer and brand new to neovim / lua etc. so I am capable but just need a little direction of where to look and then I could play around and do some testing to see if I can fix it for Windows. I tried on my own the other day for a couple hours but kept running in circles and couldn't quite figure out where everything flowed through to properly fix it.
I am unfortunately very time limited these days, and I have a lot of projects to manage, so I have to aggressively triage and carefully choose what I spend time on. I try to make sure I always review PRs, and anything breaking enough to be a P0, but everything else is no guarantees.
Some tips for investigating this yourself: get some detailed log information
require("conform").setup({
log_level = vim.log.levels.TRACE
})
Try to get an invocation of the formatter on the command line that does work, then see what the difference is between that and the command that conform is using. Gradually mutate one into the other until you can pinpoint what the issue is with the command.
If the commands are the same, then possibly there's some problem with the details of how Neovim is running the command. See if you can replicate the issue with a minimal lua script that calls vim.fn.jobstart
directly.
Hi @GitMurf, it seems i have been running into the same problem as you and i will try to find a solution. Can you tell me if you are using Mason to install the Prettier formatter ?
Me too. Same problem!
Hi @LifeAdventurer, what formatter(s) are you using ? And did you install them using Mason ?
Hi @LifeAdventurer, what formatter(s) are you using ? And did you install them using Mason ?
Yes, I'm using Mason. I first installed only installed black
, isort
, prettier
, and stylua
for testing (if everything works, I'm going to install more for other languages), but found out that these could not be used because there were spaces in my account name, which caused an error when conform.nvim
getting the path.
Hi @GitMurf, it seems i have been running into the same problem as you and i will try to find a solution. Can you tell me if you are using Mason to install the Prettier formatter ?
@msabathier I forgot how I ended up getting it working but just checked and I ended up abandoning trying to use prettier
from within the node_modules of my project (as I have spaces in the path location of my project) and instead moved to using prettierd which is installed via mason in my nvim-data user directory. I do not have spaces in that path which is how I got it working.
My path for prettierd that conform is using now is: C:\Users\MyName\AppData\Local\nvim-data\mason\bin\prettierd.cmd
@msabathier if you are trying to investigate, in my own personal nvim config stuff and plugin work I find success using vim.fs.normalize(filepath)
since there are not only "spaces" issues on windows but also often mac/unix users have the directory separator slashes incompatible with windows. The normalize method fixes that. Although I don't think it actually fixes the spaces issue as I believe that is all about escaping the entire path with quotes around it.
Hi @GitMurf, it seems i have been running into the same problem as you and i will try to find a solution. Can you tell me if you are using Mason to install the Prettier formatter ?
@msabathier I forgot how I ended up getting it working but just checked and I ended up abandoning trying to use
prettier
from within the node_modules of my project (as I have spaces in the path location of my project) and instead moved to using prettierd which is installed via mason in my nvim-data user directory. I do not have spaces in that path which is how I got it working.My path for prettierd that conform is using now is:
C:\Users\MyName\AppData\Local\nvim-data\mason\bin\prettierd.cmd
I have spaces in MyName
. That's why conform failed to get the formatter.
I've also got spaces in my User name on my Windows machine which is causing Conform to fail.
I've set the log levels to TRACE as advised above and this is the output from :ConformInfo
Log file: C:\Users\User Name\AppData\Local\nvim-data\conform.log
20:17:45[TRACE] Diff indices {}
20:17:45[TRACE] Applying text edits: {}
20:17:45[TRACE] Done formatting C:\Users\User Name\AppData\Local\nvim\lua\plugins\formatter.lua
20:17:45[ERROR] Formatter 'stylua' error: 'C:\Users\User' 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\User Name\AppData\Local\nvim-data\mason\bin\stylua.CMD
I can see the TRACE logs are happening in runner.lua
in the M.apply_format
function.
Any updates on this? Is probably tied to shell unquoting or something similar going on on the jobstart call, I've tried quoting the argument to prettierd in every way I know and it's still passing C:/Users/First unquoted.
EDIT: would vim.system
help?
After updating the version to 42b53fc or a newer one it works!
Still broken for me with prettierd unfortunately.
Since this issue was filed I've written a debugging guide that I would recommend you follow. It will help to isolate where the problem is happening.
I'll go through the steps tomorrow. I still believe the issue is that the command needs to be quoted if it includes spaces "C:/Users/Some User with Spaces/AppData/Local/nvim-data/mason/bin/prettierd.cmd"
I'm not able to get very far since cat .\test.ts | "C:\Users\My User\AppData\Local\nvim-data\mason\bin\prettierd.cmd"
throws
Error: File name must be provided as an argument
and if I use an argument I get No files specified.
Running the debug lua ends up like:
run_formatter({ "C:\\Users\\My User\\AppData\\Local\\nvim-data\\mason\\bin\\prettierd.cmd", "C:\\Users\\My User\\src\\test.ts"}, "C:/Users/My User/src/")
which fails with 'C:/Users/My' is not recognized as an internal or external command, operable program or batch file.
Well, since the call to vim.system
is failing that is going to be the root problem. vim.system
is supposed to take the first value of the command and run that file directly, so I am very surprised that there is anything weird happening with spaces. It's not going through the shell (or at least, it's not supposed to be) so quoting would be nonsensical. On Mac & Linux, spaces in the file path cause no problems.
You could try filing this as an issue on Neovim (with a minimal call to vim.system
as the repro), but based on the fact that the command is getting passed in directly to libuv, it's quite possibly an issue with libuv itself.
I was facing this issue a lot. Fortunately, I was able to invoke the formatter, say prettier, directly from prettier.cmd. So my solution was to move the cmd file to some location without space in the path name. The destination file path had a space too but it wasn't causing any issues. Once I moved the cmd file to someplace else, I modified its path in conform setup, and it started working fine. I am used to making changes in init.lua directly, so I am attaching the conform setup here for prettier in case someone wants to follow this workaround.
require("conform").setup({ formatters_by_ft = { javascript = { "prettier" }, }, formatters = { prettier = { command = "D:\Dev\nvim-formatters\prettier.cmd", --I moved it to a separate drive with no space in path name }, }, log_level = vim.log.levels.DEBUG, })
vim.api.nvim_create_autocmd("BufWritePre", { pattern = "*", callback = function(args) local conform = require("conform") conform.format({ bufnr = args.buf }) end, })
If I have a space in my path at all of my git repository (where prettier is installed in node_modules) then I get the following error:
Notice the actual start to my path to my git repo locally has a space here which is exactly where the error above cutoff.
Originally posted by @GitMurf in https://github.com/stevearc/conform.nvim/issues/236#issuecomment-1868100641