nvimdev / guard.nvim

async fast minimalist plugin make format easy in neovim
MIT License
441 stars 23 forks source link

Formatter not executable error #156

Closed BennyThadikaran closed 1 month ago

BennyThadikaran commented 1 month ago

I get the below error in Neovim when opening a Lua file. The problem started yesterday after I updated to latest guard.nvim. I then updated Neovim to latest and updated the formatters via Mason and rechecked the formatter config. I also tried reinstalling the formatters and guard.nvim.

Switched to autopep8 but nothing seems to work. Even :GuardFmt

Failed to run `config` for guard.nvim

...y/.local/share/nvim/lazy/guard.nvim/lua/guard/events.lua:23: black not executable      

# stacktrace:                                                                             
  - /guard.nvim/lua/guard/events.lua:23 _in_ **pred**                                     
  - /tmp/.mount_nvim.aR6f4ud/usr/share/nvim/runtime/lua/vim/iter.lua:892 _in_ **fn**      
  - /tmp/.mount_nvim.aR6f4ud/usr/share/nvim/runtime/lua/vim/iter.lua:900 _in_ **any**     
  - /guard.nvim/lua/guard/events.lua:21 _in_ **watch_ft**                                 
  - /guard.nvim/lua/guard/init.lua:54 _in_ **setup**                                      
  - ~/.config/nvim/lua/dev/plugins/lsp/guard.lua:27 _in_ **config**                       
  - ~/.config/nvim/lua/dev/lazy.lua:16                                                    
  - ~/.config/nvim/init.lua:3

Disabling stylua stops the error in Lua files but i get a slightly different error with same stack trace when loading Python or JSON files

...y/.local/share/nvim/lazy/guard.nvim/lua/guard/events.lua:23: stylua not executable     

NVIM v0.10.1 Build type: Release LuaJIT 2.1.1713484068

guard.nvim config

return {
  "nvimdev/guard.nvim",
  lazy = false,
  config = function()
    local ft = require("guard.filetype")

    ft("python"):fmt({
      cmd = "black",
      args = { "-s", "-l", "80", "-" },
      stdin = true,
    })

    ft("json"):fmt({
      cmd = "npx",
      args = { "prettier", "--stdin-filepath" },
      fname = true,
      stdin = true,
    })

    ft("lua"):fmt({
      cmd = "stylua",
      args = { "-" },
      stdin = true,
    })

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

Some command outputs i thought might help

:au BufWritePre                                                                 
--- Autocommands ---                                                                      
lsp_b_1_save  BufWritePre                                                                 
    <buffer=1>                                                                            
              <Lua 162: /tmp/.mount_nvim.akmdSn0/usr/share/nvim/runtime/lua/vim/lsp.lua:541> [vim.lsp: textDocument/willSave]
:au Guard                                                                                                                      
--- Autocommands ---

:=require("guard.filetype").json Running from within JSON file, similar output for python file.

{                                                                                
  formatter = { {                                                                         
      args = { "prettier", "--stdin-filepath" },                                          
      cmd = "npx",                                                                        
      cwd = "/home/benny/Documents/python/pattern_scanner_v3",                            
      fname = true,                                                                       
      stdin = true                                                                        
    } },                                                                                  
  <metatable> = <1>{                                                                      
    __index = <table 1>,                                                                  
    append = <function 1>,                                                                
    env = <function 2>,                                                                   
    extra = <function 3>,                                                                 
    fmt = <function 4>,                                                                   
    key_alias = <function 5>,                                                             
    lint = <function 6>,                                                                  
    register = <function 7>                                                               
  }                                                                                       
}
xiaoshihou514 commented 1 month ago

:checkhealth guard If neovim can't find the executables, there's not much that we can do!

BennyThadikaran commented 1 month ago

I executed this from a python file after this error: stylua not executable

guard: require("guard.health").check()

Executable check ~

Thank you for helping with this.

xiaoshihou514 commented 1 month ago

That's not very helpful, are you on windows?

BennyThadikaran commented 1 month ago

Linux Mint 21.3. I am using an appimage for Neovim.

xiaoshihou514 commented 1 month ago
which stylua
stylua --version
:= vim.fn.executable("stylua")
BennyThadikaran commented 1 month ago

stylua 0.20.0

black, 24.4.2 (compiled: yes) Python (CPython) 3.10.12

I'm dont need stylua, mostly code in Python. I got this temporary solution as workaround.

vim.api.nvim_create_augroup("FormatOnSave", { clear = true })

vim.api.nvim_create_autocmd("BufWritePre", {
  group = "FormatOnSave",
  pattern = "*.py",
  callback = function()
    local black_path = '/home/benny/.local/share/nvim/mason/bin/black'
    vim.cmd('!' .. black_path .. ' -q -l 80 ' .. vim.fn.expand('%'))
    vim.cmd('edit')
  end,
})
xiaoshihou514 commented 1 month ago

Right, so what's your problem now? I'm getting rather confused.

BennyThadikaran commented 1 month ago

Like i mentioned before, none of the formatters are working anymore (Prettier, Black, Stylua). No formatting on save, no :GuardFmt

Everything was working before the latest update. It fine, if you're unable to help with the information provided.

Thanks for your time :+1: I'll figure something over the weekend.

glepnir commented 1 month ago

@BennyThadikaran does this path /home/benny/.local/share/nvim/mason/bin in your PATH env ?

xiaoshihou514 commented 1 month ago

Well, the errors told you that they are not executable. But your env seemed to have changed between replies, which confuses me.

glepnir commented 1 month ago

check :echo executable('where balck is') I suggest install bacl from your system package management and remove which install by mason and try again.

BennyThadikaran commented 1 month ago

@BennyThadikaran does this path /home/benny/.local/share/nvim/mason/bin in your PATH env ?

No its not.

check :echo executable('where balck is') I suggest install bacl from your system package management and remove which install by mason and try again.

That makes sense. I executed :echo executable('where black is') and it returned 0. I will install and get back.

Thanks

PS: I executed ./stylua --version from the mason/bin folder, since its not in my $PATH. Sorry if that got you confused.