Check lsp client capabilties before formatting

This commit is contained in:
Sonny Bakker 2025-02-13 21:25:49 +01:00
parent 030f887734
commit a351ad691b
2 changed files with 6 additions and 2 deletions

View file

@ -18,7 +18,11 @@
- common - common
tasks: tasks:
- import_tasks: 'tasks/dotfiles.yml' - import_tasks: 'tasks/dotfiles.yml'
- import_tasks: 'tasks/neovim.yml'
- name: Include neovim tasks
import_tasks: 'tasks/neovim.yml'
tags: neovim
- name: gather package facts - name: gather package facts
package_facts: package_facts:
manager: pacman manager: pacman

View file

@ -159,7 +159,6 @@ vim.diagnostic.config({
local enable_formatting = os.getenv("ENABLE_FORMATTING", False) local enable_formatting = os.getenv("ENABLE_FORMATTING", False)
-- TODO: fix error message: [LSP] Format request failed, no matching language servers.
-- format buffers before saving for specific LSPs -- format buffers before saving for specific LSPs
if (enable_formatting) then if (enable_formatting) then
local excluded_clients = { 'pyright' } local excluded_clients = { 'pyright' }
@ -172,6 +171,7 @@ if (enable_formatting) then
callback = function() callback = function()
vim.lsp.buf.format { vim.lsp.buf.format {
filter = function(client) filter = function(client)
if not client.supports_method('textDocument/formatting') then return end
return not vim.list_contains(excluded_clients, client.name) return not vim.list_contains(excluded_clients, client.name)
end, end,
async = false, async = false,