Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lua/modules/configs/completion/formatting.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local M = {}

local method = "textDocument/formatting"
local settings = require("core.settings")
local disabled_workspaces = settings.format_disabled_dirs
local format_on_save = settings.format_on_save
Expand Down Expand Up @@ -90,12 +91,14 @@ end
function M.format_filter(clients)
return vim.tbl_filter(function(client)
local status_ok, formatting_supported = pcall(function()
return client.supports_method("textDocument/formatting")
return client.supports_method(method)
end)
if status_ok and formatting_supported and client.name == "null-ls" then
---@diagnostic disable-next-line
return "null-ls"
elseif not server_formatting_block_list[client.name] and status_ok and formatting_supported then
return client.name
---@diagnostic disable-next-line
end
end, clients)
end
Expand All @@ -117,7 +120,7 @@ function M.format(opts)
end

local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
local clients = vim.lsp.buf_get_clients(bufnr)
local clients = vim.lsp.get_clients({ bufnr = bufnr, method = method })

if opts.filter then
clients = opts.filter(clients)
Expand All @@ -131,10 +134,6 @@ function M.format(opts)
end, clients)
end

clients = vim.tbl_filter(function(client)
return client.supports_method("textDocument/formatting")
end, clients)

if #clients == 0 then
vim.notify(
"[LSP] Format request failed, no matching language servers.",
Expand Down Expand Up @@ -172,7 +171,8 @@ function M.format(opts)

-- Fall back to format the whole buffer (even if partial formatting failed)
local params = vim.lsp.util.make_formatting_params(opts.formatting_options)
local result, err = client.request_sync("textDocument/formatting", params, timeout_ms, bufnr)
---@diagnostic disable-next-line
local result, err = client.request_sync(method, params, timeout_ms, bufnr)
if result and result.result then
vim.lsp.util.apply_text_edits(result.result, bufnr, client.offset_encoding)
if format_notify then
Expand Down