Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: change how the recipes disables tsserver formatting #33

Closed
wants to merge 1 commit into from

Conversation

pprotas
Copy link

@pprotas pprotas commented Jul 27, 2023

I noticed that the tsserver formatting is disabled by overriding the server's capabilities. This is fine and works, but maybe a nicer way to do it would be by using the tsserver option that disables formatting instead.

@folke
Copy link
Contributor

folke commented Jul 27, 2023

where is that disable_formatting used? There's no such option as far as I know?

You also removed the eslint config

@pprotas
Copy link
Author

pprotas commented Jul 27, 2023

Never mind, this option does not exist. I thought it did because other people used this option in their tsserver config: https://github.com/search?q=disable_formatting+language%3ALua+&type=code and I saw it recommended on Reddit.

But I tested it out with vim.lsp.set_log_level(vim.lsp.log_levels.DEBUG), and tsserver still reacts to textDocument/formatting requests with disable_formatting = true or init_options = { format = { enable = false } }. The only way to make it stop reacting to these requests is by setting client.server_capabilities.documentFormattingProvider = false for tsserver, so this PR is wrong.

I did some more testing though, apparently you don't need to set documentFormattingProvider = true for eslint anymore. It works out of the box:

[DEBUG][2023-07-27 15:16:20] .../lua/vim/lsp.lua:1489	"LSP[eslint]"	"client.request"	2	"textDocument/formatting"	{  options = {    insertSpaces = true,    tabSize = 2  },  textDocument = {    uri = "file:///path/to/example.tsx"  }}	<function 1>	10

With the following config:

{
  "neovim/nvim-lspconfig",
  opts = {
    servers = {
      eslint = {},
    },
    setup = {
      eslint = function()
        require("lazyvim.util").on_attach(function(client, _)
          -- Notice I don't have to set documentFormattingProvider to true for eslint anymore
          if client.name == "tsserver" then
            client.server_capabilities.documentFormattingProvider = false
          end
        end)
      end,
    },
  },
},

I do know that eslint format was broken in the past, but now works without having to do anything. Possibly related to nvim-telescope/telescope.nvim#2594?

@folke
Copy link
Contributor

folke commented Jul 27, 2023

yes, exactly.

I'd rather keep the eslint code as is for now.

The reason eslint formatting now works otb is because of my dynamic capabilities PR in Neovim core.

But that's only on nightly.

@folke folke closed this Jul 27, 2023
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.

2 participants