diff options
| author | Christopher Johnstone <61227735+ChrisPJohnstone@users.noreply.github.com> | 2025-08-20 18:58:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-20 10:58:56 -0700 |
| commit | 592de750bf5b8c45fc48cebfde585721626ffd6d (patch) | |
| tree | ea6aff221376b0a293f386425f46b6c6fb9d65b6 /lsp | |
| parent | fix(ts/js): give lockfiles equal priority when finding root #4013 (diff) | |
| download | nvim-lspconfig-592de750bf5b8c45fc48cebfde585721626ffd6d.tar nvim-lspconfig-592de750bf5b8c45fc48cebfde585721626ffd6d.tar.gz nvim-lspconfig-592de750bf5b8c45fc48cebfde585721626ffd6d.tar.bz2 nvim-lspconfig-592de750bf5b8c45fc48cebfde585721626ffd6d.tar.lz nvim-lspconfig-592de750bf5b8c45fc48cebfde585721626ffd6d.tar.xz nvim-lspconfig-592de750bf5b8c45fc48cebfde585721626ffd6d.tar.zst nvim-lspconfig-592de750bf5b8c45fc48cebfde585721626ffd6d.zip | |
feat(yamlls): force documentFormattingProvider=true #4016
Problem:
The current version of the config will let you do formatting manually
`:lua vim.lsp.buf.format()` but the lsp doesn't have capabilities
registered correctly so if you use auto formatting like outlined in
[help pages](https://neovim.io/doc/user/lsp.html#lsp-attach)
if not client:supports_method('textDocument/willSaveWaitUntil')
and client:supports_method('textDocument/formatting') then
vim.api.nvim_create_autocmd('BufWritePre', {
group = vim.api.nvim_create_augroup('my.lsp', {clear=false}),
buffer = args.buf,
callback = function()
vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 })
end,
})
end
, it won't enable for the yaml lsp because
`client:supports_method('textDocument/formatting')` returns false.
Solution:
The `on_init` hook, while hacky, will mark the capability as true.
Diffstat (limited to 'lsp')
| -rw-r--r-- | lsp/yamlls.lua | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lsp/yamlls.lua b/lsp/yamlls.lua index 586745a7..04e837e1 100644 --- a/lsp/yamlls.lua +++ b/lsp/yamlls.lua @@ -70,4 +70,11 @@ return { -- formatting disabled by default in yaml-language-server; enable it yaml = { format = { enable = true } }, }, + on_init = function(client) + --- https://github.com/neovim/nvim-lspconfig/pull/4016 + --- Since formatting is disabled by default if you check `client:supports_method('textDocument/formatting')` + --- during `LspAttach` it will return `false`. This hack sets the capability to `true` to facilitate + --- autocmd's which check this capability + client.server_capabilities.documentFormattingProvider = true + end, } |
