Skip to content

Commit b7ab923

Browse files
fix(utils): skip lsp formatexpr (#414)
1 parent 3eb7333 commit b7ab923

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lua/rest-nvim/utils.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,19 @@ function utils.gq_lines(lines, filetype)
295295
vim.api.nvim_buf_set_lines(format_buf, 0, -1, false, lines)
296296
local formatexpr = vim.bo[format_buf].formatexpr
297297
local formatprg = vim.bo[format_buf].formatprg
298-
if vim.bo[format_buf].formatexpr ~= "" then
298+
if formatexpr:match("^v:lua%.vim%.lsp%.formatexpr%(.*%)$") then
299+
local clients_count = #vim.lsp.get_clients({ bufnr = format_buf })
300+
logger.warn(("formatexpr is set to `%s` but %d clients are attached to the buffer %d."):format(
301+
formatexpr,
302+
clients_count,
303+
format_buf
304+
))
305+
logger.warn("Skipping lsp formatexpr")
306+
formatexpr = ""
307+
end
308+
if formatexpr ~= "" then
299309
logger.debug(("formatting %s filetype with formatexpr=%s"):format(filetype, formatexpr))
300-
elseif vim.bo[format_buf].formatprg ~= "" then
310+
elseif formatprg ~= "" then
301311
logger.debug(("formatting %s filetype with formatprg=%s"):format(filetype, formatprg))
302312
else
303313
logger.debug(("can't find formatexpr or formatprg for %s filetype. Formatting is canceled"):format(filetype))

0 commit comments

Comments
 (0)