question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use yaml formatter with Neovim builtin LSP client?

See original GitHub issue

The codebase contains a yamlFormatter although the server capabilities says otherwise:

        documentFormattingProvider: false,

The formatter runs perfectly well in VSCode. I installed the server using npm and running the server with the default settings.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
dhruvmanilacommented, Feb 21, 2022

I think you should directly use prettier for YAML files as the language server uses that internally.

https://github.com/redhat-developer/yaml-language-server/blob/f03324a3a81c1a32b153b61dea685308865b5dac/src/languageservice/services/yamlFormatter.ts#L47

But, if you want to use the language server, then I suggest to guard the line so that it only affects the YAML language server:

local on_attach = function(client, buffer)
  if client.name == "yamlls" then
    client.resolved_capabilities.document_formatting = true
  end
end
0reactions
meatballscommented, Feb 21, 2022

Never mind. I got it working myself by adding a line to my on_attach function:

local on_attach = function(client, bufnr)
  client.resolved_capabilities.document_formatting = true
Read more comments on GitHub >

github_iconTop Results From Across the Web

Neovim for Beginners —LSP using null-ls.nvim | by alpha2phi
nvim to inject LSP diagnostics, code actions, and more by allowing third-party tools and utilities to hook into the LSP client. In this...
Read more >
Neovim Spaghetti - LSP Servers, Linters, Formatters ... - roobert
LSP facilitates features like go-to-definition, find-references, hover, completion, rename, format, refactor, etc., using semantic ...
Read more >
How to set up Neovim 0.5 + Modern plugins (LSP, Treesitter ...
I manage plugins in $HOME/.config/nvim/plug.vim . Then, relaunch Neovim and run :PlugInstall to install plugins. Set up the built-in ...
Read more >
My Neovim setup for React, TypeScript, Tailwind CSS, etc
As you may know, I mainly use Neovim to code my app called Inkdrop, a. ... plugin for Neovim's built-in LSP client; williamboman/mason.nvim...
Read more >
Null-ls - Linter & Formatter - Rocky Linux Documentation
The jose-elias-alvarez/null-ls.nvim plugin, although not essential to the ... you should use vim.lsp.buf.format({ bufnr = bufnr }) instead ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found