jose-elias-alvarez / null-ls.nvim

Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua.
Other
3.63k stars 792 forks source link

Code formatting doesn't work by pressing `=` #695

Closed cryptomilk closed 2 years ago

cryptomilk commented 2 years ago

FAQ

Issues

Neovim Version

0.6.1

Operating System

Fedora

Minimal config

--- minimal_init.lua.orig       2022-02-19 09:53:44.196843929 +0100
+++ minimal_init.lua    2022-02-19 09:53:41.435847393 +0100
@@ -26,7 +26,7 @@
     local null_ls = require("null-ls")
     -- add only what you need to reproduce your issue
     null_ls.setup({
-        sources = {},
+        sources = { null_ls.builtins.formatting.shfmt },
         debug = true,
     })
 end

Steps to reproduce

sample.sh:

#!/bin/bash

wurst=`command -v wurst`
echo "${wurst}"

nvim --clean -u minimal_init.lua sample.sh

Expected behavior

I would expect that when pressing = that my buffer gets formatted by shfmt. However nothing happens. This works fine with diagnostics-language-server.

I need to run: lua vim.lsp.buf.formatting_sync() to get the formatting done ...

Actual behavior

Pressing = should format the complete buffer.

Debug log

...

Help

No

Implementation help

No response

Requirements

jose-elias-alvarez commented 2 years ago

This isn't my area of expertise and is not related to null-ls, but to my knowledge, = uses equalprg (see :h 'equalprg'), and I'm not sure if it can be hooked into LSP formatting.

You can use LSP formatting for gq formatting, which uses formatprg (see :h vim.lsp.formatexpr()). Other than that, your best bet is to just map the key yourself.