From 172b79f658f1e043eaeea17d88e1346512093aef Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 17 Apr 2024 19:53:49 +0800 Subject: [PATCH] perf(format): use first executable formatter --- bundle/format.nvim/lua/format.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/bundle/format.nvim/lua/format.lua b/bundle/format.nvim/lua/format.lua index 1e7de9c64..499c6e7bd 100644 --- a/bundle/format.nvim/lua/format.lua +++ b/bundle/format.nvim/lua/format.lua @@ -30,13 +30,17 @@ function M.format(bang, user_input, start_line, end_line) if not formatter then ok = pcall(function() local default = require('format.ft.' .. filetype) - local formatname = default.enabled()[1] - formatter = default[formatname]({ - filepath = vim.fn.expand('%:p'), - start_line = start_line, - end_line = end_line, - }) - util.info('using default formatter:' .. formatname) + for _, formatname in ipairs(default.enabled()) do + formatter = default[formatname]({ + filepath = vim.fn.expand('%:p'), + start_line = start_line, + end_line = end_line, + }) + if vim.fn.executable(formatter.exe) == 1 then + util.info('using default formatter:' .. formatname) + break + end + end end) if not ok then return util.msg('no formatter for ' .. filetype)