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

Failed to spawn .cmd executables on windows #111

Closed
scottmckendry opened this issue Oct 7, 2023 · 6 comments · Fixed by #126
Closed

Failed to spawn .cmd executables on windows #111

scottmckendry opened this issue Oct 7, 2023 · 6 comments · Fixed by #126
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@scottmckendry
Copy link

scottmckendry commented Oct 7, 2023

:checkheath guard shows prettier as executable
image

but when testing prettier on an HTML file I get the message:

[Guard] failed to spawn process prettier

This is my config:

return {
    "nvimdev/guard.nvim",
    dependencies = {
        "nvimdev/guard-collection",
    },
    event = "BufReadPre",
    config = function()
        local ft = require("guard.filetype")
        ft("go")
            :fmt({
                cmd = "goimports-reviser",
                args = { "-output", "stdout" },
                fname = true,
            })
            :append({
                cmd = "gofmt",
                stdin = true,
            })
            :append({
                cmd = "golines",
                stdin = true,
            })

        ft("lua"):fmt("lsp")

        ft("html"):fmt("prettier")

        require("guard").setup({
            fmt_on_save = true,
            lsp_as_default_formatter = false,
        })
    end,
}

running cat index.html | prettier --stdin-filepath index.html from the commandlne outputs the formatted file with no errors.

Any ideas what I can check/test to try and get this working?

@scottmckendry
Copy link
Author

scottmckendry commented Oct 7, 2023

I've just tested this on my Linux machine and can not replicate the error - so it's isolated to Windows 11.
The exact same issue is also occurring with stylua. Works on Linux, and doesn't spawn on Windows (which is why I'm using lsp format instead).

gofmt is working fine in both os

@barrett-ruth
Copy link
Member

None of us have a windows device I believe. Attach a lot of debugging info and also try to fix the issue yourself. Make sure/check that the process is executable (vim.fn.executable), that you can start a job with it (uv.spawn), etc.

@xiaoshihou514
Copy link
Collaborator

I personally don't see an obvious issue so :( And as you said it's your win machine only so if it's not a uv.spawn quirk then I am not sure how to approach this.

@xiaoshihou514 xiaoshihou514 added the help wanted Extra attention is needed label Oct 9, 2023
@UnderCooled
Copy link

UnderCooled commented Jan 10, 2024

I've just tested this on my Linux machine and can not replicate the error - so it's isolated to Windows 11. The exact same issue is also occurring with stylua. Works on Linux, and doesn't spawn on Windows (which is why I'm using lsp format instead).

gofmt is working fine in both os

You need to add .cmd to those Node.js based tools on Windows, uv.spawn won't see these .cmd scripts as executable as vim.fn.executable on Windows.

{
  cmd = "prettier.cmd", 
  args = { '--stdin-filepath' },
  fname = true,
  stdin = true,
}

@barrett-ruth
Copy link
Member

@UnderCooled thanks for helping out with this. I looked at the executable() documentation and it seems like it automatically searches using the .cmd extension, so uv.spawn() failing instead does make sense.

I'm not accustomed to windows systems - isn't it true that some of the programs that, for example, guard-collection uses, could be .cmd, while others could be .exe?

If that's the case, I'm not sure how we could resolve this besides offering a warning to windows systems that no extension is specified.

@UnderCooled
Copy link

UnderCooled commented Jan 10, 2024

@barrett-ruth you can patch

handle = uv.spawn(opt.cmd, {

local cmd = vim.fn.exepath(opt.cmd)
:echo exepath('npm')
D:\dev_env\lang\node\npm.CMD

barrett-ruth added a commit that referenced this issue Jan 11, 2024
fix(#111): resolve windows executable paths
barrett-ruth added a commit that referenced this issue Jan 12, 2024
Revert "fix(#111): resolve windows executable paths"
@barrett-ruth barrett-ruth reopened this Jan 12, 2024
@xiaoshihou514 xiaoshihou514 added help wanted Extra attention is needed and removed help wanted Extra attention is needed labels Jan 12, 2024
@xiaoshihou514 xiaoshihou514 changed the title failed to spawn process prettier failed to spawn process prettier on windows Jan 13, 2024
@xiaoshihou514 xiaoshihou514 changed the title failed to spawn process prettier on windows Failed to spawn .cmd executables on windows Jan 14, 2024
@xiaoshihou514 xiaoshihou514 added the bug Something isn't working label Jan 14, 2024
@xiaoshihou514 xiaoshihou514 mentioned this issue Jun 13, 2024
9 tasks
xiaoshihou514 added a commit that referenced this issue Jul 21, 2024
closes #68 #86 #123 #109 #76 #141 #111
## changes
- [x] remove uv.spawn wrapper in favour of vim.system
- [x] `do_lint` now respects *all* config fields
- [x] linter can now use lnum_end and col_end
- [x] added step by step tutorial for advanced usage
- [x] remove all version checking code, only supports 0.10+ from now on
- [x] apply exepath fix for windows

## internal changes
- [x] events now contains truly all autocmd related functions
- [x] utils now contains execution checking functions
- [x] use custom simpler table copy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants