lukas-reineke / lsp-format.nvim

A wrapper around Neovims native LSP formatting.
559 stars 27 forks source link

Can you give us a clearer example of how to use the on_attach function? #48

Closed FrancoEnriqueLimonDiaz closed 2 years ago

FrancoEnriqueLimonDiaz commented 2 years ago

I want to format html, css, sass, javascript and ruby and, I have something like this! Can you give a code snippet to format these languages?, thanks. info-lsp-config

lukas-reineke commented 2 years ago

I want to format html, css, sass, javascript and ruby

Then you have to set up LSP server for those languages. lsp-format does not know or care what language you are using. You just have to call it with the LSP client of each server you use.

The example in the readme is for gopls, that is the Golang LSP

require "lspconfig".gopls.setup { on_attach = require "lsp-format".on_attach }

If you want to use it with Javascript, you need tsserver, etc.

require "lspconfig".tsserver.setup { on_attach = require "lsp-format".on_attach }