|
@@ -277,8 +277,19 @@ local format_on_save = require("format-on-save")
|
|
|
local formatters = require("format-on-save.formatters")
|
|
|
local vim_notify = require("format-on-save.error-notifiers.vim-notify")
|
|
|
|
|
|
+-- only format with LSP if there are clients attached
|
|
|
+local lsp_formatter = formatters.custom({
|
|
|
+ format = function()
|
|
|
+ local bufnr = vim.api.nvim_get_current_buf()
|
|
|
+ local clients = vim.lsp.get_active_clients({ bufnr = bufnr })
|
|
|
+ if #clients > 0 then
|
|
|
+ vim.lsp.buf.format({ timeout_ms = 4000, bufnr = bufnr })
|
|
|
+ end
|
|
|
+ end
|
|
|
+})
|
|
|
+
|
|
|
local js = {
|
|
|
- formatters.lsp,
|
|
|
+ lsp_formatter,
|
|
|
formatters.if_file_exists({
|
|
|
pattern = {
|
|
|
"dprint.json",
|
|
@@ -305,7 +316,7 @@ format_on_save.setup({
|
|
|
|
|
|
fallback_formatter = {
|
|
|
formatters.remove_trailing_whitespace,
|
|
|
- formatters.lsp,
|
|
|
+ lsp_formatter,
|
|
|
},
|
|
|
})
|
|
|
|