Skip to content

Conversation

liskin
Copy link
Contributor

@liskin liskin commented Aug 19, 2025

Faking capabilities isn't necessary to enable formatting support. It's a dynamically registered capability that yamlls announces whenever yaml formatting is enabled in settings, which it isn't by default.

See:
https://github.com/redhat-developer/yaml-language-server/blob/3821411ee8c92e5b7e5ca88f84ab443ae3b2791a/src/yamlServerInit.ts#L128
https://github.com/redhat-developer/yaml-language-server/blob/3821411ee8c92e5b7e5ca88f84ab443ae3b2791a/src/languageserver/handlers/settingsHandlers.ts#L159-L174

Fixes: 63a0164 ("feat(yamlls): document formatting support #4003")

Faking capabilities isn't necessary to enable formatting support. It's a
dynamically registered capability that yamlls announces whenever yaml
formatting is enabled in settings, which it isn't by default.

See
https://github.com/redhat-developer/yaml-language-server/blob/3821411ee8c92e5b7e5ca88f84ab443ae3b2791a/src/yamlServerInit.ts#L128
https://github.com/redhat-developer/yaml-language-server/blob/3821411ee8c92e5b7e5ca88f84ab443ae3b2791a/src/languageserver/handlers/settingsHandlers.ts#L159-L174

Fixes: 63a0164 ("feat(yamlls): document formatting support neovim#4003")
@liskin
Copy link
Contributor Author

liskin commented Aug 19, 2025

wtf is commitlint on about? conventional-changelog/commitlint#4101 hits hard :-(

Anyway let me know how hard do I need to try to satisfy these lints. Neither seems super relevant:

  • commitlint is straight hallucinating about the footer
  • lint.sh tells me not to touch lua/lspconfig/configs/* but someone touched them last Thursday (4da7247) so presumably it's okay actually?

@justinmk justinmk merged commit 66274c2 into neovim:master Aug 19, 2025
4 of 6 checks passed
@liskin liskin deleted the yamlls-format branch August 19, 2025 14:59
@ChrisPJohnstone
Copy link
Contributor

I recognise this is my fault for not explaining properly on #4003, apologies, hopefully this clears things up.

So enabling this way 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

    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 the capability is registered as false. That's why the hacky solution

I'm not sure if there's a better way to override the LSP capabilities? Imo this should be addressed in the default config though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants